CVE-2022-0845
PyTorch Lightning < 1.6.0 code injection
- CVSS 9.8
- CWE-94 Improper Control of Generation of Code ('Code Injection')
- Design Defects
- Remote
Code Injection in GitHub repository pytorchlightning/pytorch-lightning prior to 1.6.0.
- CVSS base score
- 9.8
- Published
- 2022-03-05
- OWASP
- A03 Injection
- Orthogonal defect classification
- Function
- Code defect classification
- Incorrect Functionality
- Category
- Design Defects
- Subcategory
- Security Misconfigurations
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Affected component
- PyTorch
- Fixed by upgrading
- Yes
Solution
Update pytorch-lightning to version 1.6.0 or higher.
Vulnerable code sample
import yaml
def load_yaml(file_path):
with open(file_path, 'r') as file:
# Unsafe load that can execute arbitrary code
data = yaml.load(file, Loader=yaml.FullLoader)
return data
# Example usage
config_data = load_yaml('config.yaml')Patched code sample
import yaml
def safe_load_yaml(file_path):
with open(file_path, 'r') as file:
# Use safe_load to avoid code execution vulnerabilities
data = yaml.safe_load(file)
return data
# Example usage
config_data = safe_load_yaml('config.yaml')Published fix
Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.
- Replace `eval()` with `ast.literal_eval()` for security (#12212) (pytorchlightning/pytorch-lightning)
pytorch_lightning/utilities/argparse.py,pytorch_lightning/utilities/argparse.py · parse_env_variables
Payload
!!python/object/apply:os.system ["cat /etc/passwd"]
Cite this entry
@misc{vaitp:cve20220845,
title = {{PyTorch Lightning < 1.6.0 code injection}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2022},
note = {VAITP Python Vulnerability Dataset, entry CVE-2022-0845},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2022-0845/}}
}
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 ::
