CVE-2026-144385: CVE-2026-144385: TOCTOU Race Condition in filelock ReadWriteLock SQLite Backend
CVE-2026-144385: TOCTOU Race Condition in filelock ReadWriteLock SQLite Backend Vulnerability ID: CVE-2026-144385 CVSS Score: 3.6 Published: 2026-12-04 A Time-of-Check Time-of-Use (TOCTOU) race condition exists in t
CVE-2026-144385: TOCTOU Race Condition in filelock ReadWriteLock SQLite Backend
Vulnerability ID: CVE-2026-144385
CVSS Score: 3.6
Published: 2026-12-04
A Time-of-Check Time-of-Use (TOCTOU) race condition exists in the ReadWriteLock and AsyncReadWriteLock implementations of the Python filelock package prior to version 4.3.0. The library relies on SQLite rollback journal mode to enforce inter-process mutual exclusion on lock files. While filelock performs a pre-connection header check to verify that the SQLite database is not operating in Write-Ahead Logging (WAL) mode, SQLite rereads the database header while waiting for a transaction lock. If a local process with write access to the lock file transitions the database to WAL mode during this waiting period, the mutual exclusion guarantees fail, allowing concurrent callers to acquire overlapping write locks.
TL;DR
Versions of the Python filelock library prior to 4.3.0 contain a local TOCTOU race condition (CWE-367) in the SQLite-backed ReadWriteLock. A local actor with write permissions to the lock file can switch the SQLite journal mode to WAL while a lock acquisition is queued, bypassing mutual exclusion and causing overlapping write critical sections.
⚠️ Exploit Status: POC
Technical Details
- CVE ID: CVE-2026-144385 (GHSA-vggp-mrgc-7g8j)
- Weakness Class: CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition
- Affected Component: tox-dev/filelock (ReadWriteLock & AsyncReadWriteLock)
- 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)
- EPSS Score: 0.204% (10.94th Percentile)
- Attack Vector: Local filesystem write access to shared SQLite lock database
- Security Impact: Mutual exclusion bypass leading to overlapping write critical sections
- Patched Version: filelock >= 4.3.0
Affected Systems
- Python applications utilizing filelock ReadWriteLock or AsyncReadWriteLock (< 4.3.0)
-
filelock: < 4.3.0 (Fixed in:
4.3.0)
Code Analysis
Commit: 2ed77b4
Refuse ReadWriteLock acquisition if SQLite switches to WAL mode while waiting for BEGIN
File: src/filelock/_read_write.py
@@ -31,7 +31,7 @@
import threading
import time
from collections import deque
-from contextlib import contextmanager, suppress
+from contextlib import closing, contextmanager, suppress
from dataclasses import dataclass, field
from itertools import count
from typing import TYPE_CHECKING, ClassVar, Final, Literal, NamedTuple, TypeAlias, cast
@@ -905,6 +905,11 @@ def _configure_and_begin(
# sqlite_schema is an alias added in SQLite 3.33.0; sqlite_master works on every version.
statements += " SELECT name FROM sqlite_master LIMIT 1;"
self._execute_waiting(connection, statements, timeout, blocking=blocking, operation=operation)
+ # SQLite rereads the header while BEGIN waits; a pre-connect check can miss a switch to WAL.
+ with closing(connection.execute("PRAGMA journal_mode;")) as cursor:
+ if ("wal",) in cursor.fetchall():
+ msg = f"refusing a lock database switched to WAL mode while acquiring: {self.lock_file!r}"
+ raise ValueError(msg)
self._raise_if_database_replaced(connection)
Exploit Details
- GitHub: Regression unit test (test_read_write_lock_refuses_wal_switch_during_acquire) demonstrating the WAL mode switch during lock acquisition.
Mitigation Strategies
- Upgrade the Python filelock package to version 4.3.0 or newer to enforce in-transaction journal_mode verification.
- Isolate lock files in dedicated directories with strict permissions (0700) owned solely by the application user.
- Avoid placing SQLite-backed ReadWriteLock files in world-writable directories such as /tmp.
Remediation Steps:
- Identify all Python environments and dependency manifests (requirements.txt, pyproject.toml, Pipfile, poetry.lock) referencing filelock versions prior to 4.3.0.
- Run
pip install --upgrade "filelock>=4.3.0"to install the patched release. - Audit application file-locking paths to ensure lock files reside in restricted directories inaccessible to unprivileged local accounts.
- Restart affected Python services and worker processes to load the updated filelock module.
References
- GitHub Security Advisory: GHSA-vggp-mrgc-7g8j
- Fix Commit 2ed77b40eda2bc7fbd0e14a5cad175295f4973b6
- Pull Request #980: Refuse WAL mode transition during lock acquisition
- filelock Release 4.3.0
- National Vulnerability Database (NVD): CVE-2026-144385
- CVE.org Record: CVE-2026-144385
Read the full report for CVE-2026-144385 on our website for more details including interactive diagrams and full exploit analysis.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.