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

CVE-2026-113722: virtualenv RCE Vulnerability

CVE-2026-113722 is a remote code execution flaw in virtualenv that allows attackers to execute commands when users run generated launchers with spaces in interpreter paths. This post explains its impact, affected versions, and mitigation steps.

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

CVE-2026-113722 is a command injection vulnerability in virtualenv, the widely used tool for creating isolated Python environments. Versions prior to 21.14.9 pass incompletely quoted interpreter paths to distlib's ScriptMaker when generating POSIX console scripts. When the interpreter path contains a space or produces a shebang longer than 127 bytes, distlib emits a /bin/sh wrapper whose double-quoted interpreter path still expands command substitutions and backticks. An attacker who influences the environment destination can execute commands with the user's privileges when the user later runs a generated launcher.

Critical Impact

Attackers who control the virtual environment path can inject shell commands into generated console scripts, achieving code execution under the user's account whenever the launcher is invoked.

Affected Products

  • virtualenv versions prior to 21.14.9
  • Environments seeded by affected virtualenv releases on POSIX systems
  • pip installations using the vendored distlib (unchanged by the virtualenv patch)

Discovery Timeline

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

Technical Details for CVE-2026-113722

Vulnerability Analysis

The flaw sits in the console-script generation path used when virtualenv seeds a new environment with pip, setuptools, and related entry points. On POSIX systems, when the Python interpreter path contains a space, tab, or produces a shebang exceeding 127 bytes (the kernel's #! length limit), distlib falls back to emitting a /bin/sh wrapper. The interpreter path is embedded inside double quotes, which in POSIX shell still permit command substitution via backticks and $(...) syntax. The weakness is categorized as CWE-78: Improper Neutralization of Special Elements used in an OS Command.

Root Cause

ScriptMakerCustom in virtualenv and pip's own script generator pass the interpreter path to distlib's ScriptMaker without sufficient quoting or escaping. When distlib writes the shell wrapper, it does not strip or neutralize shell metacharacters within the quoted path. Any backtick or $(...) sequence in the path is evaluated by /bin/sh at launcher execution time rather than treated as literal text.

Attack Vector

Exploitation requires an attacker to influence the virtual environment's destination directory, for example through a shared build system, CI runner path controlled by a pull request, or a predictable temporary directory. Environment creation and activation do not trigger the payload. Execution occurs when the user later runs a generated console script such as pip, pytest, or any entry point placed in bin/. User interaction is required, but the resulting shell runs with the invoking user's privileges.

text
# Patch note from docs/changelog/3417.bugfix.rst
Preserve spaces, quotes, and backslashes in interpreter paths when pip console
scripts need a POSIX shell launcher.
Paths containing tabs also use the shell launcher so the kernel does not split
the interpreter name.

Apply the same launcher quoting after pip seeding and refresh the installed
file records. Later independent pip installs or upgrades can overwrite these
launchers; recreate affected environments after upgrading virtualenv.

Source: GitHub commit 2519941

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

Indicators of Compromise

  • Console scripts in a virtual environment's bin/ directory beginning with #!/bin/sh rather than a direct Python shebang, especially where the interpreter path contains spaces or backtick characters.
  • Unexpected child processes spawned from pip, pytest, or other entry-point launchers that do not match the expected Python invocation.
  • Virtual environments created in attacker-influenced paths such as world-writable directories or CI workspaces named from untrusted input.

Detection Strategies

  • Scan bin/ directories of existing virtual environments and flag launchers whose embedded interpreter path contains shell metacharacters such as `, $(, or unescaped quotes.
  • Audit virtualenv package versions across build hosts, developer workstations, and container images; alert on any version below 21.14.9.
  • Monitor process-execution telemetry for /bin/sh wrappers launched from Python virtual environment directories that then spawn non-Python children.

Monitoring Recommendations

  • Log and review creation of virtual environments in shared or multi-tenant systems, correlating the destination path with the invoking user.
  • Track pip install and pip install --upgrade operations against existing environments, since these can regenerate affected launchers using the unpatched vendored distlib.
  • Capture file-integrity events on bin/ entry points inside long-lived virtual environments to detect launcher rewrites.

How to Mitigate CVE-2026-113722

Immediate Actions Required

  • Upgrade virtualenv to version 21.14.9 or later on all build systems, developer machines, and base container images.
  • Regenerate every virtual environment created with an earlier version; the upgrade alone does not repair existing launchers.
  • Review and restrict who can control virtual environment destination paths, especially in CI/CD pipelines and shared infrastructure.

Patch Information

The fix is released in virtualenv21.14.9. See the GitHub Release 21.14.9, Pull Request #3417, and the GHSA-c978-59m8-c77v security advisory for full details. Because pip ships its own vendored copy of distlib which is unchanged, a later independent pip install or upgrade can reintroduce an affected launcher. Recreate affected environments after upgrading.

Workarounds

  • Create virtual environments only in paths that contain no spaces, tabs, quotes, backticks, or other shell metacharacters, and that stay below the kernel shebang length limit.
  • Avoid installing virtualenv or seeding environments into attacker-controlled directories; prefer short, dedicated paths such as /opt/venvs/<name>.
  • After any pip install or pip install --upgrade against a long-lived environment, recreate the environment from scratch with patched virtualenv.
bash
# Upgrade virtualenv and recreate affected environments
python -m pip install --upgrade 'virtualenv>=21.14.9'

# Remove and recreate an existing environment to regenerate launchers
rm -rf /path/to/venv
python -m virtualenv /path/to/venv

# Verify no shell-wrapper launchers remain with embedded metacharacters
grep -lE '^#!/bin/sh' /path/to/venv/bin/* 2>/dev/null \
  | xargs -r grep -lE '[`$]'

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.