/

CVE-2026-102937

Severity:

HIGH RISK

(7.8)

OS Command Injection (CWE-78) in virtualenv BatchActivator

CVE-2026-102937

Analyzed

Vulnerability type

Category:

OS Command Injection

CWE:

CWE-78

Impact:

Arbitrary command execution in the activating user's security context

Severity:

HIGH RISK

(7.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

virtualenv can allow command injection in generated Windows activation scripts when prompt text is inserted into a batch assignment without safely handling double quotes. If an attacker can influence the prompt value, commands may run with the privileges of a user who activates the environment.

Affected context

The issue affects virtualenv's Windows batch activation path. It arises when prompt text supplied through --prompt, VIRTUALENV_PROMPT, or the corresponding configuration value is included in an activate.bat assignment without being safely handled. Risk depends on whether an attacker can influence that value and a user activates the generated environment.

Exploit preconditions

  • Attack surface: Windows batch activation scripts generated by virtualenv
  • Required access: Ability to influence the prompt through a command-line option, environment variable, or configuration
  • Trigger point: A user activates the generated environment
  • Why exploitation is possible: A double quote in the prompt can close the batch assignment, allowing following command-interpreter operators to be treated as executable syntax

Why this happens

The prompt value is returned unchanged by BatchActivator.quote() and then inserted into a cmd.exe set "VAR=value" statement. Because the value is not safely encoded for the batch command context, quote characters can alter the statement's boundaries and expose subsequent text to command interpretation. This is OS command injection, mapped to CWE-78.

Potential impact

  • Commands may execute with the privileges of the user activating the environment
  • The user's files or accessible resources could be modified or disclosed
  • Additional software or scripts available to that user could be affected

General mitigation guidance

Defensive approaches include safely encoding values for the specific Windows batch command context or avoiding direct interpolation into shell syntax. Treat prompt values and configuration as untrusted, prefer mechanisms that do not invoke a command interpreter when passing data, and limit the privileges of processes that activate environments. Keep configuration sources controlled and avoid relying on validation alone where context-aware escaping is needed.

How teams detect issues like this

Review batch-script generation for externally influenced values inserted into command statements, especially assignments and quoting boundaries. Static analysis and code review can look for unescaped interpolation into shell or batch syntax. Tests and policy checks can verify that generated scripts handle quotes and command metacharacters as data rather than executable syntax.

Sources

SourceLink
github.comgithub.com/pypa/virtualenv/commit/d721ff140ce4afdc2a9b76751e4584e25d9fbea6
github.comgithub.com/pypa/virtualenv/pull/3250
github.comgithub.com/pypa/virtualenv/releases/tag/21.7.12
github.comgithub.com/pypa/virtualenv/security/advisories/GHSA-x78j-v8h9-3j2q

Frequently asked

questions

It concerns virtualenv's Windows batch activation path when an attacker-influenced prompt is included in the generated activation script.

The attacker must be able to influence the prompt through an available input or configuration source. A user must then activate the affected environment.

Encode values for the exact batch-command context, or avoid placing untrusted values in command-interpreter syntax.

Treat configuration and environment values as untrusted, review generated shell commands for unsafe interpolation, and test that special characters remain data.

Find out what's already
exploitable in your codebase.