CVE-2026-102938
Prompt injection via crafted –prompt allows arbitrary pyvenv.cfg keys, enabling base interpreter hijack.
- CVSS 5.8
- CWE-93
- Input Validation and Sanitization
- Local
virtualenv is a tool for creating isolated virtual python environments. Prior to 21.7.11, PyEnvCfg.write() writes prompt values verbatim to the line-oriented pyvenv.cfg format while PyEnvCfg._read_values() parses the file with str.splitlines() and accepts the last value for duplicate keys. An attacker who influences –prompt, VIRTUALENV_PROMPT, or configuration input can insert a recognized line boundary and additional keys, including home, causing consumers to use an attacker-selected base interpreter or corrupted environment metadata. The security impact requires prompt input from outside the operator's trust boundary; directly supplied prompt content primarily corrupts the operator's own environment. This issue is fixed in version 21.7.11.
- CWE
- CWE-93
- CVSS base score
- 5.8
- Published
- 2026-09-29
- OWASP
- A03 Injection
- Orthogonal defect classification
- Interface
- Code defect classification
- Missing Check
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Local
- Impact
- Arbitrary Code Execution
- Affected component
- virtualenv
- Fixed by upgrading
- Yes
Solution
Upgrade virtualenv to ≥ 21.7.11.
Vulnerable code sample
import os
class PyEnvCfg:
def __init__(self, home, prompt):
self.home = home
self.prompt = prompt
def write(self, path):
# VULNERABLE: writes prompt verbatim allowing line breaks
with open(path, "w", encoding="utf-8") as f:
f.write(f"home = {self.home}\n")
f.write(f"prompt = {self.prompt}\n")
def _read_values(self, path):
values = {}
with open(path, "r", encoding="utf-8") as f:
for line in f.read().splitlines():
if "=" not in line:
continue
key, val = line.split("=", 1)
values[key.strip()] = val.strip()
return values
def load(self, path):
vals = self._read_values(path)
self.home = vals.get("home", self.home)
self.prompt = vals.get("prompt", self.prompt)Patched code sample
import os
class PyEnvCfg:
def __init__(self, home, prompt):
self.home = home
self.prompt = prompt
def write(self, path):
# FIX: sanitize prompt to remove line breaks
safe_prompt = self.prompt.replace("\n", " ").replace("\r", " ")
with open(path, "w", encoding="utf-8") as f:
f.write(f"home = {self.home}\n")
f.write(f"prompt = {safe_prompt}\n")
def _read_values(self, path):
values = {}
with open(path, "r", encoding="utf-8") as f:
for line in f.read().splitlines():
if "=" not in line:
continue
key, val = line.split("=", 1)
values[key.strip()] = val.strip()
return values
def load(self, path):
vals = self._read_values(path)
self.home = vals.get("home", self.home)
self.prompt = vals.get("prompt", self.prompt)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.
- 🐛 fix(create): keep pyvenv.cfg values on a single line (#3247) (pypa/virtualenv)
src/virtualenv/create/pyenv_cfg.py,src/virtualenv/create/pyenv_cfg.py · PyEnvCfg.write
Cite this entry
@misc{vaitp:cve2026102938,
title = {{Prompt injection via crafted --prompt allows arbitrary pyvenv.cfg keys, enabling base interpreter hijack.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-102938},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-102938/}}
}
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 ::
