CVE-2020-1747
PyYAML < 5.3.1, arbitrary code execution via python/object/new
- CVSS 9.8
- CWE-20 Improper Input Validation
- Input Validation and Sanitization
- Local
A vulnerability was discovered in the PyYAML library in versions before 5.3.1, where it is susceptible to arbitrary code execution when it processes untrusted YAML files through the full_load method or with the FullLoader loader. Applications that use the library to process untrusted input may be vulnerable to this flaw. An attacker could use this flaw to execute arbitrary code on the system by abusing the python/object/new constructor.
- CVSS base score
- 9.8
- Published
- 2020-03-24
- 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
- Local
- Impact
- Arbitrary Code Execution
- Affected component
- PyYAML
- Fixed by upgrading
- Yes
Solution
Update PyYAML to version 5.3.1 or higher.
Vulnerable code sample
import yaml
# This example demonstrates the vulnerability by using full_load
with open('untrusted_file.yaml', 'r') as file:
data = yaml.full_load(file)
# The following line could potentially execute arbitrary code
print(data)Patched code sample
import yaml
# Load YAML file safely using safe_load instead of full_load
with open('untrusted_file.yaml', 'r') as file:
data = yaml.safe_load(file)
# Now you can work with the data safely
print(data)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.
- Deprecate/warn usage of yaml.load(input) (yaml/pyyaml)
lib/yaml/constructor.py,lib/yaml/cyaml.py,lib/yaml/loader.py,lib/yaml/__init__.py,lib/yaml/__init__.py · load,lib/yaml/__init__.py · load_all,lib/yaml/__init__.py · safe_load,lib/yaml/__init__.py · safe_load_all,setup.py - Prevents arbitrary code execution during python/object/new constructor (#386) (yaml/pyyaml)
lib/yaml/constructor.py,lib3/yaml/constructor.py,lib3/yaml/constructor.py · FullConstructor.set_python_instance_state
Cite this entry
@misc{vaitp:cve20201747,
title = {{PyYAML < 5.3.1, arbitrary code execution via python/object/new}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2020},
note = {VAITP Python Vulnerability Dataset, entry CVE-2020-1747},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2020-1747/}}
}
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 ::
