Oct 24, 2026·5 min read·17 visits
Unsafe string replacement in virtualenv bash activation scripts allows arbitrary command execution via crafted prompt names during environment activation.
A command injection vulnerability in PyPA virtualenv prior to version 21.14.9 allows local attackers to execute arbitrary commands when a user sources a generated shell activation script containing a crafted prompt value.
PyPA virtualenv is a standard Python component used to create isolated virtual execution environments. During environment generation, virtualenv creates shell activation scripts (such as bin/activate) that modify shell settings, environment variables, and interactive command prompts.
In versions prior to 21.14.9, caller-supplied prompt identifiers supplied through the --prompt argument or environment settings are embedded into the interactive prompt string (PS1) inside bin/activate. The mechanism used to sanitize the custom prompt string relied on incomplete naive pattern replacements.
When a user sources an activation script where the prompt contains shell expansion syntax, such as command substitution constructs $() or backticks, the interactive shell evaluates the injected syntax during prompt rendering. This results in arbitrary code execution within the security context of the user sourcing the environment.
The underlying flaw resides in src/virtualenv/activation/bash/activate.sh. When custom prompts were supplied, virtualenv attempted to sanitize special prompt characters including backslashes, dollar signs, and backticks using Bash parameter substitution.
The initial implementation performed character replacements as follows:
_VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\\/\\\\\\\\}"
_VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\$/\\\$}"
_VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\`/\\\`}"This escaping strategy was flawed because shell prompt parsing in Bash and compatible shells executes in multiple evaluation passes. First, Bash decodes standard backslash prompt escapes. Second, if promptvars is active or if the shell operates in POSIX compatibility mode, it performs parameter expansion, command substitution, and arithmetic expansion on the resulting string.
Because the escaping logic only neutralized single-pass expansions, characters that survived initial string decoding were subjected to a secondary evaluation pass. Furthermore, when non-Bash shells such as dash sourced the script, parameter substitution rules behaved differently, causing syntax errors or secondary parsing flaws.
The remediation implemented in PR #3418 (commit 5f48d711731311428aebfae61d46957762155b22) changes the mechanism used to update PS1. Rather than evaluating and escaping variable content directly into the double-quoted string, the patched version defers evaluation by storing a literal variable reference.
The patch adds checks to ensure that PS1 modifications occur only when compatible shell instances (bash or zsh) are detected, bypassing unsupported POSIX shells like dash:
--- a/src/virtualenv/activation/bash/activate.sh
+++ b/src/virtualenv/activation/bash/activate.sh
@@ -137,29 +137,26 @@ else
export TK_LIBRARY
fi
- if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] ; then
+ if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] &&
+ { [ -n "${BASH_VERSION-}" ] || [ -n "${ZSH_VERSION-}" ]; }; then
_OLD_VIRTUAL_PS1="${PS1-}"
- _VIRTUAL_PROMPT="${VIRTUAL_ENV_PROMPT}"
- if [ -n "${BASH_VERSION-}" ]; then
- _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\\/\\\\\\\\}"
- _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\$/\\\$}"
- _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\`/\\\`}"
- elif [ -n "${ZSH_VERSION-}" ]; then
- _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\\/\\\\}"
- _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\$/\\\$}"
- _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\`/\\\`}"
- fi
- if [ -n "${ZSH_VERSION-}" ]; then
- _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\%/%%}"
+ if [ -n "${BASH_VERSION-}" ] && { shopt -q promptvars || shopt -qo posix; }; then
+ PS1='(${VIRTUAL_ENV_PROMPT-}) '"${PS1-}"
+ else
+ _VIRTUAL_PROMPT="${VIRTUAL_ENV_PROMPT//\\/\\\\}"
+ if [ -n "${ZSH_VERSION-}" ]; then
+ _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\$/\\\$}"
+ _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\`/\\\`}"
+ _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\%/%%}"
+ fi
+ PS1="(${_VIRTUAL_PROMPT}) ${PS1-}"
+ unset _VIRTUAL_PROMPT
fi
- PS1="(${_VIRTUAL_PROMPT}) ${PS1-}"
- unset _VIRTUAL_PROMPT
fiBy assigning PS1='(${VIRTUAL_ENV_PROMPT-}) '"${PS1-}", Bash treats VIRTUAL_ENV_PROMPT strictly as a literal variable reference during prompt rendering, entirely preventing shell command parsing of its inner content.
Exploitation requires an attacker to control the --prompt argument supplied during virtual environment creation or to influence the VIRTUAL_ENV_PROMPT environment variable prior to activation.
An attack scenario involves a shared repository or build configuration containing a pre-configured virtual environment generation script, where the prompt parameter is set to $(id > /tmp/pwned). When virtualenv builds the environment, it writes the raw or inadequately escaped string into bin/activate.
virtualenv --prompt '$(id > /tmp/pwned)' .venvWhen a user or automated pipeline executes source .venv/bin/activate, the shell reads the PS1 configuration. Upon rendering the primary prompt in the terminal, the subshell invocation executes id > /tmp/pwned without producing syntax errors.
Successful exploitation leads to arbitrary command execution in the context of the user running the interactive shell session. If an administrator or developer sources a compromised virtual environment activation script, the payload executes with their full privileges.
This vulnerability impacts developer workstations, continuous integration and continuous deployment (CI/CD) pipelines, and automated build scripts that dynamically construct virtual environments based on external repository metadata.
The CVSS v4.0 score is rated at 7.1 (High) with vector string CVSS:4.0/AV:L/AC:H/AT:P/PR:N/UI:A/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N. Exploitation requires local user interaction to source the generated script.
To resolve this vulnerability, update virtualenv to version 21.14.9 or later using standard package management tooling:
pip install --upgrade "virtualenv>=21.14.9"Existing virtual environments constructed prior to the update retain vulnerable bin/activate scripts. System administrators must regenerate existing virtual environments to ensure patched activation templates are written to disk.
Alternatively, users can set the VIRTUAL_ENV_DISABLE_PROMPT=1 environment variable prior to activation. This setting bypasses PS1 prompt modification entirely, preventing command evaluation regardless of virtualenv version.
CVSS:4.0/AV:L/AC:H/AT:P/PR:N/UI:A/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N| Product | Affected Versions | Fixed Version |
|---|---|---|
virtualenv PyPA | < 21.14.9 | 21.14.9 |
| Attribute | Detail |
|---|---|
| CWE ID | CWE-78 |
| CVSS v4.0 Score | 7.1 (High) |
| Attack Vector | Local |
| EPSS Score | 0.00142 (3.23th percentile) |
| CISA KEV | Not Listed |
| Exploit Status | Proof of Concept Available |
| Impact | Arbitrary Code Execution |
The software constructs an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when sent to a downstream component.
CVE-2026-126295 (also tracked as GHSA-fg9w-wfp5-j933) is a path confinement bypass vulnerability in the Natural Language Toolkit (NLTK) affecting versions 3.10.0 prior to 3.10.4. The flaw resides in nltk/parse/bllip.py within the BllipParser class and its factory method BllipParser.from_unified_model_dir(). Unlike sibling tool wrappers in NLTK that enforce data-root confinement via the nltk.pathsec module, BllipParser passes caller-supplied filesystem paths directly into the third-party bllipparser native C extension without validation. When an application passes untrusted input as model paths or directories to BllipParser, an attacker can force the native extension to open arbitrary files on the local filesystem. This leads to information disclosure through parser diagnostic oracles, local model tampering via shared directories, and denial of service by hanging worker threads on blocking special files (such as FIFOs or device nodes) or exhausting memory via oversized files.
CVE-2026-126300 (GHSA-ffr9-mgrr-wcvr) is an inefficient algorithmic complexity vulnerability (CWE-407) in the Natural Language Toolkit (NLTK) Python library affecting versions 3.2.5 prior to 3.10.4. The flaw resides in the quote-restoration routine of TreebankWordTokenizer.span_tokenize and NLTKWordTokenizer.span_tokenize, where repeated calls to list.pop(0) over matched quote tokens introduce quadratic O(n^2) time complexity. An unauthenticated remote attacker who supplies input containing long sequences of double-quote characters can exhaust CPU resources and degrade service availability.
The Natural Language Toolkit (NLTK) versions 3.6 through 3.10.3 contain an algorithmic complexity vulnerability in the LegalitySyllableTokenizer.tokenize method. When processing tokens composed of continuous runs of vowels, an unguarded string reversal and set membership lookup loop executes in quadratic time relative to the input token length. Remote attackers capable of submitting arbitrary text to applications utilizing this tokenizer can trigger sustained single-core CPU exhaustion and application-level denial of service.
CVE-2026-126304 is a symlink path traversal vulnerability (CWE-59) in the Natural Language Toolkit (NLTK) versions 3.10.0 prior to 3.10.4. The YCOECorpusReader class constructs internal sub-readers for the 'psd' and 'pos' subdirectories using FileSystemPathPointer.join(), which relies exclusively on lexical string-prefix validation rather than canonical path resolution. An attacker who supplies a crafted YCOE corpus containing symbolic links in place of the 'psd' or 'pos' subdirectories can bypass directory confinement and read arbitrary files from sibling corpora or sensitive directories within the NLTK data sandbox.
CVE-2026-128077 (GHSA-r99w-jh2x-3mg9) is an authorization bypass and interpretation conflict vulnerability affecting Nuxt and its underlying @nuxt/nitro-server package in versions 4.6.0 through 4.6.3. When an incoming HTTP request path begins with a double forward slash (e.g., //x/admin), the WHATWG URL parser within the Nuxt server-side page renderer interprets the initial segment as a network host/authority and resolves the remaining path (/admin) against the application's page router. Because Nitro server middleware, route-scoped serverHandlers, and Nitro routeRules evaluate the unparsed request path (//x/admin), path-based access controls, redirects, and security header policies configured for /admin fail to match and are bypassed.
Prior to version 2.10.2, the sqlite3-ruby gem explicitly cast 64-bit Ruby string lengths (long) to 32-bit signed integers (int) when invoking the underlying SQLite C API. On 64-bit platforms, providing a string of 4 GiB (2^32 bytes) or larger causes integer truncation, instructing SQLite to process only a prefix of the string. This flaw affects SQL query preparation, bound parameter values, and return values from custom Ruby-defined SQL functions and aggregates, allowing trailing SQL clauses such as WHERE restrictions to be silently dropped under specific conditions.