NewApp Monitoring is liveSign up free
AgentbeamBeta
Open-source package vulnerability · PyPI

CVE-2026-115586: virtualenv: Bash activator leaves the --prompt value unescaped in PS1 when promptvars is off, so prompt expansion later executes it (regression in 21.14.9)

highCVSS 4.0 7.1GHSA-cx6f-vjhg-g3cc

virtualenv 21.14.9 through 21.14.12 writes the `--prompt` value into `PS1` without escaping in the bash activator when `promptvars` is off. When prompt expansion is later turned on, bash runs any command substitution in the value as the user. Upgrade to virtualenv 21.14.13. Version 21.14.8 is not affected.

Published Oct 23, 2026 · Analysis Nov 2, 2026

What an attacker can do

The bash bin/activate script copies VIRTUAL_ENV_PROMPT into PS1. If promptvars is off at activation, the script stores the raw value, assuming expansion will never run. That assumption is wrong. Running shopt -s promptvars or set -o posix later, or starting an interactive child bash that inherits the exported PS1, makes bash expand the prompt and run $(...) or backticks in it.

This is a regression. Version 21.14.8 escaped $ and the backtick always. The 21.14.9 change for GHSA-6w3r-xr62-4xcp (pull request 3418) rewrote the block and dropped that escaping for bash.

The attacker must control the prompt value. The project's security policy already treats it as data that can come from project metadata the user did not write, for example a repository or tool config that passes --prompt 'x$(id > /tmp/ve-pwn)y'. The victim creates the environment and activates it with promptvars off, which some ~/.bashrc files set to speed up the prompt. The command runs as that user at the next prompt redraw, possibly in a later shell, because the value is stored in pyvenv.cfg and the script. There is no privilege escalation beyond that user. The CVSS vector reflects the local, high-complexity, user-driven path.

Who is affected

virtualenv >= 21.14.9 and < 21.14.13 with the bash activator. The reporter tested 21.14.9 and 21.14.12 as affected and 21.14.8 as clean. Activations that run with default options, or with posix mode already on, stayed inert in the tests. Check the version:

pip show virtualenv

virtualenv

Ecosystem
PyPI
Affected
>= 21.14.9, < 21.14.13
Fixed in
21.14.13
Check
pip show virtualenv

How to fix it

Upgrade to virtualenv 21.14.13:

pip install --upgrade "virtualenv==21.14.13"

Then recreate environments built with an affected version, since the activate script is generated at creation time. Until then, set VIRTUAL_ENV_DISABLE_PROMPT=1 before activating, which skips the prompt block, or leave promptvars at its default. Never pass an untrusted value to --prompt.

How to tell if you were hit

Search project configs, tox or nox files and scripts for --prompt values or a prompt argument that contain $(, backticks or $. Check existing environments: grep VIRTUAL_ENV_PROMPT bin/activate and the prompt line in pyvenv.cfg. Look in ~/.bashrc for shopt -u promptvars. Unexpected files created at prompt redraw, such as /tmp/ve-pwn in the proof of concept, point to execution.

Original advisory

From the GitHub Advisory Database (CC BY 4.0).

Summary

The bash activator puts the caller-supplied prompt value into PS1 unescaped whenever promptvars is off at activation time, and assumes prompt expansion can never run afterwards. promptvars and posix mode are runtime shell state, not a property of the activation moment: re-enabling prompt expansion in the same shell (shopt -s promptvars, set -o posix) or starting an interactive child bash that inherits the exported PS1 makes bash expand the stored value and run the command substitution in it. An attacker who controls the prompt value gets command execution as the user who sources bin/activate.

This is a regression. 21.14.8 escaped $ and the backtick unconditionally and stays inert under the same sequence. The 21.14.9 fix for GHSA-6w3r-xr62-4xcp (#3418) rewrote that block and left bash with a path that stores the raw value whenever promptvars is off.

Affected area

Activation scripts (activate, activate.bat, activate.csh, activate.fish, activate.nu, Activate.ps1, activate.xsh) — specifically the bash bin/activate.

Attacker-controlled input

The --prompt value, which the security policy already lists as a value that may come from project metadata the user did not write. It reaches virtualenv as --prompt on the command line or as the prompt argument of the API, is written into bin/activate as the literal VIRTUAL_ENV_PROMPT assignment (correctly quoted, the value arrives there as data), and the script then copies it into PS1 without escaping $ or the backtick.

Example: a repository or tool config supplies a prompt such as x$(id > /tmp/ve-pwn)y; the victim creates and later activates the environment.

Details

Source of the latest release: `src/virtualenv/activation/bash/activate.sh` lines 140-160

if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT-}" ] &&
    { [ -n "${BASH_VERSION-}" ] || [ -n "${ZSH_VERSION-}" ]; }; then
    _OLD_VIRTUAL_PS1="${PS1-}"
    # bash expands PS1 after decoding its prompt escapes when promptvars is on or in posix mode, so the prompt holds a
    # reference to the variable and its value never reaches that expansion; otherwise only the decode runs and
    # backslashes need doubling. ...
    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
fi

Two separate mistakes combine:

  1. A runtime shell option is treated as a constant. shopt -u promptvars at the moment of source does not bind the shell forever: shopt -s promptvars and set -o posix both re-enable PS1 expansion in the same shell. The code itself tests shopt -qo posix because posix mode expands the prompt regardless of promptvars, which shows the expansion state is not fixed by the activation.
  2. The escaping that would keep the value inert in that mode is missing for bash. GHSA-5vjq-rrrf-7h2q ("activate runs commands from the environment name in zsh with PROMPT_SUBST") fixed exactly this shape for zsh, reasoning that "a user can set it after activation", by escaping $ and the backtick. Bash lost the equivalent escaping in the same commit that added the zsh branch.

The rendered prompt shows the regression directly:

21.14.8   PS1 = (x\\$(id > /tmp/ve-pwn)y)       <- escaped, inert
21.14.9   PS1 = (x$(id > /tmp/ve-pwn)y)         <- raw value
21.14.12  PS1 = (x$(id > /tmp/ve-pwn)y)         <- raw value

Relevant commit: `5f48d711` "fix(bash): preserve literal prompts in supported shells (#3418)", which removed the unconditional $/backtick escaping from the bash path. Advisory for that change: GHSA-6w3r-xr62-4xcp.

Proof of concept

Non-destructive payload: it runs id and writes the output to a file.

python -m virtualenv --no-seed --no-periodic-update --activators bash \
    --prompt 'x$(id > /tmp/ve-pwn)y' /tmp/venv-demo

cat > /tmp/rc <<'EOF'
shopt -u promptvars
. /tmp/venv-demo/bin/activate
shopt -s promptvars
EOF

# the prompt needs a tty; script(1) provides one
printf 'exit\n' | script -qec 'bash --noprofile --rcfile /tmp/rc -i' /dev/null

cat /tmp/ve-pwn

Observed on 21.14.12:

$ cat /tmp/ve-pwn
uid=1000(asrun) gid=1000(asrun) groups=1000(asrun),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),999(ollama)

