7.8high
virtualenv activate runs commands from the environment name in zsh with PROMPT_SUBST
- Severity
- 7.8high CVSS:3.1 by GitHub_M
- Exploit likelihood
- 0.38% (higher than 34% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- GitHub_M
- Also known as
- GHSA-5vjq-rrrf-7h2qBIT-VIRTUALENV-2026-113726PYSEC-2026-4385
Description
virtualenv is a tool for creating isolated virtual python environments. Prior to 21.13.0, the bash activate script that zsh also sources leaves the environment name unescaped; from 21.13.0 until 21.14.4, it escapes backslashes, dollar signs, and backticks only when BASH_VERSION is set, so zsh receives the raw value. The script assigns that value to PS1. In zsh with PROMPT_SUBST, an attacker-influenced environment directory, --prompt, or VIRTUALENV_PROMPT value containing command, parameter, or arithmetic expansion syntax can therefore execute commands in the user's shell each time the prompt is drawn. A percent sign is separately interpreted as a zsh prompt escape but does not by itself execute commands. Plain zsh with PROMPT_SUBST disabled and bash are not affected by this mechanism. This issue is fixed in version 21.14.4.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| pypa virtualenv | < 21.14.4 | CVE List |
| virtualenv (PyPI) | before 21.14.4 | GitHub Advisory Database, PyPA Advisory Database |
| virtualenv virtualenv | before 21.14.4 | NVD |
| virtualenv (Bitnami) | before 21.14.4 | 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.13.0, the bash activate script that zsh also sources leaves the environment name unescaped; from 21.13.0 until 21.14.4, it escapes backslashes, dollar signs, and backticks only when BASH_VERSION is set, so zsh receives the raw value. The script assigns that value to PS1. In zsh with PROMPT_SUBST, an attacker-influenced environment directory, --prompt, or VIRTUALENV_PROMPT value containing command, parameter, or arithmetic expansion syntax can therefore execute commands in the user's shell each time the prompt is drawn. A percent sign is separately interpreted as a zsh prompt escape but does not by itself execute commands. Plain zsh with PROMPT_SUBST disabled and bash are not affected by this mechanism. This issue is fixed in version 21.14.4.
GitHub Advisory Database
Impact
zsh users activate an environment with the bash activate script, which puts the environment name into PS1. Since
21.13.0 the script escapes backslashes, dollar signs and backticks in that name, but only when BASH_VERSION is set, so
zsh gets the raw value. With the PROMPT_SUBST option set, zsh runs parameter expansion, command substitution and
arithmetic expansion on PS1 each time it draws the prompt. A name that contains $(...), backticks or ${...} then
runs as commands in the user's shell, once per prompt.
The name comes from the environment directory, or from --prompt or VIRTUALENV_PROMPT. After you create an
environment with:
$ virtualenv 'x$(touch PWNED)y'
source 'x$(touch PWNED)y/bin/activate' in a zsh session with PROMPT_SUBST set creates PWNED, and the prompt shows
(xy). Passing that value as --prompt to an environment with a plain name has the same effect. Without
PROMPT_SUBST, zsh shows the name as text and runs nothing. bash runs nothing either.
A plain zsh starts with PROMPT_SUBST off. oh-my-zsh users have it on: oh-my-zsh loads
lib/theme-and-appearance.zsh
at startup, and that file sets it. An attacker needs to influence the environment path or prompt: 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.
zsh also reads % in PS1 as a prompt escape, so a name with %n showed the user name in place of those characters,
though without running commands.
The bug is in releases up to and including 21.14.3. The payload runs on 20.26.6 and 21.14.3, and the reporter confirmed 21.9.1.
Patches
Fixed in 21.14.4. Under zsh, activate now escapes the name the way it does under bash and doubles
%, so the example above runs nothing and the prompt shows the name as given. zsh gets the escaping even when
PROMPT_SUBST is off, because a user can set the option after activation; a name with a backslash, dollar sign or
backtick then shows the added backslashes.
Fix: https://github.com/pypa/virtualenv/commit/5b915367da82bd024b2a0d28d2f98007034b4aa2
Workarounds
Set VIRTUAL_ENV_DISABLE_PROMPT=1 before you source activate, which leaves PS1 alone, or run
unsetopt prompt_subst if your prompt does not need it. Check the name of an environment you did not create before you
source its activate.
Credits
Kaya Emre Arikan (@kemrec) reported this issue.
References
| https://github.com/pypa/virtualenv/security/advisories/GHSA-5vjq-rrrf-7h2q | advisory, fix, patch, vendor-advisory, web | |
| https://github.com/pypa/virtualenv/commit/5b915367da82bd024b2a0d28d2f98007034b4aa2 | fix, patch, web | |
| https://github.com/pypa/virtualenv/releases/tag/21.14.4 | advisory, article, release-notes, web | |
| https://nvd.nist.gov/vuln/detail/CVE-2026-113726 | advisory, web | |
| https://github.com/pypa/virtualenv | package | |
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2026-113726 changed 2026-10-27 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-5vjq-rrrf-7h2q changed 2026-11-18 | CC-BY-4.0 |
| NVD | CVE-2026-113726 changed 2026-11-17 | Public domain |
| PyPA Advisory Database | PYSEC-2026-4385 changed 2026-11-18 | CC-BY-4.0 |
| Bitnami Vulnerability Database | BIT-VIRTUALENV-2026-113726 changed 2026-11-27 | Apache-2.0 |