Skip to content

🐛 fix(discovery): probe case in a private temp dir - #286

Merged
gaborbernat merged 2 commits into
tox-dev:mainfrom
gaborbernat:fix/case-probe-private-dir
Nov 30, 2026
Merged

gaborbernat merged 2 commits into
tox-dev:mainfrom
gaborbernat:fix/case-probe-private-dir

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

On a shared machine, another user could make interpreter discovery fail for someone else, or skip an installed interpreter, by creating an entry in the shared temporary directory. Tools built on python-discovery, such as virtualenv and tox, then stopped with a PermissionError. 🔒 Nothing another user creates there affects discovery any more. This addresses draft advisory ANT-2026-B0M9PD96.

In a shared temporary directory, with tmp.arff6yce5r standing in for another account's folder (Python 3.9 to 3.13):

$ mkdir tmp.aRfF6YCe5r
$ mkdir -m 000 tmp.arff6yce5r
$ TMPDIR=$PWD/tmp.aRfF6YCe5r python -c 'from python_discovery import get_interpreter; print(get_interpreter("python3").executable)' 2>&1 | tail -1

Before:

PermissionError: [Errno 13] Permission denied: '/home/me/demo/tmp.arff6yce5r/tmpbg8mk17v'

After:

/home/me/.venv/bin/python

Discovery checks once per process whether the file system treats Foo and foo as one name. The check now runs in a folder TemporaryDirectory creates for the current user alone, so only the file system decides the answer.

Which interpreters are found does not change on a normal machine. A machine with no writable temporary directory still fails as before.

Reported by oss-scanner: ANT-2026-B0M9PD96.

The case probe lower-cased the whole absolute path of its temporary file, so
the lookup left the probe's directory and landed on a name in the shared temp
directory. Another local user could create that name and make discovery raise
PermissionError, or cache a false case-insensitive answer.

The probe now runs inside a TemporaryDirectory and lower-cases only the file
name, so the lookup stays in a directory only the caller can write.

Reported by oss-scanner as ANT-2026-B0M9PD96.
@gaborbernat gaborbernat added bug Something isn't working security Security fixes and advisories labels Nov 29, 2026
The test only checked which path Path.exists received, so it still passed
with the result inverted. It now plants the lower-cased twin of the probe
file in the shared temp directory and asserts the probe matches the host
file system.
@gaborbernat
gaborbernat merged commit d8627d3 into tox-dev:main Nov 30, 2026
24 checks passed
@gaborbernat
gaborbernat deleted the fix/case-probe-private-dir branch November 30, 2026 15:53
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.

1 participant