The prompt printed as (xy). The same script against 21.14.8 creates no file; against 21.14.9 and 21.14.12 it does.

Triggers, all run in a pty, activation itself never executing anything; execution happens at the next prompt redraw after prompt expansion is enabled:

| After `. bin/activate` (activated with `shopt -u promptvars`) | 21.14.8 | 21.14.9 | 21.14.12 |
| `shopt -s promptvars` | inert | executes | executes |
| `set -o posix` | inert | executes | executes |
| `export PS1`, then start an interactive child `bash` (its `promptvars` defaults to on) | inert | executes | executes |
| control: activation with default options | inert | inert | inert |
| control: activation with `set -o posix` already on | inert | inert | inert |

The third trigger needs no explicit option change: the poisoned PS1 is inherited and the child bash expands it on its first prompt.

shopt -u promptvars is a documented way to make an expensive bash prompt cheap and appears in ~/.bashrc files for that reason; it is also the state left by some prompt wrappers. Whoever sources such an environment gets the unescaped value in PS1.

Impact

Command execution as the user who sources bin/activate, from a value the user may not have written (project metadata or tool config reaching --prompt). The value is also persisted in pyvenv.cfg and in the generated script, so it survives the activation that created it and fires later, in a different shell session, on the first prompt redraw with expansion enabled. No privilege elevation beyond the activating user.

Severity: high, matching GHSA-5vjq-rrrf-7h2q for the same class of prompt-expansion command injection reached by toggling a shell option after activation. If you consider the promptvars state a caller-controlled condition rather than a shell condition, this is medium; the fix is the same either way.

Versions tested

virtualenv 21.14.12 and 21.14.9 (affected), virtualenv 21.14.8 (unaffected control); CPython 3.14.7; Linux 6.x (WSL2); bash 5.1.16(1)-release. --prompt handling is platform independent; zsh/fish/csh/nu/PowerShell activators were not part of this report.

Known mitigation

For a user: activate with promptvars left at its default, or set VIRTUAL_ENV_DISABLE_PROMPT=1 before activating, which skips the whole prompt block. Do not pass an untrusted value to --prompt.

Fix in the activator: escape $ and the backtick for bash as well, in both branches, with a single backslash ($ -> \$, backtick -> `\ `, \ -> \\). Verified on bash 5.1.16 that a PS1 built that way is inert with promptvars on, with promptvars off, and with promptvars` off followed by posix mode, while still rendering the literal value on screen. That is better than both current shapes: 21.14.8's four-level escaping left stray backslashes on screen, which is why the block was rewritten.

    else
        _VIRTUAL_PROMPT="${VIRTUAL_ENV_PROMPT//\\/\\\\}"
        _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\$/\\\$}"
        _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\`/\\\`}"
        if [ -n "${ZSH_VERSION-}" ]; then
            _VIRTUAL_PROMPT="${_VIRTUAL_PROMPT//\%/%%}"
        fi
        PS1="(${_VIRTUAL_PROMPT}) ${PS1-}"

For the tests, tests/unit/activation/test_bash.py::test_bash_prompt_options already parametrises ("before", "after", "expected") and covers before="shopt -u promptvars" with after="". The missing axis is the transition: ("shopt -u promptvars", "shopt -s promptvars", ...) and ("shopt -u promptvars", "set -o posix", ...), with the existing PWNED check asserting no file was created.

Latest release

  • [x] The problem reproduces on the latest virtualenv release.

Credited to rozzkml.

Questions

Is virtualenv 21.14.8 affected?

No. The advisory uses 21.14.8 as the unaffected control because it escaped $ and the backtick unconditionally. The regression starts at 21.14.9.

Does activating the environment run the command immediately?

No. Activation itself executes nothing. Execution happens at the next prompt redraw after prompt expansion is enabled, through shopt -s promptvars, set -o posix or a child bash that inherits PS1.

Do I need a malicious prompt value to be hit?

Yes. The attacker must control the --prompt value, for example through project metadata or tool config. Default prompts are safe.

Are zsh, fish and PowerShell activators covered?

The report concerns the bash activator only. The reporter did not test the other activators.

References

How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology

More PyPI vulnerabilities

All PyPI entries