---
id: "CVE-2026-113776"
kind: "vulnerability"
aliases: ["CVE-2026-113776", "GHSA-8rjx-v5ww-45pp"]
title: "virtualenv activation scripts run code from a path that contains a placeholder name"
severity: "high"
cvss: 7.800000190734863
epss: 0.002469999948516488
exploited: false
status: "open"
category: "package"
products: [{"name": "virtualenv", "fixed": ["21.14.2"], "affected": ">= 20.26.6, <= 21.14.1", "ecosystem": "pypi"}]
ecosystems: ["pypi"]
tags: ["ci", "cwe-78", "cwe-94", "developer-machines", "package", "python", "virtualenv"]
not_affected_if: ["no-untrusted-directory-names", "virtualenv-21.14.2-or-later", "virtualenv-below-20.26.6"]
published_at: "2026-10-20T22:19:30+00:00"
first_seen_at: "2026-10-23T19:11:32+00:00"
updated_at: "2026-10-23T21:57:25+00:00"
sources: [{"source": "ghsa", "url": "https://github.com/advisories/GHSA-8rjx-v5ww-45pp", "first_seen_at": "2026-10-23T19:11:32+00:00"}, {"source": "nvd", "url": "https://nvd.nist.gov/vuln/detail/CVE-2026-113776", "first_seen_at": "2026-10-23T21:57:25+00:00"}]
---

# virtualenv activation scripts run code from a path that contains a placeholder name

virtualenv activation scripts can be made to execute attacker-chosen shell or Python code when a path or --prompt contains a placeholder name such as __VIRTUAL_NAME__. An attacker who controls the destination directory name, for example from a CI branch name or a cloned repo, gets code execution when a user activates the environment.

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

## Affected

- pypi:virtualenv affected >= 20.26.6, <= 21.14.1 fixed 21.14.2

## How to check

Run pip show virtualenv to get the installed version; versions 20.26.6 through 21.14.1 are affected.
List environment paths and --prompt values for placeholder names like __VIRTUAL_NAME__, __VIRTUAL_ENV__ or __VIRTUAL_PROMPT__.
Inspect the VIRTUAL_ENV line in bin/activate of any environment you did not create.

## Fix

Upgrade virtualenv to 21.14.2 or later.
Until then, do not create environments whose path or --prompt contains a placeholder name, and inspect generated activation scripts before sourcing them.

## Timeline

- 2026-10-23T19:11:32+00:00 ghsa https://github.com/advisories/GHSA-8rjx-v5ww-45pp
- 2026-10-23T21:57:25+00:00 nvd https://nvd.nist.gov/vuln/detail/CVE-2026-113776

## From the sources

### Impact

`ViaTemplateActivator.instantiate_template` replaces the placeholders in an activation template one key at a time, each across the whole text. When a value that it already substituted and quoted contains the name of a later placeholder, the later pass rewrites that name inside the quoted literal. The inserted value brings its own quotes, which close the outer literal, and the rest of the path runs as code when a user activates the environment.

`__VIRTUAL_NAME__` holds the environment's directory name, so a destination such as `A__VIRTUAL_NAME__B/x'$(touch PWNED)'y` is enough. In the default `activate` for bash, the `VIRTUAL_ENV` line renders as:

```sh
VIRTUAL_ENV='/tmp/t/A'x'"'"'$(touch PWNED)'"'"'y'B/x'"'"'$(touch PWNED)'"'"'y'
```

Sourcing that script runs `touch PWNED`. The same payload in a path without the placeholder name runs nothing. `activate.fish` runs the command the same way, and the reporter also showed Python code execution through `activate.xsh` and `bin/activate_this.py`. In `activate.csh`, a directory named after a prompt display placeholder, such as `__VIRTUAL_PROMPT_DISPLAY_TCSH__`, breaks the script with `Unmatched '''`.

No change to `quote()` can stop this, because the rewrite happens after `quote()` ran; it defeats `shlex.quote` and `repr()` alike.

An attacker needs to influence the destination path or `--prompt`: a CI job or wrapper tool that builds the path from a branch or project name, or a directory in a cloned repository or unpacked archive.

The bug affects versions 20.26.6 through 21.14.1. Version 20.26.6 first quoted template values (#2768) and introduced the per-key loop.

### Patches

Fixed in 21.14.2. Activation scripts now keep a placeholder name in the environment's path or prompt as plain text, and activating the example above runs nothing. Fix: https://github.com/pypa/virtualenv/commit/602b26623a724827ff171bf11fef4ad186d01f74

### Workarounds

Do not create an environment whose path or `--prompt` contains a placeholder name such as `__VIRTUAL_NAME__`, `__VIRTUAL_ENV__` or `__VIRTUAL_PROMPT__`, and inspect the generated activation script before you source one you did not create.

### Credits

Kevin Stubbings (@Kwstubbs) of GitHub Security Lab reported this issue.

---

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