CVE-2026-12345

Race condition in tempfile.TemporaryDirectory cleanup allows deleting files outside the temporary directory

Published Sep 29, 2026 CVSS 4.0 · 5.9 Medium EPSS < 1% KEV · Not listed
Description
The cleanup of tempfile.TemporaryDirectory is vulnerable to a race condition. An attacker who can modify the tree during cleanup can replace a directory with a symbolic link, causing files outside of the temporary directory to be deleted or have their permissions and file flags reset, with the privileges of the process performing the cleanup. Note that platforms where shutil.rmtree.avoids_symlink_attacks is false, remain affected, and file flags may still be reset outside of the tree on all platforms.

Analysis

AI-generated

Technical impact

The race condition, identified as a CWE-59 weakness, occurs during the cleanup of a TemporaryDirectory object in CPython's tempfile module. An attacker who can alter the directory tree while the cleanup routine is running may replace a real directory or file with a symbolic link pointing elsewhere. When the cleanup removes the TemporaryDirectory, it follows that symlink and deletes or changes metadata of files outside the intended temporary space. The result is unintended deletion or permission changes of arbitrary files owned by the process, which can corrupt data or disrupt services.

Affected Systems

CPython, the standard Python implementation maintained by the Python Software Foundation, is affected. All versions that have not yet incorporated the patch referenced in commit 5c20517a4fc56683efe63a7751020db9573f538d are vulnerable. The issue specifically involves the tempfile.TemporaryDirectory cleanup routine and the shutil.rmtree behavior that does not always prevent symlink attacks.

Risk and Exploitability

The CVSS score of 5.9 indicates moderate severity, and the EPSS score is not available, so the precise exploitation probability is uncertain. The vulnerability requires that an attacker be able to modify the target directory tree while the cleanup is executing, which typically means local execution or influence over the temporary directory content. Because the cleanup runs with the privileges of the Python process, the consequences can include unintended deletion of files that the process is allowed to modify. The absence of a KEV listing suggests no widespread exploitation yet.

Remediation

No solution or workaround provided in the CVE record.

OpenCVE Recommended Actions

  • Upgrade CPython to a version that includes the fix, such as the release following commit 5c20517a4fc56683efe63a7751020db9573f538d.
  • Ensure that any temporary directories used by your applications are not writable by untrusted code and avoid modifying them during cleanup.
  • Verify that the environment variable or setting controlling shutil.rmtree.avoids_symlink_attacks is enabled; if available set it to True to prevent symlink exploitation during recursive removal.

Generated by OpenCVE AI on September 29, 2026 at 22:38 UTC.

Tracking

Sign in to view the affected projects.

Advisories

No advisories available
History
Type Values Removed Values Added
References
Metrics threat_severity

None

cvssV3_1

{'score': 6.3, 'vector': 'CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:H/A:H'}

threat_severity

Moderate

Type Values Removed Values Added
First Time appeared Python
Python cpython
Vendors & Products Python
Python cpython
Type Values Removed Values Added
Weaknesses CWE-59
Metrics ssvc

{'options': {'Automatable': 'no', 'Exploitation': 'none', 'Technical Impact': 'partial'}, 'version': '2.0.3'}

Type Values Removed Values Added
Description The cleanup of tempfile.TemporaryDirectory is vulnerable to a race condition. An attacker who can modify the tree during cleanup can replace a directory with a symbolic link, causing files outside of the temporary directory to be deleted or have their permissions and file flags reset, with the privileges of the process performing the cleanup. Note that platforms where shutil.rmtree.avoids_symlink_attacks is false, remain affected, and file flags may still be reset outside of the tree on all platforms.
Title Race condition in tempfile.TemporaryDirectory cleanup allows deleting files outside the temporary directory
References
Metrics cvssV4_0

{'score': 5.9, 'vector': 'CVSS:4.0/AV:L/AC:L/AT:P/PR:N/UI:N/VC:N/VI:H/VA:H/SC:N/SI:N/SA:N'}

Weaknesses
  • CWE-59

    Improper Link Resolution Before File Access ('Link Following')

Sources

Status
PUBLISHED
Assigner
PSF
Published
Updated
Oct 26, 2026, 12:36 AM
Reserved
Jun 15, 2026, 7:08 PM
Status
Awaiting Analysis
Published
Sep 29, 2026, 6:17 PM
Modified
Oct 26, 2026, 1:17 AM
Severity
Moderate
Public date
Sep 29, 2026, 5:46 PM