Dev.to Security 🔐 Cybersecurity 👁 2 📖 3 min read

CVE-2026-144351: CVE-2026-144351: Mutual Exclusion Bypass via Stale Recovery Race Condition in Python filelock SoftFileLock

CVE-2026-144351: Mutual Exclusion Bypass via Stale Recovery Race Condition in Python filelock SoftFileLock Vulnerability ID: CVE-2026-144351 CVSS Score: 3.6 Published: 2026-12-04 CVE-2026-144351 is a time-of-check t

CVE-2026-144351: Mutual Exclusion Bypass via Stale Recovery Race Condition in Python filelock SoftFileLock

Vulnerability ID: CVE-2026-144351
CVSS Score: 3.6
Published: 2026-12-04

CVE-2026-144351 is a time-of-check to time-of-use (TOCTOU) race condition and concurrency control vulnerability in the Python filelock library, specifically affecting the SoftFileLock implementation in versions 4.2.1 through 4.2.12. In multi-user POSIX environments utilizing shared directories with the sticky bit set (such as /tmp) on filesystems supporting atomic name exchange, SoftFileLock swaps foreign-owned recovery records onto the public lock path during stale-marker recovery. Because POSIX sticky directory rules allow a file's owner to unlink their own files regardless of who swapped them into place, the foreign user can delete the active lock file, allowing a competing process to acquire the lock simultaneously and break mutual exclusion.

TL;DR

A race condition in filelock's SoftFileLock (versions 4.2.1 to 4.2.12) allows local users on POSIX systems with atomic file swap support to break mutual exclusion in shared sticky directories like /tmp by unlinking foreign-owned recovery records placed onto the lock path.

Technical Details

  • CWE ID: CWE-367 (TOCTOU Race Condition)
  • CVSS v3.1 Score: 3.6 Low (CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:L/A:L)
  • Attack Vector: Local (Multi-user POSIX sticky directory)
  • Affected Component: SoftFileLock._restore_claimed (src/filelock/_soft.py)
  • Affected Versions: filelock >= 4.2.1, < 4.3.0
  • Patched Version: filelock 4.3.0
  • EPSS Score: 0.20% (10.95th Percentile)
  • CISA KEV Status: Not Listed

Affected Systems

  • tox-dev/filelock (PyPI package: filelock)
  • Python applications utilizing SoftFileLock in shared sticky directories on POSIX systems (Linux, macOS, Android)
  • filelock: >= 4.2.1, < 4.3.0 (Fixed in: 4.3.0)

Code Analysis

Commit: dc52a59

Prevent SoftFileLock from placing another account's recovery record at the lock path under a sticky parent directory (PR #975).

diff --git a/src/filelock/_soft.py b/src/filelock/_soft.py
index 1da37b563..fd9004508 100644
--- a/src/filelock/_soft.py
+++ b/src/filelock/_soft.py
@@ -50,6 +50,7 @@
     exchange_back,
     exchange_names,
     exchange_supported,
+    foreign_owner,
     pin_inode,
     raise_on_not_writable_file,
     remove_own_file,
@@ -376,7 +377,7 @@ def _recover_claimed(

     def _restore_claimed(self, own: str, breaker_pid: int, marker: os.stat_result) -> bool:  # pragma: win32 no cover
         try:
-            content, _ = read_lock_file(own)
+            content, record = read_lock_file(own)
         except OSError:
             self._return_claim(own, breaker_pid)
             return True
@@ -387,8 +388,10 @@ def _restore_claimed(self, own: str, breaker_pid: int, marker: os.stat_result) -
         # The inode of the marker judged dead must still be at the path, or a peer has acted since.
         with suppress(OSError):
             current = os.lstat(self._lock_path)
-            if (current.st_ino, current.st_mtime) == (marker.st_ino, marker.st_mtime) and exchange_names(
-                own, self._lock_path
+            if (
+                foreign_owner(record, Path(self._lock_path).parent.stat()) is None
+                and (current.st_ino, current.st_mtime) == (marker.st_ino, marker.st_mtime)
+                and exchange_names(own, self._lock_path)
             ):
                 if os.lstat(own).st_ino == marker.st_ino:
                     Path(own).unlink()

Mitigation Strategies

  • Upgrade the Python filelock library to version 4.3.0 or later to enforce ownership checks prior to atomic file exchange in sticky directories.
  • Avoid storing SoftFileLock marker files in shared world-writable sticky directories such as /tmp or /var/tmp.
  • Store lock files in isolated, user-owned directories with 0700 permissions (e.g., XDG_RUNTIME_DIR).
  • Prefer OS kernel-backed locks (FileLock / UnixFileLock using flock/fcntl) over SoftFileLock on local POSIX filesystems.

Remediation Steps:

  1. Audit Python environments and dependency lockfiles (requirements.txt, poetry.lock, Pipfile.lock) for filelock versions between 4.2.1 and 4.2.12.
  2. Run pip install --upgrade "filelock>=4.3.0" across affected deployments and container images.
  3. Verify that any custom SoftFileLock instantiations use dedicated, non-world-writable directories when running on multi-user systems.

References

Read the full report for CVE-2026-144351 on our website for more details including interactive diagrams and full exploit analysis.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.