/

CVE-2026-113776

Severity:

HIGH RISK

(7.8)

Command Injection (CWE-78) in virtualenv Activation

CVE-2026-113776

Undergoing Analysis

Vulnerability type

Category:

Command Injection

CWE:

CWE-78, CWE-94

Impact:

Command Execution

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

A command injection vulnerability in virtualenv can cause attacker-influenced environment paths or prompts to be interpreted as shell commands when activation scripts are generated and later executed.

The issue becomes risky when an attacker can control the destination path or --prompt value and a user activates the affected environment through a supported shell or activation mechanism.

A command injection vulnerability in virtualenv can cause attacker-influenced environment paths or prompts to be interpreted as shell commands when activation scripts are generated and later executed.

The issue becomes risky when an attacker can control the destination path or --prompt value and a user activates the affected environment through a supported shell or activation mechanism.

Affected context

The vulnerability affects virtualenv releases from 20.26.6 through versions before the corrective release 21.14.2 when ViaTemplateActivator.instantiate_template() processes activation templates.

It requires attacker influence over the virtual environment destination path or the --prompt value. The risk is present when generated activation content is subsequently used by bash, fish, xonsh, or activate_this.py. In the csh-specific case, a related placeholder may corrupt the generated script without providing command execution.

The vulnerability affects virtualenv releases from 20.26.6 through versions before the corrective release 21.14.2 when ViaTemplateActivator.instantiate_template() processes activation templates.

It requires attacker influence over the virtual environment destination path or the --prompt value. The risk is present when generated activation content is subsequently used by bash, fish, xonsh, or activate_this.py. In the csh-specific case, a related placeholder may corrupt the generated script without providing command execution.

Exploit preconditions

  • Attack surface: Virtual environment creation and activation-template generation
  • Required access: Ability to influence the destination path or --prompt value
  • Trigger point: A user activates the resulting environment through bash, fish, xonsh, or activate_this.py
  • Why exploitation is possible: Template placeholders are replaced sequentially across already-substituted content, allowing later substitution and quoting behavior to alter an earlier literal and cause generated activation content to be interpreted as commands
  • Attack surface: Virtual environment creation and activation-template generation
  • Required access: Ability to influence the destination path or --prompt value
  • Trigger point: A user activates the resulting environment through bash, fish, xonsh, or activate_this.py
  • Why exploitation is possible: Template placeholders are replaced sequentially across already-substituted content, allowing later substitution and quoting behavior to alter an earlier literal and cause generated activation content to be interpreted as commands

Why this happens

The underlying bug is an unsafe multi-pass template substitution design. ViaTemplateActivator.instantiate_template() replaces placeholder names one at a time across the complete activation template, including text that was introduced by an earlier replacement.

If attacker-controlled path or prompt data contains a recognized placeholder name, a later substitution can modify previously quoted content. The resulting quoting boundary may cause activation scripts to interpret part of the generated value as executable shell syntax. This behavior maps primarily to CWE-78: Improper Neutralization of Special Elements used in an OS Command, with a related CWE-94: Improper Control of Generation of Code concern because generated activation code is not safely separated from data.

The underlying bug is an unsafe multi-pass template substitution design. ViaTemplateActivator.instantiate_template() replaces placeholder names one at a time across the complete activation template, including text that was introduced by an earlier replacement.

If attacker-controlled path or prompt data contains a recognized placeholder name, a later substitution can modify previously quoted content. The resulting quoting boundary may cause activation scripts to interpret part of the generated value as executable shell syntax. This behavior maps primarily to CWE-78: Improper Neutralization of Special Elements used in an OS Command, with a related CWE-94: Improper Control of Generation of Code concern because generated activation code is not safely separated from data.

Potential impact

  • An attacker could execute commands with the privileges of the user activating the environment.
  • Local credentials, source code, environment variables, or other accessible files could be exposed.
  • Development or build workflows could be modified or compromised.
  • A compromised user session could be used for further lateral movement.
  • The csh-specific placeholder issue could render an activation script unusable without establishing command execution.
  • An attacker could execute commands with the privileges of the user activating the environment.
  • Local credentials, source code, environment variables, or other accessible files could be exposed.
  • Development or build workflows could be modified or compromised.
  • A compromised user session could be used for further lateral movement.
  • The csh-specific placeholder issue could render an activation script unusable without establishing command execution.

