CVE-2025-68146·Python vulnerability
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.
- Severity
- medium
- Software
- Python
- Fixed in
- 3.20.1
- Published
- 2025-12-16
Affected versions
Until: 3.20.1
Fixed in: 3.20.1
How to fix this CVE
Update Python's filelock library to version 3.20.1 or later to patch a race condition vulnerability in lock file creation. This vulnerability allows local attackers to corrupt or truncate arbitrary files through symlink attacks on Unix, Linux, macOS, and Windows systems. Ensure all dependent applications using filelock are also updated to mitigate cascading risks.
sudo dnf update python3-filelockDefensia detects this vulnerability
How to check if you are affected
- Step 1: Check the installed filelock version by running: python3 -c "import filelock; print(filelock.__version__)"
- Step 2: Identify applications using filelock by searching for imports: grep -r "from filelock import\|import filelock" /opt /home /srv --include="*.py"
- Step 3: Monitor lock file directories for unexpected symlinks created by unprivileged users: find /tmp /var/tmp -type l -mtime -1 2>/dev/null | xargs ls -la
- Step 4: Verify the patch by confirming filelock version is 3.20.1 or later: python3 -c "import filelock; assert filelock.__version__ >= '3.20.1'"
FAQ
What is CVE-2025-68146?
CVE-2025-68146 is a Time-of-Check-Time-of-Use (TOCTOU) race condition in Python's filelock library that enables local attackers to truncate or corrupt arbitrary files by creating symlinks between the lock file existence check and file open operations.
Is CVE-2025-68146 being actively exploited?
No, CVE-2025-68146 is not currently listed in CISA's Known Exploited Vulnerabilities catalog, and no public exploits are available. However, the vulnerability is practical to exploit given local filesystem access and predictable lock file paths.
What versions of Python are affected by CVE-2025-68146?
All versions of the filelock library prior to 3.20.1 are affected. The vulnerability impacts filelock on all platforms including Unix, Linux, macOS, and Windows systems.
How do I check if my server is vulnerable to CVE-2025-68146?
Run: python3 -c "import filelock; print('Vulnerable' if filelock.__version__ < '3.20.1' else 'Patched')" to determine your current filelock version status.
Does Defensia detect CVE-2025-68146?
Yes — Defensia's CVE advisory scanner compares installed package versions against the NVD database. If Python's filelock library is installed on a monitored server, CVE-2025-68146 will appear in your dashboard with remediation steps.
Related Python CVEs
References
Track CVEs across your fleet automatically
Defensia scans your Linux servers and tells you exactly which ones are running vulnerable versions — including CVE-2025-68146. Free for 1 server.
Get started free