/

CVE-2026-113726

Severity:

HIGH RISK

(7.8)

Command Injection (CWE-78) in virtualenv zsh Prompt

CVE-2026-113726

Awaiting Analysis

Vulnerability type

Category:

Command Injection

CWE:

CWE-78, CWE-116

Impact:

Command Execution in the User's Shell

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's shell activation script can cause attacker-influenced prompt values to be evaluated as shell syntax in zsh.

When zsh uses PROMPT_SUBST, a crafted environment directory, prompt option, or VIRTUALENV_PROMPT value may execute commands whenever the user's prompt is rendered.

A command injection vulnerability in virtualenv's shell activation script can cause attacker-influenced prompt values to be evaluated as shell syntax in zsh.

When zsh uses PROMPT_SUBST, a crafted environment directory, prompt option, or VIRTUALENV_PROMPT value may execute commands whenever the user's prompt is rendered.

Affected context

The issue occurs in virtualenv activation scripts used by zsh when prompt substitution is enabled. It requires an attacker-influenced environment name or prompt value containing command, parameter, or arithmetic expansion syntax. Bash and zsh sessions with PROMPT_SUBST disabled are not affected by this specific mechanism, and percent signs alone do not execute commands.

The issue occurs in virtualenv activation scripts used by zsh when prompt substitution is enabled. It requires an attacker-influenced environment name or prompt value containing command, parameter, or arithmetic expansion syntax. Bash and zsh sessions with PROMPT_SUBST disabled are not affected by this specific mechanism, and percent signs alone do not execute commands.

Exploit preconditions

  • Attack surface: The generated shell activation script and the prompt value assigned to PS1
  • Required access: Ability to influence the virtual environment directory name, --prompt value, or VIRTUALENV_PROMPT
  • Trigger point: Rendering the interactive zsh prompt after environment activation
  • Required shell behavior: zsh must have PROMPT_SUBST enabled
  • Why exploitation is possible: The affected script can leave expansion syntax unescaped before assigning attacker-influenced data to the prompt
  • Attack surface: The generated shell activation script and the prompt value assigned to PS1
  • Required access: Ability to influence the virtual environment directory name, --prompt value, or VIRTUALENV_PROMPT
  • Trigger point: Rendering the interactive zsh prompt after environment activation
  • Required shell behavior: zsh must have PROMPT_SUBST enabled
  • Why exploitation is possible: The affected script can leave expansion syntax unescaped before assigning attacker-influenced data to the prompt

Why this happens

The underlying bug is insufficient context-aware escaping of untrusted text before it is assigned to a shell prompt variable. In the affected zsh path, escaping is conditional on BASH_VERSION, so zsh may receive raw command, parameter, or arithmetic expansion syntax. When PROMPT_SUBST is enabled, zsh evaluates that syntax while drawing the prompt, mapping the issue primarily to CWE-78: Improper Neutralization of Special Elements used in an OS Command and secondarily to CWE-116: Improper Encoding or Escaping of Output.

The underlying bug is insufficient context-aware escaping of untrusted text before it is assigned to a shell prompt variable. In the affected zsh path, escaping is conditional on BASH_VERSION, so zsh may receive raw command, parameter, or arithmetic expansion syntax. When PROMPT_SUBST is enabled, zsh evaluates that syntax while drawing the prompt, mapping the issue primarily to CWE-78: Improper Neutralization of Special Elements used in an OS Command and secondarily to CWE-116: Improper Encoding or Escaping of Output.

Potential impact

  • Commands may execute with the privileges of the affected user
  • Shell credentials, tokens, or environment data could be exposed
  • User files or development workspaces could be modified
  • Subsequent commands may be influenced through shell state changes
  • Commands may execute with the privileges of the affected user
  • Shell credentials, tokens, or environment data could be exposed
  • User files or development workspaces could be modified
  • Subsequent commands may be influenced through shell state changes

General mitigation guidance

Mitigation generally focuses on treating environment names and prompt values as untrusted data across every supported shell.

Common defensive patterns include:

  • Apply shell- and context-specific escaping unconditionally for zsh and bash paths
  • Prefer fixed, non-interpreted prompt templates over embedding raw user-controlled values
  • Disable prompt substitution where it is not required
  • Restrict who can create or rename environment directories used by shared workflows
  • Run development tooling with least privilege and avoid unnecessary access to sensitive data
  • Use maintained virtualenv releases that contain the relevant safety correction

Mitigation generally focuses on treating environment names and prompt values as untrusted data across every supported shell.

Common defensive patterns include:

  • Apply shell- and context-specific escaping unconditionally for zsh and bash paths
  • Prefer fixed, non-interpreted prompt templates over embedding raw user-controlled values
  • Disable prompt substitution where it is not required
  • Restrict who can create or rename environment directories used by shared workflows
  • Run development tooling with least privilege and avoid unnecessary access to sensitive data
  • Use maintained virtualenv releases that contain the relevant safety correction

How teams detect issues like this

Organizations can look for:

  • Static analysis rules identifying raw environment names or prompt values assigned to shell prompt variables
  • Code review signals involving conditional escaping based on shell-specific variables
  • Tests that exercise generated activation scripts under zsh with PROMPT_SUBST enabled
  • Policy checks requiring context-appropriate escaping for generated shell code
  • Runtime monitoring for unexpected child processes launched by interactive shell sessions after environment activation

Organizations can look for:

  • Static analysis rules identifying raw environment names or prompt values assigned to shell prompt variables
  • Code review signals involving conditional escaping based on shell-specific variables
  • Tests that exercise generated activation scripts under zsh with PROMPT_SUBST enabled
  • Policy checks requiring context-appropriate escaping for generated shell code
  • Runtime monitoring for unexpected child processes launched by interactive shell sessions after environment activation

Sources

SourceLink
github.comgithub.com/pypa/virtualenv/commit/5b915367da82bd024b2a0d28d2f98007034b4aa2
github.comgithub.com/pypa/virtualenv/releases/tag/21.14.4
github.comgithub.com/pypa/virtualenv/security/advisories/GHSA-5vjq-rrrf-7h2q

Frequently asked

questions

It is generally not a direct network attack. Exploitation typically requires the attacker to influence a virtual environment name or prompt-related value that a victim later activates in zsh.

The attacker needs a path to control the environment directory name, the --prompt option, or the VIRTUALENV_PROMPT value. The victim must then use the affected activation script in zsh with PROMPT_SUBST enabled.

Use a maintained virtualenv release containing the correction and ensure generated prompt values are escaped for the target shell before assignment. Disabling prompt substitution can also reduce exposure where compatible with the workflow.

Treat all generated shell fragments and prompt values as code-generation boundaries, apply shell-specific escaping, test across supported shells and modes, and use static analysis or policy checks to detect raw interpolation.

It is generally not a direct network attack. Exploitation typically requires the attacker to influence a virtual environment name or prompt-related value that a victim later activates in zsh.

The attacker needs a path to control the environment directory name, the --prompt option, or the VIRTUALENV_PROMPT value. The victim must then use the affected activation script in zsh with PROMPT_SUBST enabled.

Use a maintained virtualenv release containing the correction and ensure generated prompt values are escaped for the target shell before assignment. Disabling prompt substitution can also reduce exposure where compatible with the workflow.

Treat all generated shell fragments and prompt values as code-generation boundaries, apply shell-specific escaping, test across supported shells and modes, and use static analysis or policy checks to detect raw interpolation.

Find out what's already
exploitable in your codebase.