Repository navigation
🐛 fix(cache): reject untrusted lock directory - #291
Merged
gaborbernat merged 2 commits intoNov 30, 2026
Merged
Conversation
DiskContentStore.locked() creates locks-v2 with mkdir(exist_ok=True), which accepts a symlink or a directory owned by another user. A lock taken there could stall lookups, and the lock file could be created outside the cache. Check the lock folder with the same rule _trusted_folder applies to the cache directories: a real directory owned by the current user or root and not writable by others. In a group-shared cache any real directory is accepted, as before, but a symlink is refused. A rejected folder logs a warning and the lookup continues without the cache. Fixes tox-dev#285. Reported by oss-scanner as ANT-2026-RMWOKI09.
DiskCache refuses a group-writable cache directory, so the lock rule in the explanation page only needs the private case.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
python-discovery's disk cache keeps its locks in a
locks-v2folder, and discovery used whatever already sat there, even a symlink or another account's folder left from when the cache was group-writable. That account could stall the owner's lookups or have lock files created outside the cache. 🐛 The lock folder now passes the same ownership and permission checks as the rest of the cache; when it fails them, discovery warns and answers without the cache. Fixes #285.Before:
After:
Path.mkdirwithexist_ok=Trueaccepts anything already in place, and filelock follows links in parent folders (open(2)), so the check has to happen in discovery. It reuses the rule that already guards the cache folders.Caches created by released versions pass the check. A rejected folder keeps the cache off until someone moves it aside; renaming works where deleting may not. virtualenv, tox and hatch use their own caches and are not affected. Windows is unchanged.
Reported by oss-scanner: ANT-2026-RMWOKI09.