7.8high
virtualenv bash activate runs commands from an environment name with a backslash before $
- Severity
- 7.8high CVSS:3.1 by GitHub_M
- Exploit likelihood
- 0.28% (higher than 21% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- GitHub_M
- Also known as
- GHSA-vxj4-q4g9-crj7BIT-VIRTUALENV-2026-113725PYSEC-2026-4384
Description
virtualenv is a tool for creating isolated virtual python environments. Prior to 21.14.7, the bash activate script escapes the environment name for only one of the two passes bash makes over PS1, so a backslash in the name undoes the escaping and a name containing \$(...) runs as commands in the user's shell each time bash draws the prompt. This issue is fixed in version 21.14.7.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| pypa virtualenv | < 21.14.7 | CVE List |
| virtualenv (PyPI) | before 21.14.7 | GitHub Advisory Database, PyPA Advisory Database |
| virtualenv virtualenv | before 21.14.7 | NVD |
| virtualenv (Bitnami) | before 21.14.7 | 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. Prior to 21.14.7, the bash activate script escapes the environment name for only one of the two passes bash makes over PS1, so a backslash in the name undoes the escaping and a name containing \$(...) runs as commands in the user's shell each time bash draws the prompt. This issue is fixed in version 21.14.7.
GitHub Advisory Database
Summary
The bash activate script escapes the environment name for only one of the two passes bash makes over PS1, so a
backslash in the name undoes the escaping and a name containing \$(...) runs as commands in the user's shell each
time bash draws the prompt.
Affected area
src/virtualenv/activation/bash/activate.sh, the block that prepends the environment name to PS1.
Attacker-controlled input
The environment name: the environment directory's name, or the --prompt or VIRTUALENV_PROMPT value. An attacker
needs to influence it, for example through a CI job or wrapper tool that passes a branch, project or job name through,
or a directory in a cloned repository or unpacked archive. --prompt . takes the current directory's name.
Details
bash handles PS1 in two passes each time it draws the prompt: it first decodes backslash prompt escapes, turning \\
into \ and \$ into $ (or # for root), and then runs parameter expansion, command substitution and arithmetic
expansion on the result. Since 21.13.0 the script escapes backslashes, dollar signs and backticks in the name, but only
for the second pass, so the decode pass strips the escaping that a backslash in the name precedes. Releases before
21.13.0 do not escape the name at all. A bash running as root decodes \$ to #, so the payload shows the wrong text
there but runs nothing. zsh does no decode pass and is not affected.
Proof of concept
$ virtualenv --prompt 'a\$(touch PWNED)' env
$ bash --norc --noprofile -c 'source env/bin/activate; printf "%s" "${PS1@P}"'
$ ls PWNED
PWNED
Impact
Arbitrary command execution in the shell of a user who sources the activate script of an environment whose name an
attacker influenced, with that user's privileges, once per prompt draw.
Versions tested
21.14.6 with bash 5.2.15 on Debian bookworm, as an unprivileged user and as root.
Known mitigation
Set VIRTUAL_ENV_DISABLE_PROMPT=1 before you source activate, which leaves PS1 alone, or run shopt -u promptvars
if your prompt does not need expansion. Check the name of an environment you did not create before you source its
activate.
Latest release
- The problem reproduces on the latest virtualenv release.
21.14.6
Patches
Fixed in 21.14.7. Under bash, activate now escapes backslashes, dollar signs and backticks for both passes, so the
example above runs nothing and the prompt shows the name as given. zsh keeps the single escaping it needs.
Fix: https://github.com/pypa/virtualenv/commit/c3104e02474b652832a9bbaae79f6e1696296932
Credits
Found while running the virtualenv test suite as root inside the Anthropic OSS Scanner build image.
References
| https://github.com/pypa/virtualenv/security/advisories/GHSA-vxj4-q4g9-crj7 | advisory, exploit, fix, mitigation, patch, vendor-advisory, web | |
| https://github.com/pypa/virtualenv/commit/c3104e02474b652832a9bbaae79f6e1696296932 | fix, patch, web | |
| https://github.com/pypa/virtualenv/releases/tag/21.14.7 | advisory, article, release-notes, web | |
| https://nvd.nist.gov/vuln/detail/CVE-2026-113725 | advisory, web | |
| https://github.com/pypa/virtualenv | package | |
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2026-113725 changed 2026-10-21 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-vxj4-q4g9-crj7 changed 2026-11-18 | CC-BY-4.0 |
| NVD | CVE-2026-113725 changed 2026-11-17 | Public domain |
| PyPA Advisory Database | PYSEC-2026-4384 changed 2026-11-18 | CC-BY-4.0 |
| Bitnami Vulnerability Database | BIT-VIRTUALENV-2026-113725 changed 2026-11-27 | Apache-2.0 |