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

CVE-2026-102937: Virtualenv Command Injection Vulnerability

CVE-2026-102937 is a command injection flaw in virtualenv that allows attackers to execute arbitrary commands on Windows systems through malicious prompt values. 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-102937 Overview

CVE-2026-102937 is a command injection vulnerability [CWE-78] in virtualenv, the tool for creating isolated Python environments. Versions prior to 21.7.12 fail to sanitize prompt text before it is written into a Windows activate.bat script. An attacker who controls the --prompt option, the VIRTUALENV_PROMPT environment variable, or the corresponding configuration value can inject a double quote that terminates the cmd.exeset "VAR=value" statement. Following characters are then parsed as executable command syntax. When a user later activates the environment on Windows, the injected commands run with that user's privileges. The issue is fixed in virtualenv version 21.7.12.

Critical Impact

Arbitrary command execution occurs on Windows when a user activates a virtual environment created with an attacker-controlled prompt value.

Affected Products

  • virtualenv versions prior to 21.7.12
  • Windows environments using the generated activate.bat script
  • Python projects that accept externally supplied --prompt or VIRTUALENV_PROMPT values

Discovery Timeline

Technical Details for CVE-2026-102937

Vulnerability Analysis

The flaw resides in the BatchActivator.quote() method in src/virtualenv/activation/batch/__init__.py. The method returns the prompt string unchanged before it is interpolated into the generated activate.bat template. The template writes the value into a cmd.exe statement of the form set "VAR=value". Because cmd.exe parses shell operators inside quoted set values, characters such as &, |, <, >, ^, !, and " retain their meta-syntactic meaning. Injecting a double quote closes the assignment, and the remainder of the string is executed as shell syntax at activation time.

Root Cause

The quote() implementation on the Windows batch activator did not escape or strip cmd.exe control characters. Prompt data flowed directly from user input into a shell script without neutralization, satisfying the classic pattern of OS Command Injection [CWE-78]. The upstream fix introduces a set of neutralized characters and applies collapse_line_boundaries() to strip newlines from the value before it reaches the template.

Attack Vector

Exploitation requires local file generation followed by user interaction (activation). An attacker who can influence project configuration, contribute a pyproject.toml-style setting, publish a project template, or set VIRTUALENV_PROMPT in the target's environment can plant a malicious prompt. When the victim runs the generated activate.bat, the injected commands execute in their session.

python
# Patch excerpt: src/virtualenv/activation/batch/__init__.py
# Source: https://github.com/pypa/virtualenv/commit/d721ff140ce4afdc2a9b76751e4584e25d9fbea6

import logging
import os
from typing import TYPE_CHECKING, Final

from virtualenv.activation.via_template import ViaTemplateActivator
from virtualenv.util.text import collapse_line_boundaries

LOGGER = logging.getLogger(__name__)

# cmd.exe treats these characters as operators even inside a quoted set value.
# `(` and `)` are safe as bare characters; `!` is neutered unconditionally
# because delayed expansion may be enabled in the caller's shell.
_CMD_OPERATORS: Final[tuple[str, ...]] = ("&", "|", "<", ">", "^", "!", '"')

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

Indicators of Compromise

  • Generated activate.bat files containing double quotes, &, |, <, >, ^, or ! inside the set "VIRTUAL_ENV_PROMPT=..." line
  • Unexpected child processes spawned by cmd.exe immediately after a user runs activate.bat
  • VIRTUALENV_PROMPT environment variables containing shell metacharacters in developer workstations or CI runners

Detection Strategies

  • Inventory installed virtualenv versions across developer endpoints and build agents and flag any version below 21.7.12
  • Scan project repositories, pyproject.toml, and CI configuration for --prompt arguments or VIRTUALENV_PROMPT values containing quote or operator characters
  • Statically inspect existing activate.bat files in developer home directories and pipeline caches for malformed set statements

Monitoring Recommendations

  • Alert on cmd.exe invocations of activate.bat that immediately spawn network utilities, powershell.exe, or script interpreters
  • Log environment variable changes involving VIRTUALENV_PROMPT on shared build systems
  • Monitor package installation events for virtualenv downgrades below the fixed release

How to Mitigate CVE-2026-102937

Immediate Actions Required

  • Upgrade virtualenv to version 21.7.12 or later on every Windows workstation, container image, and CI runner
  • Regenerate any existing virtual environments whose prompt values originated from untrusted sources
  • Audit VIRTUALENV_PROMPT and project configuration files across repositories for suspicious characters

Patch Information

The fix is available in virtualenv21.7.12. The patch enumerates the cmd.exe operator set and escapes them within BatchActivator.quote(). See the GitHub Commit Overview, the GitHub Pull Request Discussion, and the GitHub Security Advisory GHSA-x78j-v8h9-3j2q for the complete change set.

Workarounds

  • Avoid passing untrusted values to the --prompt flag when creating environments on Windows
  • Unset VIRTUALENV_PROMPT in shared shells and CI images until upgrading
  • Prefer activate.ps1 (PowerShell) or POSIX activation scripts, which are not affected by this cmd.exe parsing behavior
bash
# Upgrade virtualenv to the patched release
python -m pip install --upgrade "virtualenv>=21.7.12"

# Verify the installed version
python -m virtualenv --version

# Create environments without relying on external prompt input
python -m virtualenv .venv

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.