CVE-2026-12345 in Python
Summary
by MITRE • 09/29/2026
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.
If you want to get best quality of vulnerability data, you may have to visit VulDB.
Analysis
by VulDB Data Team • 09/29/2026
The vulnerability identified in Python's tempfile.TemporaryDirectory module represents a critical race condition within the resource cleanup mechanism, specifically affecting how temporary directories are removed from the filesystem upon completion or exception handling. This flaw arises because the standard library function shutil.rmtree, which is utilized to perform the actual deletion of the directory tree, does not consistently enforce strict security checks against symbolic link attacks across all operating systems and Python versions. The core technical issue lies in the timing between the decision to delete a path and the execution of that deletion. If an attacker gains write access to any part of the temporary directory hierarchy during this narrow window, they can manipulate the filesystem structure by replacing a subdirectory with a symbolic link pointing to a sensitive location outside the intended sandboxed area.
When the cleanup process executes rmtree on such a manipulated tree, it follows the symbolic links rather than treating them as opaque objects within the temporary scope. Consequently, any directory entry that has been swapped for a symlink will cause the deletion operation to traverse into the target of the link. This results in the unauthorized removal of files located outside the original temporary directory boundary. The severity is compounded by the fact that this action occurs with the privileges of the process performing the cleanup, which often implies elevated permissions depending on how the application was launched. In scenarios where shutil.rmtree.avoids_symlink_attacks evaluates to false, typically due to underlying operating system limitations or older Python implementations lacking specific hardening patches, the risk is maximized as there are no built-in safeguards to prevent following these maliciously crafted links during recursive deletion.
Beyond file deletion, this vulnerability also poses a significant threat regarding data integrity and configuration tampering through permission manipulation. On certain platforms, even if symbolic link attacks are partially mitigated by default settings, an attacker may still exploit race conditions or specific filesystem behaviors to reset file flags and permissions on files outside the temporary directory tree. This capability allows for privilege escalation vectors where an attacker could weaken security controls on critical system files or application data by stripping away restrictive attributes such as read-only flags or immutable bits. The operational impact is severe, potentially leading to denial of service through mass deletion of essential resources, unauthorized modification of sensitive configuration files, or the establishment of persistent backdoors if executable scripts are targeted and modified prior to their execution by privileged services.
This vulnerability aligns with CWE-367, which describes Time-of-check to time-of-use (TOCTOU) race conditions, as the security check for directory validity is not atomic relative to the file system modification operations. Furthermore, it relates to CWE-22, Improper Limitation of a Pathname to a Restricted Directory, because the cleanup routine fails to strictly confine its destructive actions within the designated temporary boundary due to symlink traversal. From an ATT&CK perspective, this behavior facilitates Defense Evasion and Impact categories, specifically T1070 Indicator Removal on Host or T1485 Data Destruction, as it allows for silent deletion of evidence or critical system components without triggering immediate alarms associated with direct file access violations.
Mitigation strategies must focus on ensuring that the Python environment is updated to versions where shutil.rmtree has been hardened against symlink attacks by default, particularly on platforms where this protection was previously optional or absent. Developers should avoid relying solely on tempfile.TemporaryDirectory for security-sensitive operations and instead implement explicit validation checks before cleanup if custom removal logic is required. Additionally, running applications with the principle of least privilege reduces the blast radius of such an exploit; even if an attacker successfully deletes files outside the temporary directory, limiting the process permissions can prevent catastrophic damage to system-critical paths. Regular auditing of third-party dependencies and ensuring that all components utilizing temporary file handling are patched is essential to closing this attack vector in production environments.