virtualenv writes prompt values into pyvenv.cfg without sanitizing line boundaries, allowing configuration injectionGHSA-9h9j-4vrj-gf7g
Fix: pypa/virtualenv#3247GHSA-9h9j-4vrj-gf7g is a CWE-93 vulnerability in virtualenv. A fix is available for virtualenv — see the affected versions and patch details below.
Exploitation Status
No confirmed exploitation observed yet
- CISA’s own triage has not observed active exploitation or public proof-of-concept code for this CVE as of its last assessment.
Exploitation and automatability from CISA’s SSVC triage for GHSA-9h9j-4vrj-gf7g.
EPSS Exploitation Probability
Probability of exploitation in the next 30 days, from FIRST.org EPSS.
Real-World Exposure
virtualenvReal-time download stats are indexed for npm and PyPI packages. This vulnerability affects PyPI packages — download data is not available via public APIs for these ecosystems.
Description
Summary
pyvenv.cfg is a line-based format with no escape syntax. PyEnvCfg.write() wrote values verbatim, while PyEnvCfg._read_values() parses the file with str.splitlines(). A value containing a line boundary therefore became additional configuration lines, and because reading is last-wins, the injected keys replaced any key written earlier in the file.
Impact
The prompt value is the reachable input: it is set by --prompt, by the VIRTUALENV_PROMPT environment variable, or from the config file, and write() emits prompt before home. A crafted prompt can therefore set home in the generated pyvenv.cfg:
$ virtualenv --prompt $'x"\nhome = /attacker/path\nprompt = "z' venv
$ grep '^home' venv/pyvenv.cfg
home = /attacker/path
home is what tooling reads to locate the base interpreter, so a consumer that trusts it can be pointed elsewhere. implementation, version_info, version, executable, command and virtualenv are also written before prompt and can be replaced the same way.
This requires the prompt to come from somewhere other than the person running the command, for example a CI job templating a branch name into it, tooling deriving an environment name from user-supplied data, or an inherited VIRTUALENV_PROMPT. Where the operator supplies the prompt directly they already control the command line, and the effect is corruption rather than privilege gain: the value is truncated at the boundary and read back with a dangling quote.
Details
The boundary set is the one str.splitlines() recognizes, which is wider than \n: \r, \v, \f, the file, group and record separators, U+0085, U+2028 and U+2029 were all written through unchanged and all split the line when read back.
Patches
PyEnvCfg.write() now collapses those boundaries to spaces as it serializes each line, so it cannot emit a structurally invalid file regardless of what a caller places in content.
Workarounds
Do not pass externally influenced data as the virtualenv prompt. Strip line boundaries from any value before using it as --prompt or VIRTUALENV_PROMPT.
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 🐍PyPI | virtualenv | all versions | 21.7.11pip install --upgrade 'virtualenv==21.7.11' |
Detection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for virtualenv, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update virtualenv to 21.7.11 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-9h9j-4vrj-gf7g is resolved across your whole dependency graph.
Workarounds
If you can't upgrade right away: gate or disable the affected feature, validate untrusted input at the boundary, and avoid passing attacker-controlled data into the vulnerable path. O3's runtime protection blocks exploitation in production as an interim safeguard until the upgrade lands.
Fixing This On Your OS
If you run this on a Linux distribution, patch through your package manager against the distro's own security advisory below — it tracks the exact backported fix for your release, which can ship on a different timeline (and sometimes a different severity) than the upstream project.
A flaw was found in virtualenv, a tool for creating isolated Python virtual environments that is bundled in a number of Red Hat offerings, including Red Hat Enterprise Linux, Red Hat OpenShift AI, and other layered products and containers, as well as in Fedora and EPEL community builds. Red Hat rates this flaw as…
Strip line boundaries (such as newline, carriage return, and other Unicode line-separator characters) from any value before using it as --prompt or VIRTUALENV_PROMPT, and do not pass externally influenced data -- for example user-supplied strings or CI-derived values such as branch names -- as the virtualenv prompt. Ensure the VIRTUALENV_PROMPT environment variable and any configuration file that sets the prompt are sourced only from trusted input. The upstream project fixed this issue in virtualenv 21.7.11 by collapsing line boundaries when writing pyvenv.cfg, so updating to a version that contains this fix resolves the issue. For Red Hat products that bundle virtualenv, apply updates…Source: Red Hat security advisory for GHSA-9h9j-4vrj-gf7g (CC BY 4.0)
| Product | Fixed in | Advisory |
|---|---|---|
| Red Hat Ansible Automation Platform 2.6 | ansible-automation-platform-26/eda-controller-rhel9:1791945282 | RHSA-2026:87120 |
| Red Hat Ansible Automation Platform 2.7 | ansible-automation-platform-27/eda-controller-rhel9:1792141010 | RHSA-2026:87124 |
| Red Hat OpenShift AI 2.25 | rhoai/odh-feature-server-rhel9:1792148523 | RHSA-2026:87410 |
| Red Hat OpenShift AI 3.4 | rhoai/odh-feature-server-rhel9:1791863220 | RHSA-2026:84734 |
| Red Hat OpenShift AI 3.5 | rhoai/odh-ta-lmes-job-rhel9:1792501995 | RHSA-2026:86891 |
Frequently Asked Questions
Is GHSA-9h9j-4vrj-gf7g in your dependencies?
Find it across PyPI, including transitive dependencies.