---
id: "CVE-2026-113725"
kind: "vulnerability"
aliases: ["CVE-2026-113725", "GHSA-vxj4-q4g9-crj7"]
title: "virtualenv bash activate runs commands from an environment name with a backslash before $"
severity: "high"
cvss: 7.800000190734863
epss: 0.001550000044517219
exploited: false
status: "open"
category: "package"
products: [{"name": "virtualenv", "fixed": ["21.14.7"], "affected": "<= 21.14.6", "ecosystem": "pypi"}]
ecosystems: ["pypi"]
tags: ["bash", "ci", "cwe-116", "cwe-78", "developer-workstations", "package", "python", "virtualenv"]
not_affected_if: ["fixed-version-21.14.7-or-later", "vendor-managed-environments-with-no-untrusted-names", "zsh-only"]
published_at: "2026-10-20T20:17:19+00:00"
first_seen_at: "2026-10-23T19:11:32+00:00"
updated_at: "2026-10-23T21:57:21+00:00"
sources: [{"source": "ghsa", "url": "https://github.com/advisories/GHSA-vxj4-q4g9-crj7", "first_seen_at": "2026-10-23T19:11:32+00:00"}, {"source": "nvd", "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-113725", "first_seen_at": "2026-10-23T21:57:21+00:00"}]
---

# virtualenv bash activate runs commands from an environment name with a backslash before $

virtualenv's bash activate script fails to escape backslashes in the environment name before bash expands PS1, so a name containing \$(...) runs attacker-chosen commands in the user's shell on every prompt draw. An attacker who controls an environment name (directory name, --prompt or VIRTUALENV_PROMPT, e.g. via CI or a cloned repo) gets command execution with the victim's privileges once the victim sources that environment's activate script.

_Summary, check and fix written by a model from the sources; labelled as such._

## Affected

- pypi:virtualenv affected <= 21.14.6 fixed 21.14.7

## How to check

Run pip show virtualenv or python -m virtualenv --version and check whether it is 21.14.6 or earlier (affected <= 21.14.6).
In each environment, check whether bin/activate and bin/activate.sh were created by an affected version and whether any environment name contains a backslash followed by $.

## Fix

Upgrade virtualenv to 21.14.7 or later.
Until upgraded, set VIRTUAL_ENV_DISABLE_PROMPT=1 before sourcing activate, or run shopt -u promptvars.

## Timeline

- 2026-10-23T19:11:32+00:00 ghsa https://github.com/advisories/GHSA-vxj4-q4g9-crj7
- 2026-10-23T21:57:21+00:00 nvd https://nvd.nist.gov/vuln/detail/CVE-2026-113725

## From the sources

### 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

```console
$ 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

- [x] 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.

---

_Free to read at a human pace. An API with keys and an MCP server are in preparation; early access: hello@infrastack.ai_
