Repository navigation
chore(deps): update dependency filelock to v4 [security] - #25
Open
renovate[bot] wants to merge 1 commit into
Open
renovate[bot] wants to merge 1 commit into
renovate[bot] wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Note
This PR body was truncated due to platform limits.
This PR contains the following updates:
3.17.0→4.2.1filelock has a TOCTOU race condition which allows symlink attacks during lock file creation
CVE-2025-68146 / GHSA-w853-jp5j-5j7f
More information
Details
Impact
A Time-of-Check-Time-of-Use (TOCTOU) race condition allows local attackers to corrupt or truncate arbitrary user files through symlink attacks. The vulnerability exists in both Unix and Windows lock file creation where filelock checks if a file exists before opening it with O_TRUNC. An attacker can create a symlink pointing to a victim file in the time gap between the check and open, causing os.open() to follow the symlink and truncate the target file.
Who is impacted:
All users of filelock on Unix, Linux, macOS, and Windows systems. The vulnerability cascades to dependent libraries:
Attack requires local filesystem access and ability to create symlinks (standard user permissions on Unix; Developer Mode on Windows 10+). Exploitation succeeds within 1-3 attempts when lock file paths are predictable.
Patches
Fixed in version 3.20.1.
Unix/Linux/macOS fix: Added O_NOFOLLOW flag to os.open() in UnixFileLock._acquire() to prevent symlink following.
Windows fix: Added GetFileAttributesW API check to detect reparse points (symlinks/junctions) before opening files in WindowsFileLock._acquire().
Users should upgrade to filelock 3.20.1 or later immediately.
Workarounds
If immediate upgrade is not possible:
Warning: These workarounds provide only partial mitigation. The race condition remains exploitable. Upgrading to version 3.20.1 is strongly recommended.
Technical Details: How the Exploit Works
The Vulnerable Code Pattern
Unix/Linux/macOS (
src/filelock/_unix.py:39-44):Windows (
src/filelock/_windows.py:19-28):The Race Window
The vulnerability exists in the gap between operations:
Unix variant:
Windows variant:
Step-by-Step Attack Flow
1. Attacker Setup:
2. Attacker Creates Race Condition:
3. Victim Application Runs:
4. What Happens Inside os.open():
On Unix systems, when
os.open()is called:Without
O_NOFOLLOWflag, the kernel follows the symlink and truncates the target file.Why the Attack Succeeds Reliably
Timing Characteristics:
Success factors:
Real-World Attack Scenarios
Scenario 1: virtualenv Exploitation
Scenario 2: PyTorch Cache Poisoning
Why Standard Defenses Don't Help
File permissions don't prevent this:
Directory permissions help but aren't always feasible:
File locking doesn't prevent this:
Exploitation Proof-of-Concept Results
From empirical testing with the provided PoCs:
Simple Direct Attack (
filelock_simple_poc.py):virtualenv Attack (
weaponized_virtualenv.py):PyTorch Attack (
weaponized_pytorch.py):Discovered and reported by: George Tsigourakos (@tsigouris007)
Severity
CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:H/A:HReferences
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
filelock Time-of-Check-Time-of-Use (TOCTOU) Symlink Vulnerability in SoftFileLock
CVE-2026-22701 / GHSA-qmgc-5h2g-mvrw
More information
Details
Vulnerability Summary
Title: Time-of-Check-Time-of-Use (TOCTOU) Symlink Vulnerability in SoftFileLock
Affected Component:
filelockpackage -SoftFileLockclassFile:
src/filelock/_soft.pylines 17-27CWE: CWE-362, CWE-367, CWE-59
Description
A TOCTOU race condition vulnerability exists in the
SoftFileLockimplementation of the filelock package. An attacker with local filesystem access and permission to create symlinks can exploit a race condition between the permission validation and file creation to cause lock operations to fail or behave unexpectedly.The vulnerability occurs in the
_acquire()method betweenraise_on_not_writable_file()(permission check) andos.open()(file creation). During this race window, an attacker can create a symlink at the lock file path, potentially causing the lock to operate on an unintended target file or leading to denial of service.Attack Scenario
Impact
What kind of vulnerability is it? Who is impacted?
This is a Time-of-Check-Time-of-Use (TOCTOU) race condition vulnerability affecting any application using
SoftFileLockfor inter-process synchronization.Affected Users:
filelock.SoftFileLockdirectlyFileLockon systems withoutfcntlsupport (e.g., GraalPy)Consequences:
CVSS v4.0 Score: 5.6 (Medium)
Vector: CVSS:4.0/AV:L/AT:L/PR:L/UI:N/VC:N/VI:L/VA:H/SC:N/SI:N/SA:N
Attack Requirements:
Patches
Has the problem been patched? What versions should users upgrade to?
Yes, the vulnerability has been patched by adding the
O_NOFOLLOWflag to prevent symlink following during lock file creation.Patched Version: Next release (commit: 255ed068bc85d1ef406e50a135e1459170dd1bf0)
Mitigation Details:
O_NOFOLLOWflag is added conditionally and gracefully degrades on platforms without supportO_NOFOLLOWsupport (most modern systems): symlink attacks are completely preventedO_NOFOLLOW(e.g., GraalPy): TOCTOU window remains but is documentedUsers should:
UnixFileLockorWindowsFileLockinstead of the fallbackSoftFileLockWorkarounds
Is there a way for users to fix or remediate the vulnerability without upgrading?
For users unable to update immediately:
Avoid
SoftFileLockin security-sensitive contexts - useUnixFileLockorWindowsFileLockwhen available (these were already patched for CVE-2025-68146)Restrict filesystem permissions - prevent untrusted users from creating symlinks in lock file directories:
Use process isolation - isolate untrusted code from lock file paths to prevent symlink creation
Monitor lock operations - implement application-level checks to verify lock acquisitions are successful before proceeding with critical operations
References
Are there any links users can visit to find out more?
Reported by: George Tsigourakos (@tsigouris007)
Severity
CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:L/A:HReferences
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
filelock: WindowsFileLock ignores mode: a 0o600 lock file and the ReadWriteLock database inherit the directory ACL
CVE-2026-112910 / GHSA-8mx5-7m5m-r77g
More information
Details
filelock on Windows ignores the
modeargument.FileLock(path, mode=0o600)creates the same file asFileLock(path): one with no security descriptor of its own (the Windows record that says who may access a file). Its access list, or ACL, is whatever the lock directory hands down to new files. filelock creates theReadWriteLockdatabase, which it asks to be0o600, the same way. In a directory whose inheritable ACL grants other local accounts access to new files, those accounts can open the lock file or database. They can take the byte-range lock (a lock on a span of bytes in a file) once the owner releases it and keep the owner's lateracquire()calls waiting or timing out. They can read holder metadata anon_acquiredhook left in apreserve_lock_file=Truefile. Where the directory hands down modify access, they can write to both files.lock.modestill reports0o600. The documentation neither promises an ACL on Windows nor says that Windows drops the mode. On Unix the same mode keeps other accounts out. Mutual exclusion between processes that follow the protocol holds on either platform. Affected versions are filelock 3.10.0 through 4.2.0 on Windows.Anthropic's OSS Scanner reported this in private. Finding covered by this advisory:
ANT-2026-0KEO0DDO[medium, CWE-732]: WindowsFileLock ignores mode; 0o600 lock files inherit the directory ACL.Severity
CVSS 3.1
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:Lscores 5.3 (Medium).AV:L(local): the other account needs a logon on the same host.PR:L(low privileges): an ordinary account is enough.UI:N(no user interaction).AC:L(low attack complexity): no race.C:L(partial confidentiality impact): the lock file (holder metadata) and the lock database are readable where0o600was meant to keep them private.I:L(partial integrity impact): in the directory layout the maintainers tested, the other account can also write both files, which lets it corrupt the lock's own state but nothing the lock protects.A:L(partial availability impact): the other account can hold the byte-range lock and make the owner wait or time out.S:U(scope unchanged).Classification from the review: Windows permission failure with security impact only where callers rely on
mode=0o600across accounts. The review had marked it an unconfirmed Windows claim, since the scanner traced stand-in Win32 calls on Linux. The maintainers have since confirmed it on Windows with two local accounts (see Evidence). The scanner rated this medium; the maintainers keep medium.Scope and preconditions
FileLockandAsyncFileLockon Windows (WindowsFileLock), and the SQLite database ofReadWriteLockandAsyncReadWriteLock. Both go through_open_non_reparse_fd. The soft locks create their markers withos.open, which also keeps only a read-only bit of the mode on Windows; the scanner did not examine them further.Users, or any directory with(OI)(CI)entries (entries that new files and sub-directories inherit) for another account. A directory whose ACL already excludes other accounts, such as one inside a user profile, hides the problem.LockFileExdocumentation, read access is enough to take the byte-range lock, so it can hold the lock whenever the owner does not. The lock file exists while the owner holds the lock, and stays after release withpreserve_lock_file=True. TheReadWriteLockdatabase is not unlinked at any point.UnixFileLockcreates the file with the mode and repeats it withfchmod. Mutual exclusion between cooperating processes is not affected.Affected code
Scanned commit
b831496b0273:_open_non_reparse_fdreduces the mode to oneread_onlybit. That bit is false for every accepted mode, because_check_moderejects any mode without owner read and write, and an unset mode becomes0o666. In_nt_opentheOBJECT_ATTRIBUTES.SecurityDescriptorfield stays unassigned, andread_onlyonly choosesFILE_ATTRIBUTE_READONLY._open_lock_databasepasses0o600through the same function on Windows.Introduced
d0061e4 "added multiuser support and associated tests" (#192, 2023-03-15), first tag 3.10.0 (verified), added the
modeparameter and on Windows handed it toos.open, which applies only the read-only attribute. The Windows backend has applied no more of the mode than that at any version, so this is a long-standing gap rather than a regression.Mechanism
_open_non_reparse_fd(path, mode)computesread_only = not mode & _OWNER_WRITEand calls_nt_open(path, read_only=read_only)._nt_openfills anOBJECT_ATTRIBUTESwith the NT path andOBJ_CASE_INSENSITIVEand leavesSecurityDescriptorNULL. It then callsNtCreateFilewithFILE_OPEN_IFandFILE_ATTRIBUTE_NORMAL(orFILE_ATTRIBUTE_READONLYwhenread_only, which no accepted mode produces). Nothing consults the group and other bits. Per theNtCreateFileandOBJECT_ATTRIBUTESdocumentation, a NULL descriptor gives the new file default security, which on NTFS is the set of inheritable entries of the parent directory. A lock file created withmode=0o600in a directory that hands down read access toUsersis therefore readable byUsers.Nothing tells the caller. The constructor validates the mode,
lock.modereturns0o600, andhas_explicit_modeisTrue.docs/concepts.rstsays "filelock creates the file with it" and that "0o600and0o700keep other UIDs out", with no Windows caveat. Only the_open_non_reparse_fddocstring and a comment in_soft.pyrecord the limitation.Reproduction
The scanner's reproducer for
ANT-2026-0KEO0DDO, quoted as received. It ran against commitb831496b0273.reprorepro.d/job_with_default_lock.pyrepro.d/job_with_private_lock.pyrepro.d/run_on_windows_backend.pyFailure sequence
sequenceDiagram participant O as owner process: FileLock(path, mode=0o600) participant N as NtCreateFile participant F as lock file (inherits the directory ACL) participant U as other local account O->>N: _open_non_reparse_fd(path, 0o600): read_only=False, SecurityDescriptor=NULL rect rgb(255, 214, 214) N-->>F: created with the parent's inheritable entries only, group and other bits not consulted Note over F: the file reports mode 0o600 to the owner, the ACL says otherwise end O->>F: LockFileEx (holds the lock), release, unlock U->>F: open for read (and write, where the directory hands down modify) U->>F: LockFileEx through that handle O->>F: acquire() -> waits or Timeout while U holds the byte-range lock U->>F: read holder metadata left by on_acquired with preserve_lock_file=TrueEvidence
The scanner's reproducer runs on a Linux image. It imports filelock's unmodified Windows backend with
sys.platform == "win32"over stand-ins that print every Win32 call. The program withmode=0o600and the one without produce identical call lists (RtlDosPathNameToNtPathName_U_WithStatus,NtCreateFilewithFileAttributes=0x80andObjectAttributes.SecurityDescriptor=None,RtlFreeUnicodeString,GetFileInformationByHandle,LockFileEx,UnlockFileEx), while the Unix control produced0o600and0o644files. It printsOBSERVED the two Win32 call lists are identical: TrueandBUG. The scanner stated that it inferred the resulting ACL, and what another user can then do, from the documentation and did not run on Windows.Maintainer triage: the stand-in reproducer prints
BUGon the scanned commitb831496and on the 4.2.0 release image.Maintainer verification on Windows 11 with two local accounts: a script creates
private.lockwithFileLock(mode=0o600, preserve_lock_file=True),default.lockwithout a mode, and aReadWriteLockdatabaselock.dbas the first account, in a directory granted(OI)(CI)(M)to a second account that is a member ofUsers. It then opens each file under the second account's logon token withLogonUserWandImpersonateLoggedOnUser. On 4.2.0 the second account could openprivate.lockandlock.dbfor both read and write, the same asdefault.lock, andicaclslisted only inherited(I)entries on all three. This confirms the claim the review had marked unconfirmed.Impact
A program that passes
mode=0o600so that other accounts cannot open its lock file gets no such restriction on Windows. In a directory that hands down read access, another account can hold the lock and make the owner wait or time out, and read holder metadata in a preserved lock file. Where the directory hands down modify access, as in the maintainers' test, it can also write the lock file and theReadWriteLockdatabase. With the mode honoured, as on Unix, a user without write access to the directory can do none of this. The exposure ends there: the effect reaches only the lock file or lock database, and mutual exclusion between processes that follow the protocol still holds.Workarounds
ReadWriteLockdatabases in a directory whose ACL already excludes other accounts (inside the user profile, or a directory with inheritance disabled and only the owner,SYSTEMandAdministratorsgranted), rather than relying onmode.preserve_lock_file=Trueor aReadWriteLockdatabase, set its ACL yourself, for exampleicacls <file> /inheritance:r /grant:r "<owner>:F" "SYSTEM:F" "Administrators:F"; a file that exists keeps its ACL on later opens.on_acquiredon Windows.Patched version
4.2.1.
Fix: https://github.com/tox-dev/filelock/pull/835
Credits
Reported by Anthropic's OSS Scanner (automated analysis), 15 October 2026; reviewed by the maintainers.
Severity
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:LReferences
This data is provided by the GitHub Advisory Database (CC-BY 4.0).
filelock: UnixFileLock truncates and chmods any regular file another user renames or hard-links onto the lock path
CVE-2026-112909 / GHSA-69hj-f68j-2879
More information
Details
UnixFileLock, the backend ofFileLockandAsyncFileLockon Unix, empties whatever regular file it finds at the lock path once it holds theflock(a kernel lock on an open file). With an explicitmodeit also chmods that file (sets its permission bits), whether or not this acquire created it. Another local user who can rename or hard-link one of the files of the user running the lock (below: the lock user) onto the lock path gets that file truncated by the lock user's nextacquire(). A hard link is a second name for the same file. With a mode such as0o666the file, still owned by the lock user, also becomes readable and writable by that other user. The other user can then read and alter everything the lock user writes to it afterwards.O_NOFOLLOW, the defence added for the symlink variant (CVE-2025-68146), does not see a renamed file or a hard link. The rename route needs the file's directory to be writable without the sticky bit (a directory flag that lets only a file's owner remove or rename it). The hard-link route into a sticky directory such as/tmpneedsfs.protected_hardlinks=0, a Linux kernel setting. Affected versions are every filelock release up to and including 4.2.0 (the truncation is as old as the project; the chmod since 3.10.2).Anthropic's OSS Scanner reported this in private. Finding covered by this advisory:
ANT-2026-KO573NWI[high, CWE-706]: UnixFileLock truncates and chmods victim files renamed onto the lock path.Severity
CVSS 3.1
CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:H/A:Nscores 6.1 (Medium).AV:L(local): the other user needs an account on the same host.PR:L(low privileges): an ordinary account is enough.UI:N(no user interaction).AC:L(low attack complexity): one rename or link, then wait for the lock user's next acquire; no race.I:H(high integrity impact): the lock user's own process truncates a file it did not mean to touch, including content behind a second name the other user could neither modify nor delete. With a permissive explicitmodethe other user can then write to it. If that file is one the lock user later executes or trusts, that is code execution as the lock user.C:L(partial confidentiality impact): the old content is gone before the other user can read anything, but what the lock user writes afterwards through a descriptor (the number the kernel gives a process for an open file) it still holds is readable.A:N(no availability impact).S:U(scope unchanged).Classification from the review: security, conditional on another user controlling names in a non-sticky directory on the lock's filesystem (or on
fs.protected_hardlinks=0). The scanner rated this high. The maintainers score it medium because the reachable targets depend on the directory layout and kernel settings described below.Scope and preconditions
FileLockandAsyncFileLockon Unix (UnixFileLock).SoftFileLockapplies an explicit mode only to a file it created withO_CREAT | O_EXCLand does not truncate an existing file.WindowsFileLockhas not truncated at any version./tmpcleaner, or after a release with the defaultpreserve_lock_file=False, which unlinks the file. The scanner checked three ways at the scanned commit, with default kernel settings unless stated:0777directory);1777) on the same filesystem. The sticky bit only protects entries that already exist, so the move succeeds while the lock path is free. Once the lock user's lock file exists there, the same move fails withEPERM;link(2)into a sticky directory. This needs a system that lets a user hard-link a file it cannot write, which on Linux meansfs.protected_hardlinks=0. Mainstream distributions set 1, which refuses the link. The scanner did not test macOS or the BSDs.FileLock(path)the lock truncates the file, which keeps its mode. With an explicitmode(a lock shared between users needs0o666or0o660, becauseUnixFileLockopens the file read-write), the lock also chmods the file to that mode._apply_explicit_modesuppressesPermissionErroronly for files the lock user does not own. The lock user owns its own files, so thefchmodsucceeds.O_NOFOLLOWmakes the open fail withELOOP; mutual exclusion between cooperating processes.Affected code
Scanned commit
b831496b0273:UnixFileLock._finalize_locked_fd, whoseos.ftruncateand_apply_explicit_modecalls have only thest_nlink != 0guard (the file still has at least one name);_apply_explicit_mode;_open_lock_file, which learns from itsO_EXCLcreate whether this attempt made the file but hands that flag only to theENOSYSfallback.Introduced
The truncation of whatever is at the lock path dates from the initial commit (2157efb, which opened with
O_TRUNC). The chmod of a pre-existing inode (the kernel's identity for a file, independent of its name) came with d7e1e84 "changed from os.umask to os.chmod" (#206, 2023-03-22), first tag 3.10.2 (verified withgit tag --contains). Before it the code passed the mode only toopen(), which applies it to a file this call creates. The advisory range is therefore every release up to 4.2.0. The earlier group range>= 3.10.0understated it, as the review noted.Mechanism
_open_lock_filefirst triesos.open(path, O_RDWR | O_NOFOLLOW | O_CREAT | O_EXCL, mode). With the lock user's file renamed to the lock path that fails withFileExistsError. The secondos.open(path, O_RDWR | O_NOFOLLOW)succeeds, because the entry is a regular file the lock user owns, and returnscreated = False._acquire_nativepassescreatedonly to theENOSYSbranch. No process holds aflockon the renamed file, so_lock_fd_nonblocking(fd)succeeds at once and_finalize_locked_fd(fd)runs:os.fstat,st_nlink != 0,os.ftruncate(fd, 0), thenos.fchmod(fd, mode)when the lock has an explicit mode. Nothing in that path tells a lock file from any other regular file; a link count of 2 and a non-empty file both pass.O_NOFOLLOWdoes not help because the entry is the file itself (or a hard link, an ordinary directory entry for the same inode), not a symlink to it. There is no race: the other user renames or links once and waits for the next acquire.AsyncUnixFileLockinherits_finalize_locked_fdunchanged.The scanner measured three variants at the same commit, same accounts (
victimuid 1000,attackeruid 1001). First, a rename within a0777directory: the nextFileLock("jobs.lock", mode=0o666)ofvictimempties the0600journal ofvictimrenamed tojobs.lockand sets it to0666;attackerthen reads whatvictimkeeps writing through its open descriptor. Second, a rename of a two-name file (ln /tmp/cache/blob ~/env/blob,0644) from a0777directory,fs.protected_hardlinks=1: aftermv /tmp/cache/blob /tmp/cache/app.lockandFileLock("/tmp/cache/app.lock", mode=0o666)asvictim,~/env/blobhas2 links, mode 666, 0 bytesandecho pwned >> /home/victim/env/blobasattackersucceeds, in a directoryattackercannot write. Third,os.link(notes, lock_path)in a1777directory withfs.protected_hardlinks=0:notes.txt(0644, in the home ofvictim) ends up 0 bytes with mode0666, andopen(notes, "w")asattackerthen succeeds. With plainFileLock(lock_path)a0600file ends up empty with its mode unchanged. The planted name stays after release, so every later acquire truncates the file again.Reproduction
The scanner's reproducer for
ANT-2026-KO573NWI, quoted as received. It ran against commitb831496b0273.reprorepro.d/attacker_read_file.pyrepro.d/attacker_rename_journal.pyrepro.d/victim_job_runner.pyAttack sequence
sequenceDiagram participant A as other account participant D as shared directory (writable, not sticky) participant V as lock user: FileLock("jobs.lock", mode=0o666) participant K as kernel Note over V,D: victim-journal.log, owner victim, mode 0600 (the other account cannot read it) A->>D: mv victim-journal.log jobs.lock (one rename, no race) V->>K: open(jobs.lock, O_RDWR|O_NOFOLLOW|O_CREAT|O_EXCL) - > [!IMPORTANT] > ✂ PR body was truncated to here.