7.8high
virtualenv activation scripts run code from a path that contains a placeholder name
- Severity
- 7.8high CVSS:3.1 by GitHub_M
- Exploit likelihood
- 0.29% (higher than 23% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- GitHub_M
- Also known as
- GHSA-8rjx-v5ww-45ppBIT-VIRTUALENV-2026-113776PYSEC-2026-4387
Description
virtualenv is a tool for creating isolated virtual python environments. From 20.26.6 until 21.14.2, ViaTemplateActivator.instantiate_template() replaces placeholders one key at a time across the complete activation template, so trigger names such as __VIRTUAL_NAME__, __VIRTUAL_ENV__, or __VIRTUAL_PROMPT__ inside an already substituted and quoted environment path or prompt can be replaced during a later pass. The later value's quoting can close the earlier literal and execute the remaining path when a user activates the environment through bash, fish, xonsh, or activate_this.py. The distinct csh prompt-display token __VIRTUAL_PROMPT_DISPLAY_TCSH__ can instead break the generated script without establishing command execution. The attacker must influence the destination path or --prompt, and a value without a relevant placeholder name does not trigger this mechanism. This issue is fixed in version 21.14.2.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| pypa virtualenv | >= 20.26.6, < 21.14.2 | CVE List |
| virtualenv (PyPI) | from 20.26.6 before 21.14.2 | GitHub Advisory Database, PyPA Advisory Database |
| virtualenv virtualenv | from 20.26.6 before 21.14.2 | NVD |
| virtualenv (Bitnami) | from 20.26.6 before 21.14.2 | Bitnami Vulnerability Database |
All scores
| GitHub_M | 7.8high CVSS:3.1 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H |
| GitHub | 7.8high CVSS:3.1 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H |
| PyPA Advisory Database | 7.8high CVSS:3.1 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H |
| Bitnami Vulnerability Database | high rating |
Classification
What each source says
CVE List
virtualenv is a tool for creating isolated virtual python environments. From 20.26.6 until 21.14.2, ViaTemplateActivator.instantiate_template() replaces placeholders one key at a time across the complete activation template, so trigger names such as __VIRTUAL_NAME__, __VIRTUAL_ENV__, or __VIRTUAL_PROMPT__ inside an already substituted and quoted environment path or prompt can be replaced during a later pass. The later value's quoting can close the earlier literal and execute the remaining path when a user activates the environment through bash, fish, xonsh, or activate_this.py. The distinct csh prompt-display token __VIRTUAL_PROMPT_DISPLAY_TCSH__ can instead break the generated script without establishing command execution. The attacker must influence the destination path or --prompt, and a value without a relevant placeholder name does not trigger this mechanism. This issue is fixed in version 21.14.2.
GitHub Advisory Database
Impact
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.
__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:
VIRTUAL_ENV='/tmp/t/A'x'"'"'$(touch PWNED)'"'"'y'B/x'"'"'$(touch PWNED)'"'"'y'
Sourcing 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 '''.
No change to quote() can stop this, because the rewrite happens after quote() ran; it defeats shlex.quote and repr() alike.
An 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.
The 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.
Patches
Fixed 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
Workarounds
Do 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.
Credits
Kevin Stubbings (@Kwstubbs) of GitHub Security Lab reported this issue.
References
| https://github.com/pypa/virtualenv/security/advisories/GHSA-8rjx-v5ww-45pp | advisory, fix, mitigation, patch, vendor-advisory, web | |
| https://github.com/pypa/virtualenv/commit/602b26623a724827ff171bf11fef4ad186d01f74 | fix, patch, web | |
| https://github.com/pypa/virtualenv/releases/tag/21.14.2 | advisory, article, release-notes, web | |
| https://nvd.nist.gov/vuln/detail/CVE-2026-113776 | advisory, web | |
| https://github.com/pypa/virtualenv | package | |
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2026-113776 changed 2026-10-28 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-8rjx-v5ww-45pp changed 2026-11-18 | CC-BY-4.0 |
| NVD | CVE-2026-113776 changed 2026-11-17 | Public domain |
| PyPA Advisory Database | PYSEC-2026-4387 changed 2026-11-18 | CC-BY-4.0 |
| Bitnami Vulnerability Database | BIT-VIRTUALENV-2026-113776 changed 2026-11-27 | Apache-2.0 |