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

CVE-2026-113725: virtualenv Python Tool RCE Vulnerability

CVE-2026-113725 is a remote code execution flaw in virtualenv that allows arbitrary command execution through malicious environment names in bash activate scripts. This article covers technical details, affected versions, and mitigation.

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-113725 Overview

CVE-2026-113725 affects virtualenv, the widely used tool for creating isolated Python virtual environments. Versions prior to 21.14.7 contain a command injection flaw [CWE-78] in the bash activate script. The script escapes the environment name for only one of the two passes bash performs over PS1. An environment name containing $(...) or backticks executes as shell commands each time bash redraws the prompt. The maintainer, pypa, released version 21.14.7 with the fix.

Critical Impact

An attacker who controls a virtual environment name can achieve arbitrary command execution in the user's shell every time the prompt is rendered after activation.

Affected Products

  • pypa/virtualenv versions prior to 21.14.7
  • Bash shells sourcing the vulnerable activate script
  • Any workflow consuming untrusted environment names or --prompt values

Discovery Timeline

  • 2026-10-20 - CVE-2026-113725 published to NVD
  • 2026-10-22 - Last updated in NVD database

Technical Details for CVE-2026-113725

Vulnerability Analysis

The vulnerability resides in src/virtualenv/activation/bash/activate.sh. Bash expands PS1 in two passes on every prompt redraw. The first pass decodes backslash prompt escapes, converting \\ into \ and \$ into $. The second pass then performs parameter, command, and arithmetic expansion on the result. The original activator applied a single layer of escaping that was sufficient for zsh but insufficient for bash. A single backslash in the environment name survived the first pass and unmasked special characters for the second. An environment name containing $(malicious_command) therefore executed during prompt rendering.

Root Cause

The shared code path treated bash and zsh identically despite different prompt-expansion semantics. The guard if [ -n "${BASH_VERSION-}${ZSH_VERSION-}" ] applied zsh-appropriate escaping to both shells. Bash required double escaping of \, $, and ` to survive both expansion passes, which the script did not perform.

Attack Vector

Exploitation requires local user interaction. A victim must create or activate a virtual environment whose name or --prompt argument contains the injected payload. Attack scenarios include malicious project templates, shared CI configurations that derive environment names from untrusted input, and documentation examples that encourage copy-paste of attacker-controlled names. Once the environment is activated, every subsequent prompt redraw runs the embedded commands in the user context.

bash
     # bash, and zsh under PROMPT_SUBST, re-expand backslashes, dollar signs and backticks in PS1 on every redraw;
     # zsh gets the escaping even without the option, since a user can set it after activation. The guards keep
     # the substitution away from POSIX shells such as dash, which reject it with "Bad substitution"
-    if [ -n "${BASH_VERSION-}${ZSH_VERSION-}" ]; then
+    if [ -n "${BASH_VERSION-}" ]; then
+        # bash first decodes its backslash prompt escapes, turning \\ into \ and \$ into $ (or # for root), and only
+        # then expands the result, so each character needs escaping for both passes
+        _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//\`/\\\`}"

Source: GitHub Commit c3104e0

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

Indicators of Compromise

  • Virtual environment directory names containing $(, backticks, or embedded backslashes before shell metacharacters.
  • activate scripts under */bin/activate where _VIRTUAL_PROMPT contains unescaped command substitution syntax.
  • Unexpected child processes spawned by interactive bash sessions immediately after source activate.

Detection Strategies

  • Audit virtualenv --version across developer workstations and build agents, flagging anything below 21.14.7.
  • Scan source repositories and CI pipelines for virtualenv or python -m venv invocations that pass untrusted strings as the environment name or --prompt value.
  • Review shell history for source or . commands targeting activate scripts in directories with suspicious names.

Monitoring Recommendations

  • Alert on process executions whose parent is bash and whose command line matches content derived from PS1.
  • Track creation of virtual environment directories by non-standard automation accounts.
  • Correlate interactive shell activity with unexpected outbound network connections after environment activation.

How to Mitigate CVE-2026-113725

Immediate Actions Required

  • Upgrade virtualenv to version 21.14.7 or later on all developer machines, build servers, and container images.
  • Inventory existing virtual environments and recreate any whose names contain shell metacharacters.
  • Remove or sanitize --prompt values sourced from untrusted input in automation scripts.

Patch Information

The fix is delivered in pypa/virtualenv release 21.14.7. The patch adds double escaping for \, $, and ` in the bash branch of the activator so that both bash prompt-expansion passes treat the environment name as literal text. Review the GitHub Security Advisory GHSA-vxj4-q4g9-crj7 and the GitHub Release 21.14.7 for full details.

Workarounds

  • Restrict virtual environment names to an allowlist of alphanumeric characters, underscores, and hyphens.
  • Avoid passing user-controlled strings to the --prompt option until the upgrade is deployed.
  • Prefer the standard library venv module where feasible, or manually patch activate.sh with the escaping logic from commit c3104e0.
bash
# Upgrade virtualenv and verify the installed version
python -m pip install --upgrade 'virtualenv>=21.14.7'
virtualenv --version

# Recreate an environment using a sanitized name
SAFE_NAME="$(printf '%s' "$RAW_NAME" | tr -cd 'A-Za-z0-9_-')"
virtualenv "./.venvs/${SAFE_NAME}"

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.