{"id":"CVE-2026-113776","kind":"vulnerability","aliases":["CVE-2026-113776","GHSA-8rjx-v5ww-45pp"],"related":[],"title":"virtualenv activation scripts run code from a path that contains a placeholder name","description":"### Impact\n\n`ViaTemplateActivator.instantiate_template` replaces the placeholders in an activation template one key at a time, each across the whole text. When a value that it already substituted and quoted contains the name of a later placeholder, the later pass rewrites that name inside the quoted literal. The inserted value brings its own quotes, which close the outer literal, and the rest of the path runs as code when a user activates the environment.\n\n`__VIRTUAL_NAME__` holds the environment's directory name, so a destination such as `A__VIRTUAL_NAME__B/x'$(touch PWNED)'y` is enough. In the default `activate` for bash, the `VIRTUAL_ENV` line renders as:\n\n```sh\nVIRTUAL_ENV='/tmp/t/A'x'\"'\"'$(touch PWNED)'\"'\"'y'B/x'\"'\"'$(touch PWNED)'\"'\"'y'\n```\n\nSourcing that script runs `touch PWNED`. The same payload in a path without the placeholder name runs nothing. `activate.fish` runs the command the same way, and the reporter also showed Python code execution through `activate.xsh` and `bin/activate_this.py`. In `activate.csh`, a directory named after a prompt display placeholder, such as `__VIRTUAL_PROMPT_DISPLAY_TCSH__`, breaks the script with `Unmatched '''`.\n\nNo change to `quote()` can stop this, because the rewrite happens after `quote()` ran; it defeats `shlex.quote` and `repr()` alike.\n\nAn attacker needs to influence the destination path or `--prompt`: a CI job or wrapper tool that builds the path from a branch or project name, or a directory in a cloned repository or unpacked archive.\n\nThe bug affects versions 20.26.6 through 21.14.1. Version 20.26.6 first quoted template values (#2768) and introduced the per-key loop.\n\n### Patches\n\nFixed in 21.14.2. Activation scripts now keep a placeholder name in the environment's path or prompt as plain text, and activating the example above runs nothing. Fix: https://github.com/pypa/virtualenv/commit/602b26623a724827ff171bf11fef4ad186d01f74\n\n### Workarounds\n\nDo not create an environment whose path or `--prompt` contains a placeholder name such as `__VIRTUAL_NAME__`, `__VIRTUAL_ENV__` or `__VIRTUAL_PROMPT__`, and inspect the generated activation script before you source one you did not create.\n\n### Credits\n\nKevin Stubbings (@Kwstubbs) of GitHub Security Lab reported this issue.","summary":"virtualenv activation scripts can be made to execute attacker-chosen shell or Python code when a path or --prompt contains a placeholder name such as __VIRTUAL_NAME__. An attacker who controls the destination directory name, for example from a CI branch name or a cloned repo, gets code execution when a user activates the environment.","severity":"high","cvss":7.800000190734863,"epss":0.002469999948516488,"exploited":false,"exploited_at":null,"products":[{"name":"virtualenv","fixed":["21.14.2"],"affected":">= 20.26.6, <= 21.14.1","ecosystem":"pypi"}],"ecosystems":["pypi"],"tags":["ci","cwe-78","cwe-94","developer-machines","package","python","virtualenv"],"not_affected_if":["no-untrusted-directory-names","virtualenv-21.14.2-or-later","virtualenv-below-20.26.6"],"how_to_check":"Run pip show virtualenv to get the installed version; versions 20.26.6 through 21.14.1 are affected.\nList environment paths and --prompt values for placeholder names like __VIRTUAL_NAME__, __VIRTUAL_ENV__ or __VIRTUAL_PROMPT__.\nInspect the VIRTUAL_ENV line in bin/activate of any environment you did not create.","fix":"Upgrade virtualenv to 21.14.2 or later.\nUntil then, do not create environments whose path or --prompt contains a placeholder name, and inspect generated activation scripts before sourcing them.","status":"open","published_at":"2026-10-20T22:19:30+00:00","first_seen_at":"2026-10-23T19:11:32+00:00","triaged_at":"2026-10-23T19:52:54+00:00","updated_at":"2026-10-23T21:57:25+00:00","category":"package","confidence":0.85,"triage":{"at":"2026-10-23T19:52:54Z","model":"claude-haiku-5-5","output":{"fix":"Upgrade virtualenv to 21.14.2 or later.\nUntil then, do not create environments whose path or --prompt contains a placeholder name, and inspect generated activation scripts before sourcing them.","summary":"virtualenv activation scripts can be made to execute attacker-chosen shell or Python code when a path or --prompt contains a placeholder name such as __VIRTUAL_NAME__. An attacker who controls the destination directory name, for example from a CI branch name or a cloned repo, gets code execution when a user activates the environment.","category":"package","who_cares":["python","virtualenv","ci","developer-machines"],"confidence":0.85,"analyst_note":"","how_to_check":"Run pip show virtualenv to get the installed version; versions 20.26.6 through 21.14.1 are affected.\nList environment paths and --prompt values for placeholder names like __VIRTUAL_NAME__, __VIRTUAL_ENV__ or __VIRTUAL_PROMPT__.\nInspect the VIRTUAL_ENV line in bin/activate of any environment you did not create.","needs_analyst":false,"not_affected_if":["virtualenv-below-20.26.6","virtualenv-21.14.2-or-later","no-untrusted-directory-names"],"severity_if_unknown":"high"},"cost_usd":0.000514,"input_tokens":2872,"output_tokens":453,"severity_before":"high"},"analyst_status":null,"analyst_note":null,"search":"'-113776':16A,24A '-2026':15A,23A '-78':28B '-94':30B '/pypa/virtualenv/commit/602b26623a724827ff171bf11fef4ad186d01f74':378C '/tmp/t/a':203C '20.26.6':330C,334C '21.14.1':332C '21.14.2':350C '2768':339C '45pp':21A '8rjx':19A 'across':109C 'activ':2A,38B,90B,101C,163C,191C,351C,369C,406C 'activate.csh':250C 'activate.fish':230C 'activate.xsh':246C 'affect':328C 'alik':289C 'alreadi':118C 'also':240C 'archiv':325C 'attack':46B,66B,291C 'attacker-chosen':45B 'b/x':182C,208C 'bash':193C 'bin/activate_this.py':248C 'branch':78B,312C 'break':265C 'bring':142C 'bug':327C 'build':307C 'chang':271C 'chosen':47B 'ci':26B,77B,301C 'clone':82B,321C 'close':147C 'code':5A,51B,85B,159C,243C 'command':233C 'contain':10A,57B,122C,389C 'control':68B 'creat':382C,415C 'credit':416C 'cve':14A,22A 'cwe':27B,29B 'default':190C 'defeat':285C 'destin':70B,176C,296C 'develop':32B 'developer-machin':31B 'directori':71B,172C,252C,318C 'display':257C,263C 'enough':187C 'env':196C,202C,398C 'environ':92B,165C,170C,360C,384C 'exampl':74B,371C 'execut':44B,86B,244C 'first':335C 'fix':348C,375C 'generat':405C 'get':84B 'ghsa':18A 'ghsa-8rjx-v5ww-45pp':17A 'github':421C 'github.com':377C 'github.com/pypa/virtualenv/commit/602b26623a724827ff171bf11fef4ad186d01f74':376C 'happen':280C 'hold':168C 'impact':93C 'influenc':294C 'insert':140C 'insid':135C 'inspect':403C 'introduc':341C 'issu':426C 'job':302C 'keep':354C 'kevin':417C 'key':104C,345C 'kwstubb':419C 'lab':423C 'later':127C,130C 'line':197C 'liter':138C,150C 'loop':346C 'machin':33B 'made':42B 'name':13A,60B,64B,72B,79B,124C,134C,167C,173C,181C,227C,253C,315C,357C,392C,396C 'need':292C 'noth':229C,374C 'one':103C,411C 'outer':149C 'packag':34B 'pass':131C 'patch':347C 'path':8A,54B,156C,223C,297C,309C,362C,386C 'payload':220C 'per':344C 'per-key':343C 'placehold':12A,59B,98C,128C,226C,258C,356C,391C 'plain':366C 'project':314C 'prompt':56B,256C,262C,299C,364C,388C,401C 'pwned':184C,206C,210C,217C 'python':35B,50B,242C 'quot':121C,137C,145C,273C,282C,336C 'ran':283C 'render':198C 'replac':96C 'repo':83B 'report':239C,424C 'repositori':322C 'repr':288C 'rest':153C 'rewrit':132C,279C 'run':4A,157C,215C,228C,231C,373C 'script':3A,39B,214C,267C,352C,407C 'secur':422C 'sh':200C 'shell':48B 'shlex.quote':286C 'show':241C 'sourc':212C,410C 'stop':275C 'stub':418C 'substitut':119C 'tcsh':264C 'templat':95C,102C,337C 'text':112C,367C 'time':107C 'tool':305C 'touch':183C,205C,209C,216C 'unmatch':269C 'unpack':324C 'user':89B,162C 'v5ww':20A 'valu':115C,141C,338C 'version':329C,333C 'viatemplateactivator.instantiate':94C 'virtual':63B,166C,180C,195C,201C,261C,395C,397C,400C 'virtualenv':1A,25A,36B,37B 'way':236C 'whole':111C 'whose':385C 'without':224C 'workaround':379C 'wrapper':304C 'x':204C 'y':185C,207C,211C","nicknames":[],"mitigations":[],"who_affected":null,"tier":"B","verified":{},"analyst_revisit_at":null,"first_public_at":"2026-10-20T22:19:30+00:00","kev":null,"cvss_vector":"CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H","cvss_by":"GitHub","poc_count":0,"sources":[{"source":"ghsa","external_id":"GHSA-8rjx-v5ww-45pp","url":"https://github.com/advisories/GHSA-8rjx-v5ww-45pp","severity":"high","published_at":"2026-10-21T16:39:38+00:00","modified_at":"2026-10-21T16:39:39+00:00","first_seen_at":"2026-10-23T19:11:32+00:00","fetched_at":"2026-10-23T19:11:32+00:00","note":null},{"source":"nvd","external_id":"CVE-2026-113776","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-113776","severity":null,"published_at":"2026-10-20T22:19:30+00:00","modified_at":"2026-10-22T16:47:38+00:00","first_seen_at":"2026-10-23T21:57:25+00:00","fetched_at":"2026-10-23T22:29:00+00:00","note":null}],"documents":[],"notice":"Free to read at a human pace. An API with keys and an MCP server are in preparation; early access: hello@infrastack.ai"}