Summary
A command injection vulnerability in virtualenv's Bash activation script can occur when an attacker-controlled prompt value is copied into the shell prompt without escaping. Under specific Bash settings, later prompt expansion may execute commands as the user who activates the environment.
Affected context
The issue affects virtualenv versions 21.14.9 through 21.14.13 when using the Bash bin/activate script with a prompt value supplied through --prompt. Risk depends on shell behavior: prompt variables and POSIX mode must be disabled during activation, and a later shell action must cause the stored prompt value to be expanded.
Exploit preconditions
- Attack surface: Local Bash environment activation
- Required access: Ability to provide or influence the virtual environment's
--promptvalue and have a user activate that environment - Trigger point: The prompt value is copied into
PS1during activation; subsequent prompt expansion may evaluate it - Why exploitation is possible: The prompt value is not escaped before being stored in
PS1, allowing command substitution to be interpreted when shell settings or behavior later trigger expansion
Why this happens
The activation script places an attacker-controlled prompt value into PS1 without escaping shell expansion characters. When Bash later expands the prompt under applicable settings, command substitution in the value can execute commands. This is an OS command injection flaw mapped to CWE-78, caused by passing untrusted data into a shell-interpreted context.
Potential impact
- Commands may execute with the privileges of the user activating the environment
- The user's files, credentials, or development resources could be accessed or modified
- Malicious changes could affect projects or processes run from the compromised shell
General mitigation guidance
Defensive patterns focus on treating prompt values as untrusted data and preventing their interpretation as shell syntax.
- Escape or safely encode values before placing them in shell-interpreted prompt variables
- Prefer prompt construction mechanisms that keep data separate from executable shell expressions
- Limit who can create or modify environments and their configuration
- Run development tools and shells with only the privileges needed for their tasks
How teams detect issues like this
- Review shell activation scripts for untrusted values assigned to
PS1or other expansion-sensitive variables - Use static analysis to flag unescaped prompt data and command substitution in shell contexts
- Check code review and CI policies for unsafe interpolation of user-controlled values into shell variables
- Monitor environment creation and activation workflows for unexpected changes to prompt configuration

