Skip to content

Conversation

@gaborbernat
Copy link
Member

@gaborbernat gaborbernat commented Jan 9, 2026

Fix TOCTOU symlink vulnerability in SoftFileLock by adding O_NOFOLLOW flag protection.

Vulnerability Details

A Time-of-Check-Time-of-Use (TOCTOU) race condition vulnerability existed in SoftFileLock._acquire() between the permission check and the actual file creation. An attacker with local filesystem access could create a symlink at the lock path during this window, causing the lock to operate on an unintended target file.

Attack scenario:

  1. raise_on_not_writable_file() validates permissions
  2. RACE WINDOW - attacker creates symlink
  3. os.open() tries to open lock path
  4. Without O_NOFOLLOW: symlink is followed, lock operates on wrong file
  5. With O_NOFOLLOW: symlink is rejected, attack prevented

Attack requirements:

  • Local filesystem access
  • Permission to create symlinks (normal for regular users)

Changes Made

Add conditional O_NOFOLLOW flag:

  • Pattern used: o_nofollow = getattr(os, "O_NOFOLLOW", None)
  • Same approach as UnixFileLock (commit 5088854)
  • Gracefully degrades on platforms without O_NOFOLLOW (e.g., GraalPy)

Documentation update:

  • Added security warning about TOCTOU vulnerability
  • Explains protection on platforms with O_NOFOLLOW
  • Recommends UnixFileLock/WindowsFileLock for security-sensitive applications

Why This Fix is Safe

