Repository navigation
CVE-2025-68146 Don't follow a symlink at the lock path - #1
Merged
Merged
Conversation
filelock opened the lock file with os.O_CREAT | os.O_TRUNC and no O_NOFOLLOW, so a symlink planted at the lock path was followed and its target truncated (TOCTOU symlink attack, CVE-2025-68146 / affects < 3.20.1). Backport the upstream 3.20.1 mitigation, adapted to this 3.1.0 / Python-2.7 single-module layout: - UnixFileLock and SoftFileLock: add os.O_NOFOLLOW to the open flags, guarded by getattr(os, "O_NOFOLLOW", None) for platforms that lack it. A symlinked lock path now fails with ELOOP instead of truncating the target. (SoftFileLock already used O_EXCL, which refuses existing paths; O_NOFOLLOW is added for consistency.) - WindowsFileLock: Windows has no O_NOFOLLOW, so add _is_reparse_point() (via GetFileAttributesW + FILE_ATTRIBUTE_REPARSE_POINT) and refuse to open the lock file if it is a reparse point (symlink/junction). Add a regression test (runs for both lock types) asserting a symlinked lock path leaves its target intact and the lock unheld. Py2.7-safe: %-formatting, getattr guard, lazy ctypes import, path decoded to unicode for the wide WinAPI call. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
filelock opened the lock file with os.O_CREAT | os.O_TRUNC and no O_NOFOLLOW, so a symlink planted at the lock path was followed and its target truncated (TOCTOU symlink attack, CVE-2025-68146 / affects < 3.20.1).
Backport the upstream 3.20.1 mitigation, adapted to this 3.1.0 / Python-2.7 single-module layout:
Add a regression test (runs for both lock types) asserting a symlinked lock path leaves its target intact and the lock unheld. Py2.7-safe: %-formatting, getattr guard, lazy ctypes import, path decoded to unicode for the wide WinAPI call.