VAITP Dataset

← Back to the dataset

CVE-2026-102937

Command injection via crafted prompt in virtualenv before 21.7.12; exec cmds

  • CVSS 7.3
  • CWE-78
  • Input Validation and Sanitization
  • Local

virtualenv is a tool for creating isolated virtual python environments. Prior to 21.7.12, BatchActivator.quote() returns prompt text unchanged before activate.bat inserts it into a cmd.exe set "VAR=value" statement. An attacker who influences –prompt, VIRTUALENV_PROMPT, or the corresponding configuration value can include a double quote that closes the assignment and leaves following cmd.exe operators as executable syntax. When a user activates the generated Windows environment, the injected commands run with that user's privileges. This issue is fixed in version 21.7.12.

CVSS base score
7.3
Published
2026-09-29
OWASP
A03 Injection
Orthogonal defect classification
Assignment
Code defect classification
Incorrect Assignment
Category
Input Validation and Sanitization
Subcategory
Command Injection
Accessibility scope
Local
Impact
Arbitrary Code Execution
Affected component
virtualenv
Fixed by upgrading
Yes

Solution

Upgrade virtualenv to version 21.7.12 or newer.

Vulnerable code sample

import os

class BatchActivator:
    def __init__(self, env_path, prompt):
        self.env_path = env_path
        self.prompt = prompt

    # VULNERABLE: raw prompt inserted into cmd set statement
    def generate_activate_script(self):
        lines = []
        # The vulnerable line: prompt is not sanitized
        lines.append(f'set "PROMPT={self.prompt}"')
        activate_path = os.path.join(self.env_path, "Scripts", "activate.bat")
        with open(activate_path, "w", encoding="utf-8") as f:
            f.write("\r\n".join(lines))

Patched code sample

import os

class BatchActivator:
    def __init__(self, env_path, prompt):
        self.env_path = env_path
        self.prompt = prompt

    # FIX: escape double quotes in prompt before embedding in cmd set statement
    def generate_activate_script(self):
        lines = []
        safe_prompt = self.prompt.replace('"', r'\"')
        lines.append(f'set "PROMPT={safe_prompt}"')
        activate_path = os.path.join(self.env_path, "Scripts", "activate.bat")
        with open(activate_path, "w", encoding="utf-8") as f:
            f.write("\r\n".join(lines))

Published fix

Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.

Cite this entry

@misc{vaitp:cve2026102937,
  title        = {{Command injection via crafted prompt in virtualenv before 21.7.12; exec cmds}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2026},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2026-102937},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-102937/}}
}

Download this entry as JSON Download the whole dataset

Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.