The pre-check (raise_on_not_writable_file) is safe from TOCTOU itself because:

  • It only reads metadata via os.stat() (doesn't follow symlinks for checking)
  • The attack only works if a symlink is followed by a write operation
  • By preventing symlink following in os.open() with O_NOFOLLOW, we block the attack even if the symlink is created during the race window

Security Improvement

Platform O_NOFOLLOW Support Result
Most modern systems ✅ Yes Symlink attacks completely prevented
Rare platforms (GraalPy) ❌ No TOCTOU window remains but documented

Related

Add O_NOFOLLOW flag to prevent symlink attacks. The vulnerability existed
between the permission check and the actual file creation, allowing an
attacker to create a symlink at the lock path.

How the fix prevents the attack:
1. raise_on_not_writable_file() validates permissions (doesn't follow symlinks)
2. RACE WINDOW: attacker creates symlink to target file
3. os.open() with O_NOFOLLOW refuses to follow the symlink
4. Attack is prevented - the symlink won't help attacker

Changes:
- Add conditional O_NOFOLLOW flag (like UnixFileLock does in commit 5088854)
- Gracefully degrade on platforms without O_NOFOLLOW (e.g., GraalPy)
- No behavioral changes to existing code

Security improvement:
- Platforms with O_NOFOLLOW: ✅ Symlink attacks completely prevented
- Platforms without O_NOFOLLOW: ⚠️ TOCTOU window remains but documented

The pre-check (raise_on_not_writable_file) is safe from TOCTOU itself because
it only reads metadata. The attack only works if a symlink is followed by a
write operation. By preventing symlink following in os.open() with O_NOFOLLOW,
the attack is blocked even if the symlink is created during the race window.

Reported by George Tsigourakos (@tsigouris007)

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
@gaborbernat gaborbernat merged commit 41b42dd into tox-dev:main Jan 9, 2026
30 checks passed
ansibuddy pushed a commit to ansible/molecule that referenced this pull request Jan 12, 2026
This PR contains the following updates:

| Package | Change |
[Age](https://docs.renovatebot.com/merge-confidence/) |
[Confidence](https://docs.renovatebot.com/merge-confidence/) | Type |
Update | Pending |
|---|---|---|---|---|---|---|
| [ansible-lint](https://redirect.github.com/ansible/ansible-lint)
([changelog](https://redirect.github.com/ansible/ansible-lint/releases))
| `25.12.2` → `26.1.0` |
![age](https://developer.mend.io/api/mc/badges/age/pypi/ansible-lint/26.1.0?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/ansible-lint/25.12.2/26.1.0?slim=true)
| dependency-groups | major | |
|
[ansible-navigator](https://redirect.github.com/ansible/ansible-navigator)
([changelog](https://redirect.github.com/ansible/ansible-navigator/releases))
| `25.12.0` → `26.1.1` |
![age](https://developer.mend.io/api/mc/badges/age/pypi/ansible-navigator/26.1.1?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/ansible-navigator/25.12.0/26.1.1?slim=true)
| dependency-groups | major | |
|
[ansible/ansible-lint](https://redirect.github.com/ansible/ansible-lint)
| `v25.12.2` → `v26.1.0` |
![age](https://developer.mend.io/api/mc/badges/age/github-tags/ansible%2fansible-lint/v26.1.0?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/github-tags/ansible%2fansible-lint/v25.12.2/v26.1.0?slim=true)
| repository | major | |
|
[astral-sh/ruff-pre-commit](https://redirect.github.com/astral-sh/ruff-pre-commit)
| `v0.14.10` → `v0.14.11` |
![age](https://developer.mend.io/api/mc/badges/age/github-tags/astral-sh%2fruff-pre-commit/v0.14.11?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/github-tags/astral-sh%2fruff-pre-commit/v0.14.10/v0.14.11?slim=true)
| repository | patch | |
|
[astral-sh/uv-pre-commit](https://redirect.github.com/astral-sh/uv-pre-commit)
| `0.9.21` → `0.9.24` |
![age](https://developer.mend.io/api/mc/badges/age/github-tags/astral-sh%2fuv-pre-commit/0.9.24?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/github-tags/astral-sh%2fuv-pre-commit/0.9.21/0.9.24?slim=true)
| repository | patch | |
| [biomejs/pre-commit](https://redirect.github.com/biomejs/pre-commit) |
`v2.3.10` → `v2.3.11` |
![age](https://developer.mend.io/api/mc/badges/age/github-tags/biomejs%2fpre-commit/v2.3.11?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/github-tags/biomejs%2fpre-commit/v2.3.10/v2.3.11?slim=true)
| repository | patch | |
| [filelock](https://redirect.github.com/tox-dev/py-filelock) | `3.20.2`
→ `3.20.3` |
![age](https://developer.mend.io/api/mc/badges/age/pypi/filelock/3.20.3?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/filelock/3.20.2/3.20.3?slim=true)
| dependency-groups | patch | |
| [ruff](https://docs.astral.sh/ruff)
([source](https://redirect.github.com/astral-sh/ruff),
[changelog](https://redirect.github.com/astral-sh/ruff/blob/main/CHANGELOG.md))
| `0.14.10` → `0.14.11` |
![age](https://developer.mend.io/api/mc/badges/age/pypi/ruff/0.14.11?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/ruff/0.14.10/0.14.11?slim=true)
| dependency-groups | patch | |
|
[tombi-toml/tombi-pre-commit](https://redirect.github.com/tombi-toml/tombi-pre-commit)
| `v0.7.14` → `v0.7.16` |
![age](https://developer.mend.io/api/mc/badges/age/github-tags/tombi-toml%2ftombi-pre-commit/v0.7.16?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/github-tags/tombi-toml%2ftombi-pre-commit/v0.7.14/v0.7.16?slim=true)
| repository | patch | `v0.7.17` |
|  | All locks refreshed |  |  |  | lockFileMaintenance |  |
| [build](https://redirect.github.com/pypa/build)
([changelog](https://build.pypa.io/en/stable/changelog.html)) | `1.3.0`
→ `1.4.0` |
![age](https://developer.mend.io/api/mc/badges/age/pypi/build/1.4.0?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/build/1.3.0/1.4.0?slim=true)
| dependency-groups | minor | |
| [tox](https://redirect.github.com/tox-dev/tox)
([changelog](https://tox.wiki/en/latest/changelog.html)) | `4.33.0` →
`4.34.1` |
![age](https://developer.mend.io/api/mc/badges/age/pypi/tox/4.34.1?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/tox/4.33.0/4.34.1?slim=true)
| dependency-groups | minor | |
| [types-jsonschema](https://redirect.github.com/python/typeshed)
([changelog](https://redirect.github.com/typeshed-internal/stub_uploader/blob/main/data/changelogs/jsonschema.md))
| `4.25.1.20251009` → `4.26.0.20260109` |
![age](https://developer.mend.io/api/mc/badges/age/pypi/types-jsonschema/4.26.0.20260109?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/types-jsonschema/4.25.1.20251009/4.26.0.20260109?slim=true)
| dependency-groups | minor | |

Note: The `pre-commit` manager in Renovate is not supported by the
`pre-commit` maintainers or community. Please do not report any problems
there, instead [create a Discussion in the Renovate
repository](https://redirect.github.com/renovatebot/renovate/discussions/new)
if you have any questions.

---

### Release Notes

<details>
<summary>ansible/ansible-lint (ansible-lint)</summary>

###
[`v26.1.0`](https://redirect.github.com/ansible/ansible-lint/releases/tag/v26.1.0)

[Compare
Source](https://redirect.github.com/ansible/ansible-lint/compare/v25.12.2...v26.1.0)

#### Fixes

- fix: implement precise filtering for bracketed sub-tags
([#&#8203;4892](https://redirect.github.com/ansible/ansible-lint/issues/4892))
[@&#8203;Jkhall81](https://redirect.github.com/Jkhall81)
- fix: avoid unnecessary creation of .ansible folders
([#&#8203;4894](https://redirect.github.com/ansible/ansible-lint/issues/4894))
[@&#8203;ssbarnea](https://redirect.github.com/ssbarnea)
- fix: refactor RulesCollection to always require app argument
([#&#8203;4891](https://redirect.github.com/ansible/ansible-lint/issues/4891))
[@&#8203;ssbarnea](https://redirect.github.com/ssbarnea)
- fix: anchor kind discovery to project root
([#&#8203;4763](https://redirect.github.com/ansible/ansible-lint/issues/4763))
([#&#8203;4889](https://redirect.github.com/ansible/ansible-lint/issues/4889))
[@&#8203;Jkhall81](https://redirect.github.com/Jkhall81)
- fix: avoid creating cache directory when listing version
([#&#8203;4865](https://redirect.github.com/ansible/ansible-lint/issues/4865))
[@&#8203;ssbarnea](https://redirect.github.com/ssbarnea)
- fix: ensure exclude\_paths are honored for unparseable files
([#&#8203;4886](https://redirect.github.com/ansible/ansible-lint/issues/4886))
[@&#8203;Jkhall81](https://redirect.github.com/Jkhall81)
- fix: avoid use of pathspec 1.0.0 until yamllint is updated
([#&#8203;4887](https://redirect.github.com/ansible/ansible-lint/issues/4887))
[@&#8203;ssbarnea](https://redirect.github.com/ssbarnea)
- fix: allow valid tabs in lineinfile nested in blocks
([#&#8203;4719](https://redirect.github.com/ansible/ansible-lint/issues/4719))
([#&#8203;4881](https://redirect.github.com/ansible/ansible-lint/issues/4881))
[@&#8203;Jkhall81](https://redirect.github.com/Jkhall81)
- fix: update documentation to clarify requirement to run from project …
([#&#8203;4885](https://redirect.github.com/ansible/ansible-lint/issues/4885))
[@&#8203;Jkhall81](https://redirect.github.com/Jkhall81)
- fix: replace hardcoded /tmp path with secure temp directory (CWE…
([#&#8203;4878](https://redirect.github.com/ansible/ansible-lint/issues/4878))
[@&#8203;Jkhall81](https://redirect.github.com/Jkhall81)
- fix: handle missing keys in \_parse\_failed\_msg to prevent KeyError
([#&#8203;4879](https://redirect.github.com/ansible/ansible-lint/issues/4879))
[@&#8203;Jkhall81](https://redirect.github.com/Jkhall81)
- fix: add argument\_specs to meta schema
([#&#8203;4762](https://redirect.github.com/ansible/ansible-lint/issues/4762))
([#&#8203;4880](https://redirect.github.com/ansible/ansible-lint/issues/4880))
[@&#8203;Jkhall81](https://redirect.github.com/Jkhall81)
- fix: retire -p/--parseable option
([#&#8203;4884](https://redirect.github.com/ansible/ansible-lint/issues/4884))
[@&#8203;ssbarnea](https://redirect.github.com/ssbarnea)
- fix: correct partial-become rule documentation comments
([#&#8203;4876](https://redirect.github.com/ansible/ansible-lint/issues/4876))
[@&#8203;emmanuel-ferdman](https://redirect.github.com/emmanuel-ferdman)

#### Maintenance

- chore: add almalinux platform to meta schemas
([#&#8203;4893](https://redirect.github.com/ansible/ansible-lint/issues/4893))
[@&#8203;thelinuxracoon](https://redirect.github.com/thelinuxracoon)
- chore: refactor testing code to reduce use of get\_app()
([#&#8203;4890](https://redirect.github.com/ansible/ansible-lint/issues/4890))
[@&#8203;ssbarnea](https://redirect.github.com/ssbarnea)
- chore(deps): update all dependencies
([#&#8203;4877](https://redirect.github.com/ansible/ansible-lint/issues/4877))
@&#8203;[renovate\[bot\]](https://redirect.github.com/apps/renovate)

</details>

<details>
<summary>ansible/ansible-navigator (ansible-navigator)</summary>

###
[`v26.1.1`](https://redirect.github.com/ansible/ansible-navigator/releases/tag/v26.1.1)

[Compare
Source](https://redirect.github.com/ansible/ansible-navigator/compare/v26.1.0...v26.1.1)

#### Fixes

- fix: Update version and tests
([#&#8203;2084](https://redirect.github.com/ansible/ansible-navigator/issues/2084))
[@&#8203;alisonlhart](https://redirect.github.com/alisonlhart)

###
[`v26.1.0`](https://redirect.github.com/ansible/ansible-navigator/releases/tag/v26.1.0)

[Compare
Source](https://redirect.github.com/ansible/ansible-navigator/compare/v25.12.0...v26.1.0)

#### Fixes

- fix: mount docker's proxy ssh agent socket when running on macOS
([#&#8203;2055](https://redirect.github.com/ansible/ansible-navigator/issues/2055))
([#&#8203;2076](https://redirect.github.com/ansible/ansible-navigator/issues/2076))
[@&#8203;joonashak](https://redirect.github.com/joonashak)
- fix: Use sys.executable instead of hardcoded Python paths for
introspection
([#&#8203;2072](https://redirect.github.com/ansible/ansible-navigator/issues/2072))
[@&#8203;alisonlhart](https://redirect.github.com/alisonlhart)
- fix: Improve compatiblity with restrictive shell environments
([#&#8203;2073](https://redirect.github.com/ansible/ansible-navigator/issues/2073))
[@&#8203;alisonlhart](https://redirect.github.com/alisonlhart)

</details>

<details>
<summary>astral-sh/ruff-pre-commit (astral-sh/ruff-pre-commit)</summary>

###
[`v0.14.11`](https://redirect.github.com/astral-sh/ruff-pre-commit/releases/tag/v0.14.11)

[Compare
Source](https://redirect.github.com/astral-sh/ruff-pre-commit/compare/v0.14.10...v0.14.11)

See: <https://github.com/astral-sh/ruff/releases/tag/0.14.11>

</details>

<details>
<summary>astral-sh/uv-pre-commit (astral-sh/uv-pre-commit)</summary>

###
[`v0.9.24`](https://redirect.github.com/astral-sh/uv-pre-commit/releases/tag/0.9.24)

[Compare
Source](https://redirect.github.com/astral-sh/uv-pre-commit/compare/0.9.23...0.9.24)

See: <https://github.com/astral-sh/uv/releases/tag/0.9.24>

###
[`v0.9.23`](https://redirect.github.com/astral-sh/uv-pre-commit/releases/tag/0.9.23)

[Compare
Source](https://redirect.github.com/astral-sh/uv-pre-commit/compare/0.9.22...0.9.23)

See: <https://github.com/astral-sh/uv/releases/tag/0.9.23>

###
[`v0.9.22`](https://redirect.github.com/astral-sh/uv-pre-commit/releases/tag/0.9.22)

[Compare
Source](https://redirect.github.com/astral-sh/uv-pre-commit/compare/0.9.21...0.9.22)

See: <https://github.com/astral-sh/uv/releases/tag/0.9.22>

</details>

<details>
<summary>biomejs/pre-commit (biomejs/pre-commit)</summary>

###
[`v2.3.11`](https://redirect.github.com/biomejs/pre-commit/compare/v2.3.10...v2.3.11)

[Compare
Source](https://redirect.github.com/biomejs/pre-commit/compare/v2.3.10...v2.3.11)

</details>

<details>
<summary>tox-dev/py-filelock (filelock)</summary>

###
[`v3.20.3`](https://redirect.github.com/tox-dev/filelock/releases/tag/3.20.3)

[Compare
Source](https://redirect.github.com/tox-dev/py-filelock/compare/3.20.2...3.20.3)

<!-- Release notes generated using configuration in .github/release.yml
at main -->

#### What's Changed

- Fix TOCTOU symlink vulnerability in SoftFileLock by
[@&#8203;gaborbernat](https://redirect.github.com/gaborbernat) in
[tox-dev/filelock#465](https://redirect.github.com/tox-dev/filelock/pull/465)

**Full Changelog**:
<tox-dev/filelock@3.20.2...3.20.3>

</details>

<details>
<summary>astral-sh/ruff (ruff)</summary>

###
[`v0.14.11`](https://redirect.github.com/astral-sh/ruff/blob/HEAD/CHANGELOG.md#01411)

[Compare
Source](https://redirect.github.com/astral-sh/ruff/compare/0.14.10...0.14.11)

Released on 2026-01-08.

##### Preview features

- Consolidate diagnostics for matched disable/enable suppression
comments
([#&#8203;22099](https://redirect.github.com/astral-sh/ruff/pull/22099))
- Report diagnostics for invalid/unmatched range suppression comments
([#&#8203;21908](https://redirect.github.com/astral-sh/ruff/pull/21908))
- \[`airflow`] Passing positional argument into
`airflow.lineage.hook.HookLineageCollector.create_asset` is not allowed
(`AIR303`)
([#&#8203;22046](https://redirect.github.com/astral-sh/ruff/pull/22046))
- \[`refurb`] Mark `FURB192` fix as always unsafe
([#&#8203;22210](https://redirect.github.com/astral-sh/ruff/pull/22210))
- \[`ruff`] Add `non-empty-init-module` (`RUF067`)
([#&#8203;22143](https://redirect.github.com/astral-sh/ruff/pull/22143))

##### Bug fixes

- Fix GitHub format for multi-line diagnostics
([#&#8203;22108](https://redirect.github.com/astral-sh/ruff/pull/22108))
- \[`flake8-unused-arguments`] Mark `**kwargs` in `TypeVar` as used
(`ARG001`)
([#&#8203;22214](https://redirect.github.com/astral-sh/ruff/pull/22214))

##### Rule changes

- Add `help:` subdiagnostics for several Ruff rules that can sometimes
appear to disagree with `ty`
([#&#8203;22331](https://redirect.github.com/astral-sh/ruff/pull/22331))
- \[`pylint`] Demote `PLW1510` fix to display-only
([#&#8203;22318](https://redirect.github.com/astral-sh/ruff/pull/22318))
- \[`pylint`] Ignore identical members (`PLR1714`)
([#&#8203;22220](https://redirect.github.com/astral-sh/ruff/pull/22220))
- \[`pylint`] Improve diagnostic range for `PLC0206`
([#&#8203;22312](https://redirect.github.com/astral-sh/ruff/pull/22312))
- \[`ruff`] Improve fix title for `RUF102` invalid rule code
([#&#8203;22100](https://redirect.github.com/astral-sh/ruff/pull/22100))
- \[`flake8-simplify`]: Avoid unnecessary builtins import for `SIM105`
([#&#8203;22358](https://redirect.github.com/astral-sh/ruff/pull/22358))

##### Configuration

- Allow Python 3.15 as valid `target-version` value in preview
([#&#8203;22419](https://redirect.github.com/astral-sh/ruff/pull/22419))
- Check `required-version` before parsing rules
([#&#8203;22410](https://redirect.github.com/astral-sh/ruff/pull/22410))
- Include configured `src` directories when resolving graphs
([#&#8203;22451](https://redirect.github.com/astral-sh/ruff/pull/22451))

##### Documentation

- Update `T201` suggestion to not use root logger to satisfy `LOG015`
([#&#8203;22059](https://redirect.github.com/astral-sh/ruff/pull/22059))
- Fix `iter` example in unsafe fixes doc
([#&#8203;22118](https://redirect.github.com/astral-sh/ruff/pull/22118))
- \[`flake8_print`] better suggestion for `basicConfig` in `T201` docs
([#&#8203;22101](https://redirect.github.com/astral-sh/ruff/pull/22101))
- \[`pylint`] Restore the fix safety docs for `PLW0133`
([#&#8203;22211](https://redirect.github.com/astral-sh/ruff/pull/22211))
- Fix Jupyter notebook discovery info for editors
([#&#8203;22447](https://redirect.github.com/astral-sh/ruff/pull/22447))

##### Contributors

- [@&#8203;charliermarsh](https://redirect.github.com/charliermarsh)
- [@&#8203;ntBre](https://redirect.github.com/ntBre)
- [@&#8203;cenviity](https://redirect.github.com/cenviity)
- [@&#8203;njhearp](https://redirect.github.com/njhearp)
- [@&#8203;cbachhuber](https://redirect.github.com/cbachhuber)
- [@&#8203;jelle-openai](https://redirect.github.com/jelle-openai)
- [@&#8203;AlexWaygood](https://redirect.github.com/AlexWaygood)
- [@&#8203;ValdonVitija](https://redirect.github.com/ValdonVitija)
- [@&#8203;BurntSushi](https://redirect.github.com/BurntSushi)
- [@&#8203;Jkhall81](https://redirect.github.com/Jkhall81)
- [@&#8203;PeterJCLaw](https://redirect.github.com/PeterJCLaw)
- [@&#8203;harupy](https://redirect.github.com/harupy)
- [@&#8203;amyreese](https://redirect.github.com/amyreese)
- [@&#8203;sjyangkevin](https://redirect.github.com/sjyangkevin)
- [@&#8203;woodruffw](https://redirect.github.com/woodruffw)

</details>

<details>
<summary>tombi-toml/tombi-pre-commit
(tombi-toml/tombi-pre-commit)</summary>

###
[`v0.7.16`](https://redirect.github.com/tombi-toml/tombi-pre-commit/releases/tag/v0.7.16)

[Compare
Source](https://redirect.github.com/tombi-toml/tombi-pre-commit/compare/v0.7.15...v0.7.16)

See: <https://github.com/tombi-toml/tombi/releases/tag/v0.7.16>

###
[`v0.7.15`](https://redirect.github.com/tombi-toml/tombi-pre-commit/releases/tag/v0.7.15)

[Compare
Source](https://redirect.github.com/tombi-toml/tombi-pre-commit/compare/v0.7.14...v0.7.15)

See: <https://github.com/tombi-toml/tombi/releases/tag/v0.7.15>

</details>

<details>
<summary>pypa/build (build)</summary>

###
[`v1.4.0`](https://redirect.github.com/pypa/build/blob/HEAD/CHANGELOG.rst#140-2026-01-08)

[Compare
Source](https://redirect.github.com/pypa/build/compare/1.3.0...1.4.0)

\==================

- Add `--quiet` flag
  (:pr:`947`)
- Add option to dump PEP 517 metadata with `--metadata`
  (:pr:`940`, :pr:`943`)
- Support `UV` environment variable
  (:pr:`971`)
- Remove a workaround for 3.14b1
  (:pr:`960`)
- In 3.14 final release, `color` defaults to `True` already
  (:pr:`962`)
- Pass sp-repo-review
  (:pr:`942`)
- In pytest configuration, `log_level` is better than `log_cli_level`
  (:pr:`950`)
- Split up typing and mypy
  (:pr:`944`)
- Use `types-colorama`
  (:pr:`945`)
- In docs, first argument for `_has_dependency` is a name
  (PR :pr:`970`)
- Fix test failure when `flit-core` is installed
  (PR :pr:`921`)

</details>

<details>
<summary>tox-dev/tox (tox)</summary>

###
[`v4.34.1`](https://redirect.github.com/tox-dev/tox/releases/tag/4.34.1)

[Compare
Source](https://redirect.github.com/tox-dev/tox/compare/4.34.0...4.34.1)

<!-- Release notes generated using configuration in .github/release.yml
at 4.34.1 -->

#### What's Changed

- fix: wheel corruption when running parallel tox processes by
[@&#8203;gaborbernat](https://redirect.github.com/gaborbernat) in
[#&#8203;3667](https://redirect.github.com/tox-dev/tox/pull/3667)

**Full Changelog**:
<tox-dev/tox@4.34.0...4.34.1>

###
[`v4.34.0`](https://redirect.github.com/tox-dev/tox/releases/tag/4.34.0)

[Compare
Source](https://redirect.github.com/tox-dev/tox/compare/4.33.0...4.34.0)

<!-- Release notes generated using configuration in .github/release.yml
at 4.34.0 -->

#### What's Changed

- feat: Support depenedcy groups with self references by
[@&#8203;Czaki](https://redirect.github.com/Czaki) in
[#&#8203;3666](https://redirect.github.com/tox-dev/tox/pull/3666)

**Full Changelog**:
<tox-dev/tox@4.33.0...4.34.0>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 4am on monday" in timezone
UTC, Automerge - Between 12:00 AM and 03:59 AM, only on Monday ( * 0-3 *
* 1 ) in timezone UTC.

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the
rebase/retry checkbox.

👻 **Immortal**: This PR will be recreated if closed unmerged. Get
[config
help](https://redirect.github.com/renovatebot/renovate/discussions) if
that's undesired.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/ansible/molecule).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi43NC41IiwidXBkYXRlZEluVmVyIjoiNDIuNzQuNSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiY2hvcmUiLCJkZXBlbmRlbmNpZXMiXX0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
doctrino pushed a commit to cognitedata/toolkit that referenced this pull request Jan 17, 2026
This PR contains the following updates:

| Package | Change |
[Age](https://docs.renovatebot.com/merge-confidence/) |
[Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [filelock](https://redirect.github.com/tox-dev/py-filelock) | `3.20.2`
→ `3.20.3` |
![age](https://developer.mend.io/api/mc/badges/age/pypi/filelock/3.20.3?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/filelock/3.20.2/3.20.3?slim=true)
|

### GitHub Vulnerability Alerts

####
[CVE-2026-22701](https://redirect.github.com/tox-dev/filelock/security/advisories/GHSA-qmgc-5h2g-mvrw)

## Vulnerability Summary

**Title:** Time-of-Check-Time-of-Use (TOCTOU) Symlink Vulnerability in
SoftFileLock

**Affected Component:** `filelock` package - `SoftFileLock` class
**File:** `src/filelock/_soft.py` lines 17-27
**CWE:** CWE-362, CWE-367, CWE-59

---

## Description

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.

### Attack Scenario

```
1. Lock attempts to acquire on /tmp/app.lock
2. Permission validation passes
3. [RACE WINDOW] - Attacker creates: ln -s /tmp/important.txt /tmp/app.lock
4. os.open() tries to create lock file
5. Lock operates on attacker-controlled target file or fails
```

---

## Impact

_What kind of vulnerability is it? Who is impacted?_

This is a **Time-of-Check-Time-of-Use (TOCTOU) race condition
vulnerability** affecting any application using `SoftFileLock` for
inter-process synchronization.

**Affected Users:**
- Applications using `filelock.SoftFileLock` directly
- Applications using the fallback `FileLock` on systems without `fcntl`
support (e.g., GraalPy)

**Consequences:**
- **Silent lock acquisition failure** - applications may not detect that
exclusive resource access is not guaranteed
- **Denial of Service** - attacker can prevent lock file creation by
maintaining symlink
- **Resource serialization failures** - multiple processes may acquire
"locks" simultaneously
- **Unintended file operations** - lock could operate on
attacker-controlled files

**CVSS v4.0 Score:** 5.6 (Medium)
**Vector:** CVSS:4.0/AV:L/AT:L/PR:L/UI:N/VC:N/VI:L/VA:H/SC:N/SI:N/SA:N

**Attack Requirements:**
- Local filesystem access to the directory containing lock files
- Permission to create symlinks (standard for regular unprivileged users
on Unix/Linux)
- Ability to time the symlink creation during the narrow race window

---

## Patches

_Has the problem been patched? What versions should users upgrade to?_

Yes, the vulnerability has been patched by adding the `O_NOFOLLOW` flag
to prevent symlink following during lock file creation.

**Patched Version:** Next release (commit:
255ed068bc85d1ef406e50a135e1459170dd1bf0)

**Mitigation Details:**
- The `O_NOFOLLOW` flag is added conditionally and gracefully degrades
on platforms without support
- On platforms with `O_NOFOLLOW` support (most modern systems): symlink
attacks are completely prevented
- On platforms without `O_NOFOLLOW` (e.g., GraalPy): TOCTOU window
remains but is documented

**Users should:**
- Upgrade to the patched version when available
- For critical deployments, consider using `UnixFileLock` or
`WindowsFileLock` instead of the fallback `SoftFileLock`

---

## Workarounds

_Is there a way for users to fix or remediate the vulnerability without
upgrading?_

For users unable to update immediately:

1. **Avoid `SoftFileLock` in security-sensitive contexts** - use
`UnixFileLock` or `WindowsFileLock` when available (these were already
patched for CVE-2025-68146)

2. **Restrict filesystem permissions** - prevent untrusted users from
creating symlinks in lock file directories:
   ```bash
   chmod 700 /path/to/lock/directory
   ```

3. **Use process isolation** - isolate untrusted code from lock file
paths to prevent symlink creation

4. **Monitor lock operations** - implement application-level checks to
verify lock acquisitions are successful before proceeding with critical
operations

---

## References

_Are there any links users can visit to find out more?_

- **Similar Vulnerability:** CVE-2025-68146 (TOCTOU vulnerability in
UnixFileLock/WindowsFileLock)
- **CWE-362 (Concurrent Execution using Shared Resource):**
https://cwe.mitre.org/data/definitions/362.html
- **CWE-367 (Time-of-check Time-of-use Race Condition):**
https://cwe.mitre.org/data/definitions/367.html
- **CWE-59 (Improper Link Resolution Before File Access):**
https://cwe.mitre.org/data/definitions/59.html
- **O_NOFOLLOW documentation:**
https://man7.org/linux/man-pages/man2/open.2.html
- **GitHub Repository:** https://github.com/tox-dev/filelock

---

**Reported by:** George Tsigourakos (@&#8203;tsigouris007)

---

### Release Notes

<details>
<summary>tox-dev/py-filelock (filelock)</summary>

###
[`v3.20.3`](https://redirect.github.com/tox-dev/filelock/releases/tag/3.20.3)

[Compare
Source](https://redirect.github.com/tox-dev/py-filelock/compare/3.20.2...3.20.3)

<!-- Release notes generated using configuration in .github/release.yml
at main -->

#### What's Changed

- Fix TOCTOU symlink vulnerability in SoftFileLock by
[@&#8203;gaborbernat](https://redirect.github.com/gaborbernat) in
[tox-dev/filelock#465](https://redirect.github.com/tox-dev/filelock/pull/465)

**Full Changelog**:
<tox-dev/filelock@3.20.2...3.20.3>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "" (UTC), Automerge - At any time (no
schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/cognitedata/toolkit).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi43NC41IiwidXBkYXRlZEluVmVyIjoiNDIuNzQuNSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIiwicmVub3ZhdGUiXX0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
renovate bot added a commit to vortex-data/vortex that referenced this pull request Feb 3, 2026
This PR contains the following updates:

| Package | Change |
[Age](https://docs.renovatebot.com/merge-confidence/) |
[Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [filelock](https://redirect.github.com/tox-dev/py-filelock) | `3.20.0`
→ `3.20.3` |
![age](https://developer.mend.io/api/mc/badges/age/pypi/filelock/3.20.3?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/filelock/3.20.0/3.20.3?slim=true)
|

### GitHub Vulnerability Alerts

####
[CVE-2025-68146](https://redirect.github.com/tox-dev/filelock/security/advisories/GHSA-w853-jp5j-5j7f)

### Impact

A Time-of-Check-Time-of-Use (TOCTOU) race condition allows local
attackers to corrupt or truncate arbitrary user files through symlink
attacks. The vulnerability exists in both Unix and Windows lock file
creation where filelock checks if a file exists before opening it with
O_TRUNC. An attacker can create a symlink pointing to a victim file in
the time gap between the check and open, causing os.open() to follow the
symlink and truncate the target file.

**Who is impacted:**

All users of filelock on Unix, Linux, macOS, and Windows systems. The
vulnerability cascades to dependent libraries:

- **virtualenv users**: Configuration files can be overwritten with
virtualenv metadata, leaking sensitive paths
- **PyTorch users**: CPU ISA cache or model checkpoints can be
corrupted, causing crashes or ML pipeline failures
- **poetry/tox users**: through using virtualenv or filelock on their
own.

Attack requires local filesystem access and ability to create symlinks
(standard user permissions on Unix; Developer Mode on Windows 10+).
Exploitation succeeds within 1-3 attempts when lock file paths are
predictable.

### Patches

Fixed in version **3.20.1**.

**Unix/Linux/macOS fix:** Added O_NOFOLLOW flag to os.open() in
UnixFileLock.\_acquire() to prevent symlink following.

**Windows fix:** Added GetFileAttributesW API check to detect reparse
points (symlinks/junctions) before opening files in
WindowsFileLock.\_acquire().

**Users should upgrade to filelock 3.20.1 or later immediately.**

### Workarounds

If immediate upgrade is not possible:

1. Use SoftFileLock instead of UnixFileLock/WindowsFileLock (note:
different locking semantics, may not be suitable for all use cases)
2. Ensure lock file directories have restrictive permissions (chmod
0700) to prevent untrusted users from creating symlinks
3. Monitor lock file directories for suspicious symlinks before running
trusted applications

**Warning:** These workarounds provide only partial mitigation. The race
condition remains exploitable. Upgrading to version 3.20.1 is strongly
recommended.

______________________________________________________________________

## Technical Details: How the Exploit Works

### The Vulnerable Code Pattern

**Unix/Linux/macOS** (`src/filelock/_unix.py:39-44`):

```python
def _acquire(self) -> None:
    ensure_directory_exists(self.lock_file)
    open_flags = os.O_RDWR | os.O_TRUNC  # (1) Prepare to truncate
    if not Path(self.lock_file).exists():  # (2) CHECK: Does file exist?
        open_flags |= os.O_CREAT
    fd = os.open(self.lock_file, open_flags, ...)  # (3) USE: Open and truncate
```

**Windows** (`src/filelock/_windows.py:19-28`):

```python
def _acquire(self) -> None:
    raise_on_not_writable_file(self.lock_file)  # (1) Check writability
    ensure_directory_exists(self.lock_file)
    flags = os.O_RDWR | os.O_CREAT | os.O_TRUNC  # (2) Prepare to truncate
    fd = os.open(self.lock_file, flags, ...)  # (3) Open and truncate
```

### The Race Window

The vulnerability exists in the gap between operations:

**Unix variant:**

```
Time    Victim Thread                          Attacker Thread
----    -------------                          ---------------
T0      Check: lock_file exists? → False
T1                                             ↓ RACE WINDOW
T2                                             Create symlink: lock → victim_file
T3      Open lock_file with O_TRUNC
        → Follows symlink
        → Opens victim_file
        → Truncates victim_file to 0 bytes! ☠️
```

**Windows variant:**

```
Time    Victim Thread                          Attacker Thread
----    -------------                          ---------------
T0      Check: lock_file writable?
T1                                             ↓ RACE WINDOW
T2                                             Create symlink: lock → victim_file
T3      Open lock_file with O_TRUNC
        → Follows symlink/junction
        → Opens victim_file
        → Truncates victim_file to 0 bytes! ☠️
```

### Step-by-Step Attack Flow

**1. Attacker Setup:**

```python

# Attacker identifies target application using filelock
lock_path = "/tmp/myapp.lock"  # Predictable lock path
victim_file = "/home/victim/.ssh/config"  # High-value target
```

**2. Attacker Creates Race Condition:**

```python
import os
import threading

def attacker_thread():
    # Remove any existing lock file
    try:
        os.unlink(lock_path)
    except FileNotFoundError:
        pass

    # Create symlink pointing to victim file
    os.symlink(victim_file, lock_path)
    print(f"[Attacker] Created: {lock_path} → {victim_file}")

# Launch attack
threading.Thread(target=attacker_thread).start()
```

**3. Victim Application Runs:**

```python
from filelock import UnixFileLock

# Normal application code
lock = UnixFileLock("/tmp/myapp.lock")
lock.acquire()  # ← VULNERABILITY TRIGGERED HERE

# At this point, /home/victim/.ssh/config is now 0 bytes!
```

**4. What Happens Inside os.open():**

On Unix systems, when `os.open()` is called:

```c
// Linux kernel behavior (simplified)
int open(const char *pathname, int flags) {
    struct file *f = path_lookup(pathname);  // Resolves symlinks by default!

    if (flags & O_TRUNC) {
        truncate_file(f);  // ← Truncates the TARGET of the symlink
    }

    return file_descriptor;
}
```

Without `O_NOFOLLOW` flag, the kernel follows the symlink and truncates
the target file.

### Why the Attack Succeeds Reliably

**Timing Characteristics:**

- **Check operation** (Path.exists()): ~100-500 nanoseconds
- **Symlink creation** (os.symlink()): ~1-10 microseconds
- **Race window**: ~1-5 microseconds (very small but exploitable)
- **Thread scheduling quantum**: ~1-10 milliseconds

**Success factors:**

1. **Tight loop**: Running attack in a loop hits the race window within
1-3 attempts
2. **CPU scheduling**: Modern OS thread schedulers frequently
context-switch during I/O operations
3. **No synchronization**: No atomic file creation prevents the race
4. **Symlink speed**: Creating symlinks is extremely fast (metadata-only
operation)

### Real-World Attack Scenarios

**Scenario 1: virtualenv Exploitation**

```python

# Victim runs: python -m venv /tmp/myenv
# Attacker racing to create:
os.symlink("/home/victim/.bashrc", "/tmp/myenv/pyvenv.cfg")

# Result: /home/victim/.bashrc overwritten with:

# home = /usr/bin/python3
# include-system-site-packages = false

# version = 3.11.2
# ← Original .bashrc contents LOST + virtualenv metadata LEAKED to attacker
```

**Scenario 2: PyTorch Cache Poisoning**

```python

# Victim runs: import torch
# PyTorch checks CPU capabilities, uses filelock on cache

# Attacker racing to create:
os.symlink("/home/victim/.torch/compiled_model.pt", "/home/victim/.cache/torch/cpu_isa_check.lock")

# Result: Trained ML model checkpoint truncated to 0 bytes

# Impact: Weeks of training lost, ML pipeline DoS
```

### Why Standard Defenses Don't Help

**File permissions don't prevent this:**

- Attacker doesn't need write access to victim_file
- os.open() with O_TRUNC follows symlinks using the *victim's*
permissions
- The victim process truncates its own file

**Directory permissions help but aren't always feasible:**

- Lock files often created in shared /tmp directory (mode 1777)
- Applications may not control lock file location
- Many apps use predictable paths in user-writable directories

**File locking doesn't prevent this:**

- The truncation happens *during* the open() call, before any lock is
acquired
- fcntl.flock() only prevents concurrent lock acquisition, not symlink
attacks

### Exploitation Proof-of-Concept Results

From empirical testing with the provided PoCs:

**Simple Direct Attack** (`filelock_simple_poc.py`):

- Success rate: 33% per attempt (1 in 3 tries)
- Average attempts to success: 2.1
- Target file reduced to 0 bytes in \<100ms

**virtualenv Attack** (`weaponized_virtualenv.py`):

- Success rate: ~90% on first attempt (deterministic timing)
- Information leaked: File paths, Python version, system configuration
- Data corruption: Complete loss of original file contents

**PyTorch Attack** (`weaponized_pytorch.py`):

- Success rate: 25-40% per attempt
- Impact: Application crashes, model loading failures
- Recovery: Requires cache rebuild or model retraining

**Discovered and reported by:** George Tsigourakos
(@&#8203;tsigouris007)

####
[CVE-2026-22701](https://redirect.github.com/tox-dev/filelock/security/advisories/GHSA-qmgc-5h2g-mvrw)

## Vulnerability Summary

**Title:** Time-of-Check-Time-of-Use (TOCTOU) Symlink Vulnerability in
SoftFileLock

**Affected Component:** `filelock` package - `SoftFileLock` class
**File:** `src/filelock/_soft.py` lines 17-27
**CWE:** CWE-362, CWE-367, CWE-59

---

## Description

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.

### Attack Scenario

```
1. Lock attempts to acquire on /tmp/app.lock
2. Permission validation passes
3. [RACE WINDOW] - Attacker creates: ln -s /tmp/important.txt /tmp/app.lock
4. os.open() tries to create lock file
5. Lock operates on attacker-controlled target file or fails
```

---

## Impact

_What kind of vulnerability is it? Who is impacted?_

This is a **Time-of-Check-Time-of-Use (TOCTOU) race condition
vulnerability** affecting any application using `SoftFileLock` for
inter-process synchronization.

**Affected Users:**
- Applications using `filelock.SoftFileLock` directly
- Applications using the fallback `FileLock` on systems without `fcntl`
support (e.g., GraalPy)

**Consequences:**
- **Silent lock acquisition failure** - applications may not detect that
exclusive resource access is not guaranteed
- **Denial of Service** - attacker can prevent lock file creation by
maintaining symlink
- **Resource serialization failures** - multiple processes may acquire
"locks" simultaneously
- **Unintended file operations** - lock could operate on
attacker-controlled files

**CVSS v4.0 Score:** 5.6 (Medium)
**Vector:** CVSS:4.0/AV:L/AT:L/PR:L/UI:N/VC:N/VI:L/VA:H/SC:N/SI:N/SA:N

**Attack Requirements:**
- Local filesystem access to the directory containing lock files
- Permission to create symlinks (standard for regular unprivileged users
on Unix/Linux)
- Ability to time the symlink creation during the narrow race window

---

## Patches

_Has the problem been patched? What versions should users upgrade to?_

Yes, the vulnerability has been patched by adding the `O_NOFOLLOW` flag
to prevent symlink following during lock file creation.

**Patched Version:** Next release (commit:
255ed068bc85d1ef406e50a135e1459170dd1bf0)

**Mitigation Details:**
- The `O_NOFOLLOW` flag is added conditionally and gracefully degrades
on platforms without support
- On platforms with `O_NOFOLLOW` support (most modern systems): symlink
attacks are completely prevented
- On platforms without `O_NOFOLLOW` (e.g., GraalPy): TOCTOU window
remains but is documented

**Users should:**
- Upgrade to the patched version when available
- For critical deployments, consider using `UnixFileLock` or
`WindowsFileLock` instead of the fallback `SoftFileLock`

---

## Workarounds

_Is there a way for users to fix or remediate the vulnerability without
upgrading?_

For users unable to update immediately:

1. **Avoid `SoftFileLock` in security-sensitive contexts** - use
`UnixFileLock` or `WindowsFileLock` when available (these were already
patched for CVE-2025-68146)

2. **Restrict filesystem permissions** - prevent untrusted users from
creating symlinks in lock file directories:
   ```bash
   chmod 700 /path/to/lock/directory
   ```

3. **Use process isolation** - isolate untrusted code from lock file
paths to prevent symlink creation

4. **Monitor lock operations** - implement application-level checks to
verify lock acquisitions are successful before proceeding with critical
operations

---

## References

_Are there any links users can visit to find out more?_

- **Similar Vulnerability:** CVE-2025-68146 (TOCTOU vulnerability in
UnixFileLock/WindowsFileLock)
- **CWE-362 (Concurrent Execution using Shared Resource):**
https://cwe.mitre.org/data/definitions/362.html
- **CWE-367 (Time-of-check Time-of-use Race Condition):**
https://cwe.mitre.org/data/definitions/367.html
- **CWE-59 (Improper Link Resolution Before File Access):**
https://cwe.mitre.org/data/definitions/59.html
- **O_NOFOLLOW documentation:**
https://man7.org/linux/man-pages/man2/open.2.html
- **GitHub Repository:** https://github.com/tox-dev/filelock

---

**Reported by:** George Tsigourakos (@&#8203;tsigouris007)

---

### Release Notes

<details>
<summary>tox-dev/py-filelock (filelock)</summary>

###
[`v3.20.3`](https://redirect.github.com/tox-dev/filelock/releases/tag/3.20.3)

[Compare
Source](https://redirect.github.com/tox-dev/py-filelock/compare/3.20.2...3.20.3)

<!-- Release notes generated using configuration in .github/release.yml
at main -->

#### What's Changed

- Fix TOCTOU symlink vulnerability in SoftFileLock by
[@&#8203;gaborbernat](https://redirect.github.com/gaborbernat) in
[tox-dev/filelock#465](https://redirect.github.com/tox-dev/filelock/pull/465)

**Full Changelog**:
<tox-dev/filelock@3.20.2...3.20.3>

###
[`v3.20.2`](https://redirect.github.com/tox-dev/filelock/releases/tag/3.20.2)

[Compare
Source](https://redirect.github.com/tox-dev/py-filelock/compare/3.20.1...3.20.2)

<!-- Release notes generated using configuration in .github/release.yml
at main -->

##### What's Changed

- Support Unix systems without O\_NOFOLLOW by
[@&#8203;mwilliamson](https://redirect.github.com/mwilliamson) in
[tox-dev/filelock#463](https://redirect.github.com/tox-dev/filelock/pull/463)
- \[pre-commit.ci] pre-commit autoupdate by
[@&#8203;pre-commit-ci](https://redirect.github.com/pre-commit-ci)\[bot]
in
[tox-dev/filelock#464](https://redirect.github.com/tox-dev/filelock/pull/464)

##### New Contributors

- [@&#8203;mwilliamson](https://redirect.github.com/mwilliamson) made
their first contribution in
[tox-dev/filelock#463](https://redirect.github.com/tox-dev/filelock/pull/463)

**Full Changelog**:
<tox-dev/filelock@3.20.1...3.20.2>

###
[`v3.20.1`](https://redirect.github.com/tox-dev/filelock/releases/tag/3.20.1)

[Compare
Source](https://redirect.github.com/tox-dev/py-filelock/compare/3.20.0...3.20.1)

<!-- Release notes generated using configuration in .github/release.yml
at main -->

#### What's Changed

- CVE-2025-68146: Fix TOCTOU symlink vulnerability in lock file creation
by [@&#8203;gaborbernat](https://redirect.github.com/gaborbernat) in
[tox-dev/filelock#461](https://redirect.github.com/tox-dev/filelock/pull/461)

**Full Changelog**:
<tox-dev/filelock@3.20.0...3.20.1>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "" (UTC), Automerge - At any time (no
schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/vortex-data/vortex).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi45NS4yIiwidXBkYXRlZEluVmVyIjoiNDIuOTUuMiIsInRhcmdldEJyYW5jaCI6ImRldmVsb3AiLCJsYWJlbHMiOlsiY2hhbmdlbG9nL2Nob3JlIl19-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
danking pushed a commit to vortex-data/vortex that referenced this pull request Feb 6, 2026
This PR contains the following updates:

| Package | Change |
[Age](https://docs.renovatebot.com/merge-confidence/) |
[Confidence](https://docs.renovatebot.com/merge-confidence/) |
|---|---|---|---|
| [filelock](https://redirect.github.com/tox-dev/py-filelock) | `3.20.0`
→ `3.20.3` |
![age](https://developer.mend.io/api/mc/badges/age/pypi/filelock/3.20.3?slim=true)
|
![confidence](https://developer.mend.io/api/mc/badges/confidence/pypi/filelock/3.20.0/3.20.3?slim=true)
|

### GitHub Vulnerability Alerts

####
[CVE-2025-68146](https://redirect.github.com/tox-dev/filelock/security/advisories/GHSA-w853-jp5j-5j7f)

### Impact

A Time-of-Check-Time-of-Use (TOCTOU) race condition allows local
attackers to corrupt or truncate arbitrary user files through symlink
attacks. The vulnerability exists in both Unix and Windows lock file
creation where filelock checks if a file exists before opening it with
O_TRUNC. An attacker can create a symlink pointing to a victim file in
the time gap between the check and open, causing os.open() to follow the
symlink and truncate the target file.

**Who is impacted:**

All users of filelock on Unix, Linux, macOS, and Windows systems. The
vulnerability cascades to dependent libraries:

- **virtualenv users**: Configuration files can be overwritten with
virtualenv metadata, leaking sensitive paths
- **PyTorch users**: CPU ISA cache or model checkpoints can be
corrupted, causing crashes or ML pipeline failures
- **poetry/tox users**: through using virtualenv or filelock on their
own.

Attack requires local filesystem access and ability to create symlinks
(standard user permissions on Unix; Developer Mode on Windows 10+).
Exploitation succeeds within 1-3 attempts when lock file paths are
predictable.

### Patches

Fixed in version **3.20.1**.

**Unix/Linux/macOS fix:** Added O_NOFOLLOW flag to os.open() in
UnixFileLock.\_acquire() to prevent symlink following.

**Windows fix:** Added GetFileAttributesW API check to detect reparse
points (symlinks/junctions) before opening files in
WindowsFileLock.\_acquire().

**Users should upgrade to filelock 3.20.1 or later immediately.**

### Workarounds

If immediate upgrade is not possible:

1. Use SoftFileLock instead of UnixFileLock/WindowsFileLock (note:
different locking semantics, may not be suitable for all use cases)
2. Ensure lock file directories have restrictive permissions (chmod
0700) to prevent untrusted users from creating symlinks
3. Monitor lock file directories for suspicious symlinks before running
trusted applications

**Warning:** These workarounds provide only partial mitigation. The race
condition remains exploitable. Upgrading to version 3.20.1 is strongly
recommended.

______________________________________________________________________

## Technical Details: How the Exploit Works

### The Vulnerable Code Pattern

**Unix/Linux/macOS** (`src/filelock/_unix.py:39-44`):

```python
def _acquire(self) -> None:
    ensure_directory_exists(self.lock_file)
    open_flags = os.O_RDWR | os.O_TRUNC  # (1) Prepare to truncate
    if not Path(self.lock_file).exists():  # (2) CHECK: Does file exist?
        open_flags |= os.O_CREAT
    fd = os.open(self.lock_file, open_flags, ...)  # (3) USE: Open and truncate
```

**Windows** (`src/filelock/_windows.py:19-28`):

```python
def _acquire(self) -> None:
    raise_on_not_writable_file(self.lock_file)  # (1) Check writability
    ensure_directory_exists(self.lock_file)
    flags = os.O_RDWR | os.O_CREAT | os.O_TRUNC  # (2) Prepare to truncate
    fd = os.open(self.lock_file, flags, ...)  # (3) Open and truncate
```

### The Race Window

The vulnerability exists in the gap between operations:

**Unix variant:**

```
Time    Victim Thread                          Attacker Thread
----    -------------                          ---------------
T0      Check: lock_file exists? → False
T1                                             ↓ RACE WINDOW
T2                                             Create symlink: lock → victim_file
T3      Open lock_file with O_TRUNC
        → Follows symlink
        → Opens victim_file
        → Truncates victim_file to 0 bytes! ☠️
```

**Windows variant:**

```
Time    Victim Thread                          Attacker Thread
----    -------------                          ---------------
T0      Check: lock_file writable?
T1                                             ↓ RACE WINDOW
T2                                             Create symlink: lock → victim_file
T3      Open lock_file with O_TRUNC
        → Follows symlink/junction
        → Opens victim_file
        → Truncates victim_file to 0 bytes! ☠️
```

### Step-by-Step Attack Flow

**1. Attacker Setup:**

```python

# Attacker identifies target application using filelock
lock_path = "/tmp/myapp.lock"  # Predictable lock path
victim_file = "/home/victim/.ssh/config"  # High-value target
```

**2. Attacker Creates Race Condition:**

```python
import os
import threading

def attacker_thread():
    # Remove any existing lock file
    try:
        os.unlink(lock_path)
    except FileNotFoundError:
        pass

    # Create symlink pointing to victim file
    os.symlink(victim_file, lock_path)
    print(f"[Attacker] Created: {lock_path} → {victim_file}")

# Launch attack
threading.Thread(target=attacker_thread).start()
```

**3. Victim Application Runs:**

```python
from filelock import UnixFileLock

# Normal application code
lock = UnixFileLock("/tmp/myapp.lock")
lock.acquire()  # ← VULNERABILITY TRIGGERED HERE

# At this point, /home/victim/.ssh/config is now 0 bytes!
```

**4. What Happens Inside os.open():**

On Unix systems, when `os.open()` is called:

```c
// Linux kernel behavior (simplified)
int open(const char *pathname, int flags) {
    struct file *f = path_lookup(pathname);  // Resolves symlinks by default!

    if (flags & O_TRUNC) {
        truncate_file(f);  // ← Truncates the TARGET of the symlink
    }

    return file_descriptor;
}
```

Without `O_NOFOLLOW` flag, the kernel follows the symlink and truncates
the target file.

### Why the Attack Succeeds Reliably

**Timing Characteristics:**

- **Check operation** (Path.exists()): ~100-500 nanoseconds
- **Symlink creation** (os.symlink()): ~1-10 microseconds
- **Race window**: ~1-5 microseconds (very small but exploitable)
- **Thread scheduling quantum**: ~1-10 milliseconds

**Success factors:**

1. **Tight loop**: Running attack in a loop hits the race window within
1-3 attempts
2. **CPU scheduling**: Modern OS thread schedulers frequently
context-switch during I/O operations
3. **No synchronization**: No atomic file creation prevents the race
4. **Symlink speed**: Creating symlinks is extremely fast (metadata-only
operation)

### Real-World Attack Scenarios

**Scenario 1: virtualenv Exploitation**

```python

# Victim runs: python -m venv /tmp/myenv
# Attacker racing to create:
os.symlink("/home/victim/.bashrc", "/tmp/myenv/pyvenv.cfg")

# Result: /home/victim/.bashrc overwritten with:

# home = /usr/bin/python3
# include-system-site-packages = false

# version = 3.11.2
# ← Original .bashrc contents LOST + virtualenv metadata LEAKED to attacker
```

**Scenario 2: PyTorch Cache Poisoning**

```python

# Victim runs: import torch
# PyTorch checks CPU capabilities, uses filelock on cache

# Attacker racing to create:
os.symlink("/home/victim/.torch/compiled_model.pt", "/home/victim/.cache/torch/cpu_isa_check.lock")

# Result: Trained ML model checkpoint truncated to 0 bytes

# Impact: Weeks of training lost, ML pipeline DoS
```

### Why Standard Defenses Don't Help

**File permissions don't prevent this:**

- Attacker doesn't need write access to victim_file
- os.open() with O_TRUNC follows symlinks using the *victim's*
permissions
- The victim process truncates its own file

**Directory permissions help but aren't always feasible:**

- Lock files often created in shared /tmp directory (mode 1777)
- Applications may not control lock file location
- Many apps use predictable paths in user-writable directories

**File locking doesn't prevent this:**

- The truncation happens *during* the open() call, before any lock is
acquired
- fcntl.flock() only prevents concurrent lock acquisition, not symlink
attacks

### Exploitation Proof-of-Concept Results

From empirical testing with the provided PoCs:

**Simple Direct Attack** (`filelock_simple_poc.py`):

- Success rate: 33% per attempt (1 in 3 tries)
- Average attempts to success: 2.1
- Target file reduced to 0 bytes in \<100ms

**virtualenv Attack** (`weaponized_virtualenv.py`):

- Success rate: ~90% on first attempt (deterministic timing)
- Information leaked: File paths, Python version, system configuration
- Data corruption: Complete loss of original file contents

**PyTorch Attack** (`weaponized_pytorch.py`):

- Success rate: 25-40% per attempt
- Impact: Application crashes, model loading failures
- Recovery: Requires cache rebuild or model retraining

**Discovered and reported by:** George Tsigourakos
(@&#8203;tsigouris007)

####
[CVE-2026-22701](https://redirect.github.com/tox-dev/filelock/security/advisories/GHSA-qmgc-5h2g-mvrw)

## Vulnerability Summary

**Title:** Time-of-Check-Time-of-Use (TOCTOU) Symlink Vulnerability in
SoftFileLock

**Affected Component:** `filelock` package - `SoftFileLock` class
**File:** `src/filelock/_soft.py` lines 17-27
**CWE:** CWE-362, CWE-367, CWE-59

---

## Description

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.

### Attack Scenario

```
1. Lock attempts to acquire on /tmp/app.lock
2. Permission validation passes
3. [RACE WINDOW] - Attacker creates: ln -s /tmp/important.txt /tmp/app.lock
4. os.open() tries to create lock file
5. Lock operates on attacker-controlled target file or fails
```

---

## Impact

_What kind of vulnerability is it? Who is impacted?_

This is a **Time-of-Check-Time-of-Use (TOCTOU) race condition
vulnerability** affecting any application using `SoftFileLock` for
inter-process synchronization.

**Affected Users:**
- Applications using `filelock.SoftFileLock` directly
- Applications using the fallback `FileLock` on systems without `fcntl`
support (e.g., GraalPy)

**Consequences:**
- **Silent lock acquisition failure** - applications may not detect that
exclusive resource access is not guaranteed
- **Denial of Service** - attacker can prevent lock file creation by
maintaining symlink
- **Resource serialization failures** - multiple processes may acquire
"locks" simultaneously
- **Unintended file operations** - lock could operate on
attacker-controlled files

**CVSS v4.0 Score:** 5.6 (Medium)
**Vector:** CVSS:4.0/AV:L/AT:L/PR:L/UI:N/VC:N/VI:L/VA:H/SC:N/SI:N/SA:N

**Attack Requirements:**
- Local filesystem access to the directory containing lock files
- Permission to create symlinks (standard for regular unprivileged users
on Unix/Linux)
- Ability to time the symlink creation during the narrow race window

---

## Patches

_Has the problem been patched? What versions should users upgrade to?_

Yes, the vulnerability has been patched by adding the `O_NOFOLLOW` flag
to prevent symlink following during lock file creation.

**Patched Version:** Next release (commit:
255ed068bc85d1ef406e50a135e1459170dd1bf0)

**Mitigation Details:**
- The `O_NOFOLLOW` flag is added conditionally and gracefully degrades
on platforms without support
- On platforms with `O_NOFOLLOW` support (most modern systems): symlink
attacks are completely prevented
- On platforms without `O_NOFOLLOW` (e.g., GraalPy): TOCTOU window
remains but is documented

**Users should:**
- Upgrade to the patched version when available
- For critical deployments, consider using `UnixFileLock` or
`WindowsFileLock` instead of the fallback `SoftFileLock`

---

## Workarounds

_Is there a way for users to fix or remediate the vulnerability without
upgrading?_

For users unable to update immediately:

1. **Avoid `SoftFileLock` in security-sensitive contexts** - use
`UnixFileLock` or `WindowsFileLock` when available (these were already
patched for CVE-2025-68146)

2. **Restrict filesystem permissions** - prevent untrusted users from
creating symlinks in lock file directories:
   ```bash
   chmod 700 /path/to/lock/directory
   ```

3. **Use process isolation** - isolate untrusted code from lock file
paths to prevent symlink creation

4. **Monitor lock operations** - implement application-level checks to
verify lock acquisitions are successful before proceeding with critical
operations

---

## References

_Are there any links users can visit to find out more?_

- **Similar Vulnerability:** CVE-2025-68146 (TOCTOU vulnerability in
UnixFileLock/WindowsFileLock)
- **CWE-362 (Concurrent Execution using Shared Resource):**
https://cwe.mitre.org/data/definitions/362.html
- **CWE-367 (Time-of-check Time-of-use Race Condition):**
https://cwe.mitre.org/data/definitions/367.html
- **CWE-59 (Improper Link Resolution Before File Access):**
https://cwe.mitre.org/data/definitions/59.html
- **O_NOFOLLOW documentation:**
https://man7.org/linux/man-pages/man2/open.2.html
- **GitHub Repository:** https://github.com/tox-dev/filelock

---

**Reported by:** George Tsigourakos (@&#8203;tsigouris007)

---

### Release Notes

<details>
<summary>tox-dev/py-filelock (filelock)</summary>

###
[`v3.20.3`](https://redirect.github.com/tox-dev/filelock/releases/tag/3.20.3)

[Compare
Source](https://redirect.github.com/tox-dev/py-filelock/compare/3.20.2...3.20.3)

<!-- Release notes generated using configuration in .github/release.yml
at main -->

#### What's Changed

- Fix TOCTOU symlink vulnerability in SoftFileLock by
[@&#8203;gaborbernat](https://redirect.github.com/gaborbernat) in
[tox-dev/filelock#465](https://redirect.github.com/tox-dev/filelock/pull/465)

**Full Changelog**:
<tox-dev/filelock@3.20.2...3.20.3>

###
[`v3.20.2`](https://redirect.github.com/tox-dev/filelock/releases/tag/3.20.2)

[Compare
Source](https://redirect.github.com/tox-dev/py-filelock/compare/3.20.1...3.20.2)

<!-- Release notes generated using configuration in .github/release.yml
at main -->

##### What's Changed

- Support Unix systems without O\_NOFOLLOW by
[@&#8203;mwilliamson](https://redirect.github.com/mwilliamson) in
[tox-dev/filelock#463](https://redirect.github.com/tox-dev/filelock/pull/463)
- \[pre-commit.ci] pre-commit autoupdate by
[@&#8203;pre-commit-ci](https://redirect.github.com/pre-commit-ci)\[bot]
in
[tox-dev/filelock#464](https://redirect.github.com/tox-dev/filelock/pull/464)

##### New Contributors

- [@&#8203;mwilliamson](https://redirect.github.com/mwilliamson) made
their first contribution in
[tox-dev/filelock#463](https://redirect.github.com/tox-dev/filelock/pull/463)

**Full Changelog**:
<tox-dev/filelock@3.20.1...3.20.2>

###
[`v3.20.1`](https://redirect.github.com/tox-dev/filelock/releases/tag/3.20.1)

[Compare
Source](https://redirect.github.com/tox-dev/py-filelock/compare/3.20.0...3.20.1)

<!-- Release notes generated using configuration in .github/release.yml
at main -->

#### What's Changed

- CVE-2025-68146: Fix TOCTOU symlink vulnerability in lock file creation
by [@&#8203;gaborbernat](https://redirect.github.com/gaborbernat) in
[tox-dev/filelock#461](https://redirect.github.com/tox-dev/filelock/pull/461)

**Full Changelog**:
<tox-dev/filelock@3.20.0...3.20.1>

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "" (UTC), Automerge - At any time (no
schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR was generated by [Mend Renovate](https://mend.io/renovate/).
View the [repository job
log](https://developer.mend.io/github/vortex-data/vortex).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi45NS4yIiwidXBkYXRlZEluVmVyIjoiNDIuOTUuMiIsInRhcmdldEJyYW5jaCI6ImRldmVsb3AiLCJsYWJlbHMiOlsiY2hhbmdlbG9nL2Nob3JlIl19-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant