Skip to content

🐛 fix(cache): keep shim results out of shared cache - #232

Merged
gaborbernat merged 4 commits into
tox-dev:mainfrom
gaborbernat:fix/hk25s1m7-shim-cache
Nov 3, 2026
Merged

gaborbernat merged 4 commits into
tox-dev:mainfrom
gaborbernat:fix/hk25s1m7-shim-cache

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

An untrusted checkout can make a launcher select an unsupported Python. The process cache and disk cache keyed that verdict by the launcher's unchanged path, so a later unrelated checkout could inherit the failure. This PR caches a query only when the probed path is the interpreter that answered. This addresses draft advisory ANT-2026-HK25S1M7.

Launcher results crossed directories

pyenv selects a version from the current directory's .python-version. Before this change, _get_from_cache retained every result under the launcher path, while _get_via_file_cache wrote successful and unsupported results to disk under the same path. The new identity check compares the queried path with the interpreter that answered before either cache accepts the result.

flowchart LR
    Q[Query candidate] --> Old[Before: cache by candidate path]
    Q --> Same{Now: candidate is the interpreter?}
    Same -- yes --> Keep[Cache the result]
    Same -- no --> Retry[Return without caching]
    classDef old fill:#ffd6d6,stroke:#c1121f,color:#5c0000;
    classDef fixed fill:#d8f3dc,stroke:#2d6a4f,color:#1b4332;
    class Old old;
    class Same,Keep,Retry fixed;
Loading

Unsupported-version verdict identity

The old version gate reported only the version. The updated gate also reports its sys.executable, and _query_failure passes that identity to the cache decision. The user-facing error still names the queried candidate and its version.

Behavior changes

Direct interpreter paths and symlinks to them remain cacheable. Discovery queries launchers and generic failures again on later calls, including calls from a different current directory. The collector script change also invalidates older disk entries through the existing script hash.

Closes #194.

Reported by Anthropic's OSS Scanner: ANT-2026-HK25S1M7.

A checkout can change the interpreter selected by a launcher without changing
the launcher's path or mtime. Its cached result then affects later checkouts.

Cache a query only when the probed path is the interpreter that answered. This
also keeps unsupported-version verdicts tied to the interpreter that produced
them. Fixes tox-dev#194.
@gaborbernat gaborbernat added bug Something isn't working security Security fixes and advisories labels Nov 3, 2026
@gaborbernat
gaborbernat merged commit c943204 into tox-dev:main Nov 3, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working security Security fixes and advisories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A cached shim verdict applies in unrelated directories

1 participant