CVE-2026-12345: Race condition in tempfile.TemporaryDirectory cleanup allows deleting files outside the temporary directory
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.avoidssymlinkattacks is false, remain affected, and file flags may still be reset outside of the tree on all platforms.
Affected Software
Event History
Frequently Asked Questions
What access does an attacker need to exploit this issue?
The attacker must be able to modify the temporary directory tree while cleanup is in progress. Exploitation relies on replacing a directory in that tree with a symbolic link during the race window.
How does the affected platform influence exposure?
Platforms where shutil.rmtree.avoids_symlink_attacks is false remain affected. On all platforms, file flags may still be reset outside the temporary-directory tree.
What privileges are used for the unintended file operations?
Any deletion, permission reset, or file-flag reset outside the temporary directory occurs with the privileges of the process performing the cleanup.