CVE-2022-21668
Pipenv prior to 2022.1.8 allows remote code execution via malicious requirements files
- CVSS 8.6
- CWE-190
- Input Validation and Sanitization
- Remote
pipenv is a Python development workflow tool. Starting with version 2018.10.9 and prior to version 2022.1.8, a flaw in pipenv's parsing of requirements files allows an attacker to insert a specially crafted string inside a comment anywhere within a requirements.txt file, which will cause victims who use pipenv to install the requirements file to download dependencies from a package index server controlled by the attacker. By embedding malicious code in packages served from their malicious index server, the attacker can trigger arbitrary remote code execution (RCE) on the victims' systems. If an attacker is able to hide a malicious `–index-url` option in a requirements file that a victim installs with pipenv, the attacker can embed arbitrary malicious code in packages served from their malicious index server that will be executed on the victim's host during installation (remote code execution/RCE). When pip installs from a source distribution, any code in the setup.py is executed by the install process. This issue is patched in version 2022.1.8. The GitHub Security Advisory contains more information about this vulnerability.
- CWE
- CWE-190
- CVSS base score
- 8.6
- Published
- 2022-01-10
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Input Validation and Sanitization
- Subcategory
- Insecure Parsing or Deserialization
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Fixed by upgrading
- Yes
Solution
Update pipenv to version 2022.1.8 or higher.
Vulnerable code sample
def parse_requirements(requirements_content):
requirements = []
for line in requirements_content.splitlines():
if line.strip() and not line.startswith('#'):
requirements.append(line)
return requirements
requirements_txt = """
# --index-url=https://example.com/simple
requests==2.25.1
flask==1.1.2
"""
parsed_requirements = parse_requirements(requirements_txt)
print("Parsed requirements:", parsed_requirements)Patched code sample
import re
def parse_requirements(requirements_content):
requirements = []
for line in requirements_content.splitlines():
if line.startswith('#'):
continue
if re.search(r'--index-url', line):
raise ValueError("Malicious index-url detected in requirements.")
requirements.append(line)
return requirements
requirements_txt = """
requests==2.25.1
# --index-url=https://example.com/simple
flask==1.1.2
"""
try:
parsed_requirements = parse_requirements(requirements_txt)
print("Safe requirements:", parsed_requirements)
except ValueError as e:
print(e)Cite this entry
@misc{vaitp:cve202221668,
title = {{Pipenv prior to 2022.1.8 allows remote code execution via malicious requirements files}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2022},
note = {VAITP Python Vulnerability Dataset, entry CVE-2022-21668},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-21668/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
