Repository navigation
Description
The app-data seeder checks paths from an existing distribution's RECORD or top_level.txt before deciding whether they are inside the environment. An absolute entry can therefore cause a filesystem lookup outside the environment during reseeding, even though cleanup will not remove it. The Windows network effect of a UNC entry has not been tested.
Affected code
- At 8e09166d,
_uninstall_dist, the lookup at line 104 precedes the containment check at line 108. - At ebe06113,
_uninstall_distand_record_paths, the lookup still precedes the check. For a.pyentry,_record_pathsalso searches its__pycache__directory before reaching that loop.
Mechanism
The seeder joins each metadata name to site-packages. pathlib discards the base when the right-hand path is absolute. The resulting path enters exists() and is_symlink() before the resolved-path containment check; a missing path skips that check and its warning. Current _bytecode_of calls glob() on the parent of a .py entry. RECORD normally lists paths relative to the installed library directory, so the absolute entry requires malformed metadata.
Reproduction
This script records calls to Path.exists and Path.glob using only temporary local paths. It invokes the same cleanup function on a temporary environment.
from pathlib import Path, PureWindowsPath
from tempfile import TemporaryDirectory
from unittest.mock import patch
from virtualenv.seed.embed.via_app_data.pip_install.base import PipInstall
with TemporaryDirectory() as tmp:
root = Path(tmp)
dist = root / "venv" / "lib" / "python3.15" / "site-packages" / "pip-1.0.dist-info"
dist.mkdir(parents=True)
outside = root / "outside-missing.py"
(dist / "RECORD").write_text(f"{outside},,\n", encoding="utf-8")
calls = []
original_exists, original_glob = Path.exists, Path.glob
def traced_exists(path):
if path == outside:
calls.append("exists outside")
return original_exists(path)
def traced_glob(path, pattern):
if path == outside.parent / "__pycache__":
calls.append("glob outside __pycache__")
return original_glob(path, pattern)
with patch.object(Path, "exists", traced_exists), patch.object(Path, "glob", traced_glob):
PipInstall._uninstall_dist(dist, root / "venv")
print(f"outside_calls={calls!r}")
print(f"outside_exists={outside.exists()}")
print(PureWindowsPath(r"C:\project\venv\Lib\site-packages") / "//host/share/x")Run with PYTHONPATH=src python3 repro.py from each checkout. The archived 8e09166 checkout needed its generated src/virtualenv/version.py supplied before import. Output:
8e09166d: outside_calls=['exists outside']
8e09166d: outside_exists=False
8e09166d: \\host\share\x
ebe06113: outside_calls=['glob outside __pycache__', 'exists outside']
ebe06113: outside_exists=False
ebe06113: \\host\share\x
Expected: cleanup should reject a name outside the environment before any filesystem query on that name or its derived bytecode directory. Paths such as ../../../bin/pip that remain inside the environment still need to work.
Impact
This requires reseeding an existing environment without --clear whose seed-package metadata has a malformed absolute path. The lookup is reproducible with that setup (moderate). Such metadata is unusual and already resides in a trusted environment directory (unlikely real-world exposure). A .pth file in the same site-packages directory can already run code when that environment starts, so this lookup has no demonstrated additional attacker capability. On Windows, PureWindowsPath joins //host/share/x to \\host\share\x; SMB traffic or credential use from an actual Windows run has not been observed.
The lookup remains after #3428, which added the post-lookup containment check. A fix needs to cover the earlier bytecode glob() on the current branch as well as the cleanup loop.
Credits
Reported by oss-scanner: ANT-2026-5PAH96SM.
Activity
🐛 fix(seed): contain metadata lookups
🐛 fix(seed): contain metadata lookups
🐛 fix(seed): contain metadata lookups
🐛 fix(seed): contain metadata lookups
🐛 fix(seed): contain metadata lookups
🐛 fix(seed): contain metadata lookups