Description
filelock is a platform-independent file lock for Python. In versions prior to 3.20.1, 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. All users of filelock on Unix, Linux, macOS, and Windows systems are impacted. The vulnerability cascades to dependent libraries. The 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. The issue is fixed in version 3.20.1. If immediate upgrade is not possible, use SoftFileLock instead of UnixFileLock/WindowsFileLock (note: different locking semantics, may not be suitable for all use cases); ensure lock file directories have restrictive permissions (chmod 0700) to prevent untrusted users from creating symlinks; and/or monitor lock file directories for suspicious symlinks before running trusted applications. These workarounds provide only partial mitigation. The race condition remains exploitable. Upgrading to version 3.20.1 is strongly recommended.
Problem types
CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition
CWE-59: Improper Link Resolution Before File Access ('Link Following')
CWE-362: Concurrent Execution using Shared Resource with Improper Synchronization ('Race Condition')
Product status
References
github.com/...lelock/security/advisories/GHSA-w853-jp5j-5j7f
github.com/tox-dev/filelock/pull/461
github.com/...ommit/4724d7f8c3393ec1f048c93933e6e3e6ec321f0e
github.com/tox-dev/filelock/releases/tag/3.20.1
Data based on CVE®. Copyright © 1999-2025, The MITRE Corporation. All rights reserved.