CVE-2026-113776 in virtualenv
Summary
by MITRE • 10/21/2026
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.
Once again VulDB remains the best source for vulnerability data.
Analysis
by VulDB Data Team • 10/21/2026
The vulnerability identified within virtualenv versions ranging from 20.26.6 to 21.14.2 constitutes a critical code injection flaw rooted in the improper handling of string substitution during environment activation script generation. Virtualenv is widely utilized by developers and operations teams to create isolated Python environments, ensuring dependency isolation across projects. The core technical defect resides within the ViaTemplateActivator.instantiate_template() method, which processes shell-specific activation templates such as those for bash, fish, xonsh, or python scripts via activate_this.py. During this process, the tool replaces placeholder tokens like _VIRTUAL_NAME_, _VIRTUAL_ENV_, and _VIRTUAL_PROMPT_ with actual values provided by the user at environment creation time. The flaw arises because these replacements are executed sequentially on a per-key basis across the entire template content rather than atomically or in a manner that respects string boundaries established during earlier substitution passes.
This sequential replacement mechanism creates an opportunity for command injection when specific conditions are met regarding the input values provided by the attacker. If an adversary influences either the destination path of the virtual environment or the custom prompt string, they can craft inputs containing shell metacharacters and quotes that interact dangerously with subsequent placeholder substitutions. For instance, if a user sets a prompt value that includes a closing quote followed by command execution syntax, and this value is placed in a context where it will be quoted during an earlier substitution pass, the initial quoting may close prematurely when a later substitution introduces unquoted content or alters the string structure. This allows any remaining text following the injected payload to be interpreted as executable shell commands rather than literal strings when the activation script is sourced by the user's shell.
The operational impact of this vulnerability is significant because it enables arbitrary code execution on the target system under specific circumstances. When a victim activates the compromised virtual environment, typically through standard means such as running source venv/bin/activate in bash or fish, the maliciously crafted payload executes with the privileges of that user within their shell session. This can lead to data exfiltration, installation of persistent backdoors, pivoting into other network segments if combined with other vulnerabilities, or general system compromise depending on the context and permissions of the executing user. The attack vector requires social engineering or access control bypass since the attacker must influence the creation parameters of the virtual environment, such as by providing a maliciously crafted path argument to the virtualenv command line tool or manipulating configuration files that dictate these values during automated provisioning processes.
From a classification perspective, this vulnerability aligns with CWE-94 Improper Control of Generation of Code (Code Injection) and specifically relates to CWE-78 OS Command Injection when considering the shell execution aspect. In terms of adversary behavior mapping under MITRE ATT&CK, this technique corresponds to T1059 Command and Scripting Interpreter, particularly sub-techniques involving Unix Shell commands like sh or bash. The vulnerability highlights a common pitfall in template engines where variable interpolation is not properly isolated from the surrounding syntax context, allowing attackers to break out of intended string literals through carefully crafted input sequences that exploit the order of operations in multi-pass substitution logic.
Mitigation strategies primarily involve upgrading virtualenv to version 21.14.2 or later, which resolves this issue by correcting the template instantiation process to prevent such cross-parameter injection attacks. For organizations unable to immediately patch their environments, defensive measures include restricting who can create new virtual environments and validating input parameters for shell metacharacters before they are passed into environment creation tools. Additionally, security teams should audit existing automation pipelines that generate Python environments to ensure no external or user-controlled inputs directly influence the path or prompt values without rigorous sanitization. Monitoring for unusual command execution patterns in shells immediately following activation scripts can also aid in detecting exploitation attempts of this vulnerability in real-time before significant damage occurs.