CVE-2025-68146
Time-of-Check-Time-of-Use (TOCTOU) vulnerability in filelock (PyPI)

Time-of-Check-Time-of-Use (TOCTOU) No known exploit Fixable By Resolved Security

What is CVE-2025-68146 About?

This TOCTOU race condition in the `filelock` library allows local attackers to truncate or corrupt arbitrary user files through symlink attacks. It occurs during lock file creation when a check for file existence or writability is followed by an `os.open()` call with `O_TRUNC` without sufficient safeguards. By creating a symlink in the race window, an attacker can redirect the `O_TRUNC` operation to a victim file, making it relatively easy for a local attacker to exploit reliably.

Affected Software

filelock <3.20.1

Technical Details

The filelock library is vulnerable to a TOCTOU (Time-of-Check-Time-of-Use) race condition during its lock file acquisition process. In UnixFileLock, a Path(self.lock_file).exists() check (T0) precedes an os.open() call with os.O_RDWR | os.O_TRUNC (T3). In WindowsFileLock, a writability check (T0) is followed by an os.open() with os.O_RDWR | os.O_CREAT | os.O_TRUNC (T3). An attacker can exploit the race window (T1-T2) by removing the legitimate lock file and then creating a symbolic link (or reparse point on Windows) at the lock_file's path, pointing to an arbitrary victim_file (e.g., /home/victim/.ssh/config). When the victim process then calls os.open() with O_TRUNC, the operating system follows the symlink and truncates the victim_file to zero bytes. This happens because os.open() on Unix (without O_NOFOLLOW) and Windows (without checking for reparse points) resolves symlinks before truncating the target. The checks and the open() call are not atomic, creating the exploitable time gap. The attack is local and relies on creating symlinks.

What is the Impact of CVE-2025-68146?

Successful exploitation may allow attackers to corrupt or truncate arbitrary user files, leading to data loss, denial of service for applications, or system instability. This can result in irreversible damage to critical configuration files, cached data, or even machine learning models.

What is the Exploitability of CVE-2025-68146?

Exploitation of this TOCTOU vulnerability is local, requiring access to the filesystem and the ability to create symlinks (standard user permissions). The complexity is low, and no authentication is needed beyond local system access. No special privileges are required for the attacker, as the vulnerability leverages the victim process's own permissions to truncate its files. The attack is highly reliable, often succeeding within 1-3 attempts due to the short but consistent race window. Factors increasing exploitation likelihood include predictable lock file paths (e.g., in /tmp or user home directories), shared directories with permissive write permissions (e.g., /tmp mode 1777), and the common use of the filelock library by various applications like virtualenv and PyTorch, which creates attractive target files. This vulnerability affects both Unix and Windows systems that use the filelock library without the applied patches.

What are the Known Public Exploits?

PoC Author Link Commentary
No known exploits

What are the Available Fixes for CVE-2025-68146?

A Fix by Resolved Security Exists!
See how we help you strengthen security with automated backported fixes for your libraries.

About the Fix from Resolved Security

The patch prevents file locks from being created on symlinks or reparse points by adding the O_NOFOLLOW flag on Unix systems and explicitly refusing reparse points on Windows. This mitigates CVE-2025-68146, which is a vulnerability where an attacker could exploit a race condition (TOCTOU) and use symlinks or reparse points to make locking code overwrite or truncate arbitrary files. By refusing to follow symlinks or reparse points, the patch closes this attack vector.

Available Upgrade Options

  • filelock
    • <3.20.1 → Upgrade to 3.20.1

Struggling with dependency upgrades?

See how Resolved Security's drop-in replacements make it simple.

Book a demo

Additional Resources

What are Similar Vulnerabilities to CVE-2025-68146?

Similar Vulnerabilities: CVE-2023-45803 , CVE-2023-42465 , CVE-2022-38686 , CVE-2022-25946 , CVE-2021-39293