General mitigation guidance

Mitigation generally focuses on treating paths and prompts as data rather than template syntax.

Common defensive patterns include:

  • Replacing sequential global substitution with a single-pass, context-aware rendering process.
  • Escaping or encoding attacker-influenced values for the specific shell or script language in which they will be emitted.
  • Using structured template rendering that prevents substituted values from being interpreted as new template tokens.
  • Reducing trust in destination paths and prompt values supplied by untrusted users or automation.
  • Limiting activation and environment-generation operations to appropriately privileged accounts and isolated workspaces.
  • Testing generated activation scripts across supported shells with adversarial placeholder and quoting cases.

Mitigation generally focuses on treating paths and prompts as data rather than template syntax.

Common defensive patterns include:

  • Replacing sequential global substitution with a single-pass, context-aware rendering process.
  • Escaping or encoding attacker-influenced values for the specific shell or script language in which they will be emitted.
  • Using structured template rendering that prevents substituted values from being interpreted as new template tokens.
  • Reducing trust in destination paths and prompt values supplied by untrusted users or automation.
  • Limiting activation and environment-generation operations to appropriately privileged accounts and isolated workspaces.
  • Testing generated activation scripts across supported shells with adversarial placeholder and quoting cases.

How teams detect issues like this

Detection can include:

  • Static analysis for repeated global substitutions over already-rendered templates.
  • Code review checks for user-controlled paths or prompts inserted into shell, Python, or other executable script content.
  • Tests that verify substituted values cannot introduce new template tokens or alter quoting boundaries.
  • Policy enforcement requiring shell-specific escaping and single-pass template rendering.
  • Monitoring for unexpected commands launched during environment activation and unusual access by activation processes.

Automated security review tools may help identify dangerous string-replacement patterns, generated-code flows, and missing output-context escaping.

Detection can include:

  • Static analysis for repeated global substitutions over already-rendered templates.
  • Code review checks for user-controlled paths or prompts inserted into shell, Python, or other executable script content.
  • Tests that verify substituted values cannot introduce new template tokens or alter quoting boundaries.
  • Policy enforcement requiring shell-specific escaping and single-pass template rendering.
  • Monitoring for unexpected commands launched during environment activation and unusual access by activation processes.

Automated security review tools may help identify dangerous string-replacement patterns, generated-code flows, and missing output-context escaping.

Sources

SourceLink
github.comgithub.com/pypa/virtualenv/commit/602b26623a724827ff171bf11fef4ad186d01f74
github.comgithub.com/pypa/virtualenv/releases/tag/21.14.2
github.comgithub.com/pypa/virtualenv/security/advisories/GHSA-8rjx-v5ww-45pp

Frequently asked

questions

Not by itself. Exploitation generally requires a way to influence the environment destination path or --prompt, followed by activation of the resulting environment by a user or process.

No. The attacker needs control over the relevant input value, but command execution occurs in the security context of whoever activates the generated environment.

Use single-pass, context-aware template rendering and shell-specific escaping so substituted values remain data and cannot become new template expressions or executable syntax.

Treat paths and prompts as untrusted input, test generated scripts against placeholder and quoting collisions, restrict who can create or activate environments, and apply static analysis to generated-code paths.

Not by itself. Exploitation generally requires a way to influence the environment destination path or --prompt, followed by activation of the resulting environment by a user or process.

No. The attacker needs control over the relevant input value, but command execution occurs in the security context of whoever activates the generated environment.

Use single-pass, context-aware template rendering and shell-specific escaping so substituted values remain data and cannot become new template expressions or executable syntax.

Treat paths and prompts as untrusted input, test generated scripts against placeholder and quoting collisions, restrict who can create or activate environments, and apply static analysis to generated-code paths.

Find out what's already
exploitable in your codebase.