You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
shutil.copy2 race condition leading to local file disclosure #96719
shutil.copy2 first copies the contents (creating the file with default permissions), then sets the permissions. This allows a local attacker that can read the directory to quickly grab the contents of the file before the permissions are changed. (This was reported to security@ on 2022-02-04 and has now been publicly disclosed - the link has some extra detail. Creating the bug here as directed.)
Note that changing the permissions after file creation but before writing content is insufficient: if the file is created with permissions that allow the attacker to open it, the attacker can get a file handle for the (empty) file. Under POSIX, the handle remains valid and readable even if the permissions change, allowing the attacker to read the file contents when they're populated. (@tiran, please feel free to add the info from your security@ response.)
I recently read a blog post about such issues and was wondering if the Python standard lib could have similar problems, which led me to find some apparently unreported bugs and this one (which seems to be the same as #59305 if I'm not mistaken).
Do you know if anyone has tried to find a fix? Discussions in #59305 imply that it's "not that simple" but I still think it'd be worth looking into fixing.
Activity
KowalskiThomas commentedon May 14, 2026
I recently read a blog post about such issues and was wondering if the Python standard lib could have similar problems, which led me to find some apparently unreported bugs and this one (which seems to be the same as #59305 if I'm not mistaken).
Do you know if anyone has tried to find a fix? Discussions in #59305 imply that it's "not that simple" but I still think it'd be worth looking into fixing.