VAITP Dataset

← Back to the dataset

CVE-2017-16616

YAML parsing vulnerability in PyAnyAPI (before 0.6.1): Arbitrary Python command execution due to "load" instead of "safe_load"

  • CVSS 9.8
  • CWE-15: External Control of System or Configuration Setting
  • Input Validation and Sanitization
  • Local

An exploitable vulnerability exists in the YAML parsing functionality in the YAMLParser method in Interfaces.py in PyAnyAPI before 0.6.1. 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
PyAnyAPI
Fixed by upgrading
Yes

Solution

Update PyAnyAPI to version 0.6.1 or higher.

Vulnerable code sample

import yaml

def load_yaml(yaml_string):
    # Using load instead of safe_load, which can execute arbitrary code
    return yaml.load(yaml_string)

# Example of potentially dangerous YAML input
yaml_data = """
!!python/object/apply:os.system ['echo Vulnerable']
"""
data = load_yaml(yaml_data)
print(data)

Patched code sample

import yaml

def safe_load_yaml(yaml_string):
    # Use safe_load to prevent arbitrary code execution
    return yaml.safe_load(yaml_string)

# Example usage
yaml_data = """
name: John Doe
age: 30
"""
data = safe_load_yaml(yaml_data)
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.

Cite this entry

@misc{vaitp:cve201716616,
  title        = {{YAML parsing vulnerability in PyAnyAPI (before 0.6.1): Arbitrary Python command execution due to "load" instead of "safe_load"}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2017},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2017-16616},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2017-16616/}}
}

Download this entry as JSON Download the whole dataset

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 ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.