VAITP Dataset

← Back to the dataset

CVE-2026-112938

TOCTOU symlink race in filelock lets an attacker swap coordination paths, hijack claims and bypass strict locks.

  • CVSS 5.8
  • CWE-363
  • Race Conditions
  • Local

filelock is a platform-independent file lock for Python. From 3.30.0 until 4.2.1, On POSIX platforms, StrictSoftFileLock and AsyncStrictSoftFileLock validate the coordination directory in _ensure_protocol_directory but later reach the claims directory through _open_directory by pathname, allowing a local account that can rename the coordination name to swap in a symbolic link between check and use during acquisition. That race can create and leave claim files in another writable directory or strand claims in a different strict lock so the second lock times out. Separately, the claims property and force_break follow a resting symbolic link without a race when the lock user inspects or recovers the lock. Claims inspection discloses a file name to the other account only if the resulting exception text or claim_name reaches that account through a shared log, CI output, or error report. A blind force_break recovery that removes live claims from another strict lock can allow two processes into that lock's critical section; this path reaches other strict locks, not arbitrary files. This issue is fixed in version 4.2.1.

CVSS base score
5.8
Published
2026-11-05
OWASP
A04 Insecure Design
Orthogonal defect classification
Timing/Serialization
Code defect classification
Timing Issues
Category
Race Conditions
Subcategory
Time-of-Check to Time-of-Use
Accessibility scope
Local
Impact
Unauthorized Access
Affected component
filelock
Fixed by upgrading
Yes

Solution

Upgrade filelock to version 4.2.1 or later.

Vulnerable code sample

import os
import filelock

def acquire_strict_lock(coord_dir: str) -> filelock.StrictSoftFileLock:
    # VULNERABLE: TOCTOU between directory existence check and lock file creation
    if not os.path.isdir(coord_dir):
        os.mkdir(coord_dir)
    lock_path = os.path.join(coord_dir, "resource.lock")
    lock = filelock.StrictSoftFileLock(lock_path)
    lock.acquire()
    return lock

Patched code sample

import os
import filelock

def acquire_strict_lock(coord_dir: str) -> filelock.StrictSoftFileLock:
    # FIX: open coordination directory with O_NOFOLLOW to prevent symlink race
    fd = os.open(coord_dir, os.O_RDONLY | getattr(os, "O_NOFOLLOW", 0))
    os.close(fd)  # directory existence is now verified without following symlinks
    lock_path = os.path.join(coord_dir, "resource.lock")
    lock = filelock.StrictSoftFileLock(lock_path)
    lock.acquire()
    return lock

Published fix

Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.

  • fix(strict): reach claims through dir descriptors (tox-dev/filelock)
    src/filelock/_strict.py, src/filelock/_strict.py · StrictSoftFileLock._acquire, src/filelock/_strict.py · StrictSoftFileLock._attempt_doorway, src/filelock/_strict.py · _attempt_claim_read, src/filelock/_strict.py · _ensure_protocol_directory, src/filelock/_strict.py · _filesystem_now, src/filelock/_strict.py · _inspect_lock_path, src/filelock/_strict.py · _link_no_replace, src/filelock/_strict.py · _list_claim_names, src/filelock/_strict.py · _open_directory, src/filelock/_strict.py · _open_record, src/filelock/_strict.py · _public_claim_names and 9 more
  • =?UTF-8?q?=F0=9F=90=9B=20fix(strict):=20keep=20claim=20di?= (tox-dev/filelock)
    src/filelock/_lease.py, src/filelock/_soft_rw/_protocol.py, src/filelock/_soft_rw/_protocol.py · Files.create, src/filelock/_soft_rw/_protocol.py · Files.overwrite, src/filelock/_soft_rw/_protocol.py · GenerationLog.commit, src/filelock/_soft_rw/_protocol.py · GenerationLog._extends_the_log, src/filelock/_soft_rw/_protocol.py · GenerationLog._list, src/filelock/_soft_rw/_protocol.py · Ledger.observe, src/filelock/_soft_rw/_protocol.py · Participant.heartbeat, src/filelock/_soft_rw/_protocol.py · Participant.leave, src/filelock/_soft_rw/_protocol.py · Participant._create_holder, src/filelock/_soft_rw/_protocol.py · Participant._refresh_nonce and 34 more

Cite this entry

@misc{vaitp:cve2026112938,
  title        = {{TOCTOU symlink race in filelock lets an attacker swap coordination paths, hijack claims and bypass strict locks.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-112938},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-112938/}}
}

Download this entry as JSON Download the whole dataset

Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.