Skip to main content
Vulnerability Database/CVE-2026-113776

CVE-2026-113776: virtualenv RCE Vulnerability

CVE-2026-113776 is a remote code execution vulnerability in virtualenv affecting versions 20.26.6 to 21.14.2. Attackers can exploit placeholder substitution in activation templates to execute commands. This article covers technical details, affected versions, impact assessment, and mitigation strategies.

Published:

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

CVE-2026-113776 Overview

CVE-2026-113776 is a command injection vulnerability in virtualenv, the widely used tool for creating isolated Python environments. The flaw affects versions 20.26.6 through 21.14.1 and resides in the ViaTemplateActivator.instantiate_template() method. The function replaces placeholders in activation scripts one key at a time, allowing a previously substituted value containing a trigger name such as __VIRTUAL_NAME__, __VIRTUAL_ENV__, or __VIRTUAL_PROMPT__ to be re-substituted in a later pass. When a user activates the environment through bash, fish, xonsh, or activate_this.py, the second substitution can close the surrounding quoting and execute attacker-controlled content. The issue is fixed in version 21.14.2.

Critical Impact

An attacker who influences the destination path or --prompt value can achieve local code execution in the context of the user activating the virtual environment.

Affected Products

  • virtualenv from version 20.26.6 up to and including 21.14.1
  • Activation scripts for bash, fish, xonsh, and activate_this.py
  • csh activation script is affected to a lesser degree, where the __VIRTUAL_PROMPT_DISPLAY_TCSH__ token can break the generated script without achieving execution

Discovery Timeline

  • 2026-10-20 - CVE-2026-113776 published to the National Vulnerability Database
  • 2026-10-22 - Last updated in NVD database

Technical Details for CVE-2026-113776

Vulnerability Analysis

The vulnerability is a command injection flaw ([CWE-78]) rooted in how virtualenv renders activation scripts. ViaTemplateActivator.instantiate_template() walks a dictionary of placeholder keys and performs a sequential str.replace() across the entire template for each key. Because the passes are independent, a value substituted early that happens to contain another placeholder trigger name is treated as a valid placeholder during subsequent passes. Shell quoting applied in the first pass does not protect against reinterpretation during later passes.

Exploitation requires a user to activate a virtual environment whose destination path or --prompt value was influenced by an attacker. This commonly happens in continuous integration pipelines, build systems, and automation that create environments from untrusted repository metadata or user-supplied inputs.

Root Cause

The root cause is sequential, non-atomic placeholder substitution combined with quoting applied only at substitution time. When placeholder A is replaced first with a quoted value containing the literal string __VIRTUAL_PROMPT__, a later replacement of placeholder B rewrites content inside the already quoted string. The injected value's own quoting characters can close the earlier string literal and append shell syntax that executes when the activation script is sourced.

Attack Vector

The attacker supplies a crafted directory path or --prompt argument that embeds a trigger placeholder name along with quoting characters. When the victim runs source bin/activate under bash, fish, xonsh, or imports activate_this.py, the generated script executes attacker-controlled commands under the victim's user account.

python
# Security patch in src/virtualenv/activation/cshell/__init__.py
# Source: https://github.com/pypa/virtualenv/commit/602b26623a724827ff171bf11fef4ad186d01f74

    # quotes and aborts the whole script with "Event not found"; only a backslash suppresses it
    return shlex.quote(string).replace("!", "\\!")

-    def instantiate_template(self, replacements: dict[str, str], template: str, creator: Creator) -> str:
-        text = super().instantiate_template(replacements, template, creator)
+    def substitutions(self, replacements: dict[str, str], creator: Creator) -> dict[str, str]:
        # carries its own quoting, so it cannot go through the shared quote() pass with the other replacements;
        # tcsh and plain csh disagree on whether % needs escaping, so activate.csh picks one of these at runtime
        display = creator.env_name if self.flag_prompt is None else self.flag_prompt
