CVE-2024-9287 Overview
A command injection vulnerability has been discovered in the CPython venv module and CLI where path names provided when creating a virtual environment were not quoted properly. This allows an attacker who controls the virtual environment creation process to inject arbitrary commands into virtual environment activation scripts (e.g., source venv/bin/activate). When a user subsequently activates the malicious virtual environment, the injected commands execute with the user's privileges.
Critical Impact
Attacker-controlled virtual environments can execute arbitrary commands when activated, potentially leading to code execution on developer workstations or CI/CD systems.
Affected Products
- Python (multiple versions prior to patched releases)
- Python 3.14.0 alpha1
- Systems using CPython's venv module for virtual environment management
Discovery Timeline
- October 22, 2024 - CVE-2024-9287 published to NVD
- November 3, 2025 - Last updated in NVD database
Technical Details for CVE-2024-9287
Vulnerability Analysis
This vulnerability stems from improper handling of path names within the CPython venv module. When a virtual environment is created using a path that contains shell metacharacters or special characters, these characters are not properly escaped or quoted in the generated activation scripts. The activation scripts (activate, activate.csh, activate.fish, etc.) are shell scripts that set up environment variables and modify the PATH to use the virtual environment's Python interpreter.
The vulnerability specifically affects scenarios where an attacker can control or influence the directory path used to create a virtual environment. This is particularly relevant in scenarios involving:
- Downloading and extracting projects from untrusted sources
- Automated CI/CD pipelines processing external repositories
- Development environments where paths may be influenced by user input
Importantly, virtual environments that are used without activation (e.g., directly invoking ./venv/bin/python) are not affected by this vulnerability.
Root Cause
The root cause is classified under CWE-428 (Unquoted Search Path or Element) and CWE-77 (Command Injection). The venv module failed to properly quote or escape the virtual environment path when writing it into the activation shell scripts. This creates an opportunity for shell command injection when the path contains characters with special meaning to the shell, such as backticks, semicolons, or $() constructs.
Attack Vector
The attack requires local access and involves creating a maliciously crafted virtual environment with a specially constructed path name. When an unsuspecting user activates this virtual environment using the standard source venv/bin/activate command, the injected commands execute in the context of the user's shell session.
Attack scenarios include:
- An attacker providing a malicious project repository with a pre-created virtual environment
- Supply chain attacks where build scripts create virtual environments using attacker-influenced paths
- Shared development environments where one user can influence paths used by others
The attack requires some level of privilege to create the malicious virtual environment and depends on user interaction to activate it.
Detection Methods for CVE-2024-9287
Indicators of Compromise
- Unusual characters in virtual environment directory paths, particularly shell metacharacters like backticks, $(), semicolons, or pipes
- Activation scripts (activate, activate.csh, activate.fish) containing unexpected command sequences
- Unexpected process spawning when activating virtual environments
- Virtual environment paths containing encoded or obfuscated shell commands
Detection Strategies
- Monitor file system events for virtual environment creation in directories with suspicious path names
- Implement static analysis of activation scripts before sourcing them to detect injected commands
- Review virtual environment paths in repositories and CI/CD pipelines for shell metacharacters
- Use endpoint detection to identify unusual process trees originating from shell activation scripts
Monitoring Recommendations
- Enable logging for shell script execution in development and build environments
- Monitor for process creation events following virtual environment activation
- Implement code review policies for any committed virtual environment directories
- Configure SentinelOne to alert on suspicious command execution patterns from Python-related directories
How to Mitigate CVE-2024-9287
Immediate Actions Required
- Upgrade Python to a patched version that properly quotes path names in activation scripts
- Audit existing virtual environments, especially those from untrusted sources, for suspicious activation scripts
- Avoid activating virtual environments from untrusted projects; instead, invoke the interpreter directly using ./venv/bin/python
- Review CI/CD pipelines to ensure virtual environment paths are controlled and validated
Patch Information
The Python Software Foundation has released patches across multiple Python version branches. The fix ensures proper quoting of path names in virtual environment activation scripts. Relevant commits include:
- GitHub Commit 633555735
- GitHub Commit 8450b248
- GitHub Commit 9286ab3a
- GitHub Commit ae961ae9
- GitHub Commit d48cc82e
- GitHub Commit e52095a0
For additional details, see the Python Security Announcement and GitHub Pull Request #124712.
Linux distributions have also released updates, including Debian LTS announcements for November and December 2024.
Workarounds
- Use direct Python interpreter invocation (./venv/bin/python script.py) instead of activating virtual environments from untrusted sources
- Manually inspect activation scripts before sourcing them to verify they contain no injected commands
- Create virtual environments only in trusted, controlled directory paths without special characters
- Implement repository policies to prevent committing virtual environment directories
# Safe usage without activation
# Instead of: source venv/bin/activate && python script.py
# Use direct invocation:
./venv/bin/python script.py
# Verify activation script contents before use
cat venv/bin/activate | grep -E '[\`\$\(\);|&]'
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.


