{"id":"CVE-2026-22701","aliases":["CVE-2026-22701","GHSA-qmgc-5h2g-mvrw","PYSEC-2026-1374"],"related":[],"kind":"vulnerability","state":"published","title":"filelock Time-of-Check-Time-of-Use (TOCTOU) Symlink Vulnerability in SoftFileLock","summary":"filelock is a platform-independent file lock for Python. Prior to version 3.20.3, a TOCTOU race condition vulnerability exists in the SoftFileLock implementation of the filelock package. An attacker with local filesystem access and permission to create symlinks can exploit a race condition between the permission validation and file creation to cause lock operations to fail or behave unexpectedly. The vulnerability occurs in the _acquire() method between raise_on_not_writable_file() (permission check) and os.open() (file creation). During this race window, an attacker can create a symlink at the lock file path, potentially causing the lock to operate on an unintended target file or leading to denial of service. This issue has been patched in version 3.20.3.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"filelock is a platform-independent file lock for Python. Prior to version 3.20.3, a TOCTOU race condition vulnerability exists in the SoftFileLock implementation of the filelock package. An attacker with local filesystem access and permission to create symlinks can exploit a race condition between the permission validation and file creation to cause lock operations to fail or behave unexpectedly. The vulnerability occurs in the _acquire() method between raise_on_not_writable_file() (permission check) and os.open() (file creation). During this race window, an attacker can create a symlink at the lock file path, potentially causing the lock to operate on an unintended target file or leading to denial of service. This issue has been patched in version 3.20.3.","source":"cvelist"},{"lang":"en","text":"## Vulnerability Summary\n\n**Title:** Time-of-Check-Time-of-Use (TOCTOU) Symlink Vulnerability in SoftFileLock\n\n**Affected Component:** `filelock` package - `SoftFileLock` class\n**File:** `src/filelock/_soft.py` lines 17-27\n**CWE:** CWE-362, CWE-367, CWE-59\n\n---\n\n## Description\n\nA TOCTOU race condition vulnerability exists in the `SoftFileLock` implementation of the filelock package. An attacker with local filesystem access and permission to create symlinks can exploit a race condition between the permission validation and file creation to cause lock operations to fail or behave unexpectedly.\n\nThe vulnerability occurs in the `_acquire()` method between `raise_on_not_writable_file()` (permission check) and `os.open()` (file creation). During this race window, an attacker can create a symlink at the lock file path, potentially causing the lock to operate on an unintended target file or leading to denial of service.\n\n### Attack Scenario\n\n```\n1. Lock attempts to acquire on /tmp/app.lock\n2. Permission validation passes\n3. [RACE WINDOW] - Attacker creates: ln -s /tmp/important.txt /tmp/app.lock\n4. os.open() tries to create lock file\n5. Lock operates on attacker-controlled target file or fails\n```\n\n---\n\n## Impact\n\n_What kind of vulnerability is it? Who is impacted?_\n\nThis is a **Time-of-Check-Time-of-Use (TOCTOU) race condition vulnerability** affecting any application using `SoftFileLock` for inter-process synchronization.\n\n**Affected Users:**\n- Applications using `filelock.SoftFileLock` directly\n- Applications using the fallback `FileLock` on systems without `fcntl` support (e.g., GraalPy)\n\n**Consequences:**\n- **Silent lock acquisition failure** - applications may not detect that exclusive resource access is not guaranteed\n- **Denial of Service** - attacker can prevent lock file creation by maintaining symlink\n- **Resource serialization failures** - multiple processes may acquire \"locks\" simultaneously\n- **Unintended file operations** - lock could operate on attacker-controlled files\n\n**CVSS v4.0 Score:** 5.6 (Medium)\n**Vector:** CVSS:4.0/AV:L/AT:L/PR:L/UI:N/VC:N/VI:L/VA:H/SC:N/SI:N/SA:N\n\n**Attack Requirements:**\n- Local filesystem access to the directory containing lock files\n- Permission to create symlinks (standard for regular unprivileged users on Unix/Linux)\n- Ability to time the symlink creation during the narrow race window\n\n---\n\n## Patches\n\n_Has the problem been patched? What versions should users upgrade to?_\n\nYes, the vulnerability has been patched by adding the `O_NOFOLLOW` flag to prevent symlink following during lock file creation.\n\n**Patched Version:** Next release (commit: 255ed068bc85d1ef406e50a135e1459170dd1bf0)\n\n**Mitigation Details:**\n- The `O_NOFOLLOW` flag is added conditionally and gracefully degrades on platforms without support\n- On platforms with `O_NOFOLLOW` support (most modern systems): symlink attacks are completely prevented\n- On platforms without `O_NOFOLLOW` (e.g., GraalPy): TOCTOU window remains but is documented\n\n**Users should:**\n- Upgrade to the patched version when available\n- For critical deployments, consider using `UnixFileLock` or `WindowsFileLock` instead of the fallback `SoftFileLock`\n\n---\n\n## Workarounds\n\n_Is there a way for users to fix or remediate the vulnerability without upgrading?_\n\nFor users unable to update immediately:\n\n1. **Avoid `SoftFileLock` in security-sensitive contexts** - use `UnixFileLock` or `WindowsFileLock` when available (these were already patched for CVE-2025-68146)\n\n2. **Restrict filesystem permissions** - prevent untrusted users from creating symlinks in lock file directories:\n   ```bash\n   chmod 700 /path/to/lock/directory\n   ```\n\n3. **Use process isolation** - isolate untrusted code from lock file paths to prevent symlink creation\n\n4. **Monitor lock operations** - implement application-level checks to verify lock acquisitions are successful before proceeding with critical operations\n\n---\n\n## References\n\n_Are there any links users can visit to find out more?_\n\n- **Similar Vulnerability:** CVE-2025-68146 (TOCTOU vulnerability in UnixFileLock/WindowsFileLock)\n- **CWE-362 (Concurrent Execution using Shared Resource):** https://cwe.mitre.org/data/definitions/362.html\n- **CWE-367 (Time-of-check Time-of-use Race Condition):** https://cwe.mitre.org/data/definitions/367.html\n- **CWE-59 (Improper Link Resolution Before File Access):** https://cwe.mitre.org/data/definitions/59.html\n- **O_NOFOLLOW documentation:** https://man7.org/linux/man-pages/man2/open.2.html\n- **GitHub Repository:** https://github.com/tox-dev/filelock\n\n---\n\n**Reported by:** George Tsigourakos (@tsigouris007)","format":"markdown","source":"ghsa"},{"lang":"es","text":"filelock es un bloqueo de archivos independiente de la plataforma para Python. Antes de la versión 3.20.3, existe una vulnerabilidad de condición de carrera TOCTOU en la implementación SoftFileLock del paquete filelock. Un atacante con acceso al sistema de archivos local y permiso para crear enlaces simbólicos puede explotar una condición de carrera entre la validación de permisos y la creación de archivos para hacer que las operaciones de bloqueo fallen o se comporten de manera inesperada. La vulnerabilidad ocurre en el método _acquire() entre raise_on_not_writable_file() ('verificación de permisos') y os.open() ('creación de archivos'). Durante esta ventana de carrera, un atacante puede crear un enlace simbólico en la ruta del archivo de bloqueo, lo que podría hacer que el bloqueo opere en un archivo de destino no deseado o que conduzca a una denegación de servicio. Este problema ha sido parcheado en la versión 3.20.3.","source":"nvd"}],"published":"2026-01-10T05:59:28.872Z","modified":"2026-09-10T03:50:33.702Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:L/A:H","score":5.3,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:L/A:H","score":5.3,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:L/A:H","score":5.3,"rating":"MEDIUM"},{"scorer":"PyPA Advisory Database","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:L/A:H","score":5.3,"rating":"MEDIUM"}],"cwes":["CWE-59","CWE-362","CWE-367"],"affected":[{"ranges":[{"version":"< 3.20.3","status":"affected"}],"vendor":"tox-dev","product":"filelock","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"3.20.3"}],"ecosystem":"PyPI","package":"filelock","purl":"pkg:pypi/filelock","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"3.20.3"}],"vendor":"tox-dev","product":"filelock","cpe":"cpe:2.3:a:tox-dev:filelock:*:*:*:*:*:python:*:*","source":"nvd"},{"ranges":[{"type":"ecosystem","introduced":"0","status":"affected","fixed":"3.20.3"}],"ecosystem":"PyPI","package":"filelock","purl":"pkg:pypi/filelock","source":"pysec"}],"references":[{"url":"https://github.com/tox-dev/filelock/security/advisories/GHSA-qmgc-5h2g-mvrw","tags":["mitigation","patch","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/tox-dev/filelock/commit/255ed068bc85d1ef406e50a135e1459170dd1bf0","tags":["patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://github.com/tox-dev/filelock/commit/41b42dd2c72aecf7da83dbda5903b8087dddc4d5","tags":["patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd","pysec"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-22701","tags":["advisory"],"sources":["ghsa","pysec"]},{"url":"https://github.com/tox-dev/filelock","tags":["package"],"sources":["ghsa","pysec"]},{"url":"https://pypi.org/project/filelock","tags":["package"],"sources":["pysec"]},{"url":"https://github.com/advisories/GHSA-qmgc-5h2g-mvrw","tags":["advisory"],"sources":["pysec"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"none","automatable":"no","technicalImpact":"partial","date":"2026-01-12T16:45:44.181Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-22701","url":"https://www.cve.org/CVERecord?id=CVE-2026-22701","licence":"CVE Terms of Use","modified":"2026-01-12T16:45:50.638Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-qmgc-5h2g-mvrw","url":"https://github.com/advisories/GHSA-qmgc-5h2g-mvrw","licence":"CC-BY-4.0","modified":"2026-09-10T03:50:33.702Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-22701","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-22701","licence":"Public domain","modified":"2026-06-17T10:20:15.667Z"},{"source":"pysec","name":"PyPA Advisory Database","id":"PYSEC-2026-1374","url":"https://osv.dev/vulnerability/PYSEC-2026-1374","licence":"CC-BY-4.0","modified":"2026-07-07T17:47:14.848Z"}],"updatedAt":"2026-11-25T22:59:12.719Z","epss":{"score":0.00127,"percentile":0.0251,"date":"2026-12-01T12:00:22.000Z"}}