-        text = text.replace(_PROMPT_DISPLAY_TCSH, _prompt_literal(display, tcsh=True))
-        return text.replace(_PROMPT_DISPLAY_PLAIN, _prompt_literal(display, tcsh=False))
+        return {
+            **super().substitutions(replacements, creator),
+            _PROMPT_DISPLAY_TCSH: _prompt_literal(display, tcsh=True),
+            _PROMPT_DISPLAY_PLAIN: _prompt_literal(display, tcsh=False),
+        }

The patch refactors the activator API to expose a substitutions() method returning a single dictionary. All placeholders are resolved in one atomic pass, preventing a substituted value from being reinterpreted as a placeholder during a later iteration. See the GitHub Security Advisory GHSA-8rjx-v5ww-45pp for additional detail.

Stop Remote Code Execution Before It Runs

Singularity™ Endpoint detects and blocks exploit attempts at machine speed, including zero-days and novel attack techniques.

Stop Exploit Attempts

Detection Methods for CVE-2026-113776

Indicators of Compromise

  • Virtual environment directory paths containing the literal strings __VIRTUAL_NAME__, __VIRTUAL_ENV__, or __VIRTUAL_PROMPT__
  • Activation scripts (bin/activate, bin/activate.fish, bin/activate.xsh, bin/activate_this.py) containing shell metacharacters outside expected quoted paths
  • Unexpected child processes spawned by a shell immediately after an activate script is sourced
  • CI job logs showing virtualenv creation with attacker-controlled --prompt or destination arguments

Detection Strategies

  • Inventory installed virtualenv versions across developer workstations, build agents, and container images, and flag any in the range 20.26.6 to 21.14.1
  • Scan virtual environment directories for activation scripts whose quoted path or prompt literals contain embedded placeholder trigger names
  • Review source control history and CI pipeline configurations for parameters that feed untrusted input into virtualenv destination paths or --prompt

Monitoring Recommendations

  • Alert on process executions where a shell parent sources an activate script and immediately launches unexpected binaries such as curl, wget, nc, or python -c
  • Monitor package installations and upgrades of virtualenv on build systems to ensure the fixed version is deployed
  • Track creation of Python virtual environments under directories derived from external inputs (webhooks, pull request metadata, artifact names)

How to Mitigate CVE-2026-113776

Immediate Actions Required

  • Upgrade virtualenv to version 21.14.2 or later on all systems, including CI runners, container base images, and developer workstations
  • Audit automation that constructs virtual environment paths or --prompt values from untrusted input and sanitize those inputs
  • Rebuild any virtual environments that were created with vulnerable virtualenv versions from attacker-influenced paths

Patch Information

The fix is included in virtualenv release 21.14.2. The remediation is implemented in commit 602b2662, which replaces sequential placeholder replacement with a single atomic substitution pass. Install with pip install --upgrade 'virtualenv>=21.14.2'.

Workarounds

  • Reject or sanitize any user-controlled values destined for the virtualenv target directory or the --prompt argument, filtering out the substrings __VIRTUAL_NAME__, __VIRTUAL_ENV__, and __VIRTUAL_PROMPT__
  • Create virtual environments only under fully controlled, trusted paths in automation pipelines
  • Prefer the standard library venv module where feasible until the upgrade is deployed
bash
# Upgrade virtualenv to the patched release
python -m pip install --upgrade 'virtualenv>=21.14.2'

# Verify the installed version
virtualenv --version

# Example input validation before invoking virtualenv in automation
case "$ENV_PATH" in
  *__VIRTUAL_NAME__*|*__VIRTUAL_ENV__*|*__VIRTUAL_PROMPT__*)
    echo "Rejected: path contains reserved placeholder token" >&2
    exit 1
    ;;
esac
virtualenv "$ENV_PATH"

Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

Sources: National Vulnerability Database, CISA KEV, Exploit-DB

Experience the Most Advanced Cybersecurity Platform

See how the world’s most intelligent, autonomous cybersecurity platform can protect your organization today and into the future.