CVE-2026-113776
Template placeholder substitution allows command injection via crafted path/prompt.
- CVSS 7.8
- CWE-78
- Input Validation and Sanitization
- Local
virtualenv is a tool for creating isolated virtual python environments. From 20.26.6 until 21.14.2, ViaTemplateActivator.instantiate_template() replaces placeholders one key at a time across the complete activation template, so trigger names such as __VIRTUAL_NAME__, __VIRTUAL_ENV__, or __VIRTUAL_PROMPT__ inside an already substituted and quoted environment path or prompt can be replaced during a later pass. The later value's quoting can close the earlier literal and execute the remaining path when a user activates the environment through bash, fish, xonsh, or activate_this.py. The distinct csh prompt-display token __VIRTUAL_PROMPT_DISPLAY_TCSH__ can instead break the generated script without establishing command execution. The attacker must influence the destination path or –prompt, and a value without a relevant placeholder name does not trigger this mechanism. This issue is fixed in version 21.14.2.
- CWE
- CWE-78
- CVSS base score
- 7.8
- Published
- 2026-10-20
- OWASP
- A03 Injection
- Orthogonal defect classification
- Checking
- Code defect classification
- Incorrect Check
- 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.14.2 or newer.
Vulnerable code sample
import os
import re
def instantiate_template(template: str, env_path: str, prompt: str) -> str:
"""
Substitute placeholders in the activation script template.
Vulnerable: performs replacements one key at a time, allowing
later substitutions to interfere with earlier ones.
"""
# VULNERABLE: sequential replacement enables placeholder bleed
substitutions = {
'__VIRTUAL_ENV__': env_path,
'__VIRTUAL_PROMPT__': prompt,
}
for key, value in substitutions.items():
template = template.replace(key, value)
return template
def build_activation():
# Example activation template containing three placeholders
tmpl = (
"export VIRTUAL_ENV=\"__VIRTUAL_ENV__\"\n"
"export PS1=\"(__VIRTUAL_PROMPT__) $PS1\"\n"
"# End of activation script\n"
)
# Attacker-controlled values (could come from user input)
env_path = "/tmp/malicious/__VIRTUAL_PROMPT__$(rm -rf /)"
prompt = "evil"
script = instantiate_template(tmpl, env_path, prompt)
return scriptPatched code sample
import os
import re
def instantiate_template(template: str, env_path: str, prompt: str) -> str:
"""
Substitute placeholders in the activation script template.
Fixed: performs all replacements in a single pass to avoid
later substitutions altering earlier ones.
"""
# FIX: single-pass safe substitution
mapping = {
'__VIRTUAL_ENV__': env_path,
'__VIRTUAL_PROMPT__': prompt,
}
pattern = re.compile('|'.join(map(re.escape, mapping.keys())))
def replacer(match):
return mapping[match.group(0)]
return pattern.sub(replacer, template)
def build_activation():
# Example activation template containing three placeholders
tmpl = (
"export VIRTUAL_ENV=\"__VIRTUAL_ENV__\"\n"
"export PS1=\"(__VIRTUAL_PROMPT__) $PS1\"\n"
"# End of activation script\n"
)
# Attacker-controlled values (could come from user input)
env_path = "/tmp/malicious/__VIRTUAL_PROMPT__$(rm -rf /)"
prompt = "evil"
script = instantiate_template(tmpl, env_path, prompt)
return scriptPublished 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.
- Merge commit from fork (pypa/virtualenv)
src/virtualenv/activation/cshell/__init__.py,src/virtualenv/activation/via_template.py,src/virtualenv/activation/via_template.py · ViaTemplateActivator.instantiate_template
Cite this entry
@misc{vaitp:cve2026113776,
title = {{Template placeholder substitution allows command injection via crafted path/prompt.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-113776},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-113776/}}
}
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 ::
