CVE-2017-16615
YAML parsing in MLAlchemy allows arbitrary Python command execution via unsafe load usage
- CVSS 9.8
- CWE-502: Deserialization of Untrusted Data
- Input Validation and Sanitization
- Local
An exploitable vulnerability exists in the YAML parsing functionality in the parse_yaml_query method in parser.py in MLAlchemy before 0.2.2. When processing YAML-Based queries for data, a YAML parser can execute arbitrary Python commands resulting in command execution because load is used where safe_load should have been used. An attacker can insert Python into loaded YAML to trigger this vulnerability.
- CVSS base score
- 9.8
- Published
- 2017-11-08
- OWASP
- A03 Injection
- 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
- MLAlchemy
- Fixed by upgrading
- Yes
Solution
Update MLAlchemy to version 0.2.2 or higher.
Vulnerable code sample
import yaml
def parse_yaml_query(yaml_query):
# Vulnerable code: using load instead of safe_load
return yaml.load(yaml_query)
# Example usage
yaml_query = """
- !!python/object/apply:os.system ['echo vulnerable code executed']
"""
# This will execute the command in the YAML due to the vulnerability
result = parse_yaml_query(yaml_query)
print(result)Patched code sample
import yaml
def safe_parse_yaml_query(yaml_query):
# Use safe_load instead of load to prevent arbitrary code execution
return yaml.safe_load(yaml_query)
# Example usage
yaml_query = """
- !!python/object/apply:os.system ['echo vulnerable code executed']
"""
# This will safely parse the YAML without executing the command
result = safe_parse_yaml_query(yaml_query)
print(result)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.
- attempting to fix security flaw (issue #1) (thanethomson/MLAlchemy)
mlalchemy/parser.py · parse_yaml_query
Cite this entry
@misc{vaitp:cve201716615,
title = {{YAML parsing in MLAlchemy allows arbitrary Python command execution via unsafe load usage}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2017},
note = {VAITP Python Vulnerability Dataset, entry CVE-2017-16615},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2017-16615/}}
}
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 ::
