Skip to content

🐛 fix(discovery): ignore stdlib landmark owned by another user - #288

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/stdlib-landmark-owner
Nov 30, 2026
Merged

gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/stdlib-landmark-owner

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Discovery keeps an interpreter symlink unresolved when a standard library sits next to it, so that aliases such as Debian's /usr/bin/python3 stay as they are (#86). It never checked who owned that library, so another local user could create one beside a link kept under a shared folder such as /tmp. Environments built from that link with venv then loaded the other user's standard library. 🐛 Only a library owned by root, the current user or the owner of the link's folder keeps a link unresolved now. Fixes #283.

On python:3.13-slim with two accounts, mallory and alice:

# as mallory, another local account
$ mkdir -p /tmp/lib/python3.13 && cp /usr/local/lib/python3.13/os.py /tmp/lib/python3.13/
# as alice
$ mkdir /tmp/tmp.X && ln -s /usr/local/bin/python3.13 /tmp/tmp.X/python3
$ python3 -c 'from python_discovery import get_interpreter; print(get_interpreter("/tmp/tmp.X/python3").system_executable)'

Before:

/tmp/tmp.X/python3

After:

/usr/local/bin/python3.13

The rule from #87 that keeps distribution aliases stays, with one added condition on who installed the library.

Distribution, pyenv, uv and Homebrew installs behave as before. A library owned by some other account now resolves to the real interpreter, as release 1.4.1 did (#85). Windows is unchanged. A link placed directly in a world-writable folder right below / stays exposed, as it is to python -m venv without python-discovery.

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

An interpreter symlink stayed unresolved whenever the directory beside it
held an existing lib/pythonX.Y/os.py, whoever owned that file. A venv built
from the link records the link's directory as home, and CPython then imports
the standard library from there. A file another user created in a shared
parent such as /tmp was enough to switch the resolution off.

The landmark now counts only when lib, lib/pythonX.Y and os.py are each owned
by root, the effective user or the owner of the link's directory. They are
checked with lstat, so a symlink owned by another user cannot pass on the
owner of its target. Platforms without geteuid keep the previous check.

Fixes tox-dev#283.
Reported by oss-scanner as ANT-2026-UFV4PHZZ.
@gaborbernat gaborbernat added the bug Something isn't working label Nov 29, 2026
@gaborbernat
gaborbernat merged commit d55fd92 into tox-dev:main Nov 30, 2026
25 checks passed
@gaborbernat
gaborbernat deleted the fix/stdlib-landmark-owner 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Symlink resolution stops at a standard library owned by another user

1 participant