VAITP Dataset

← Back to the dataset

CVE-2024-39780

ROS dynparam YAML deserialization allows arbitrary Python code execution.

  • CVSS 9.8
  • CWE-20
  • Design Defects
  • Remote

A YAML deserialization vulnerability was found in the Robot Operating System (ROS) 'dynparam', a command-line tool for getting, setting, and deleting parameters of a dynamically configurable node, affecting ROS distributions Noetic and earlier. The issue is caused by the use of the yaml.load() function in the 'set' and 'get' verbs, and allows for the creation of arbitrary Python objects. Through this flaw, a local or remote user can craft and execute arbitrary Python code. This issue has now been fixed for ROS Noetic via commit 3d93ac13603438323d7e9fa74e879e45c5fe2e8e.

CVSS base score
9.8
Published
2025-04-02
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Interface
Code defect classification
Incorrect Functionality
Category
Design Defects
Subcategory
Insecure Parsing or Deserialization
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
Python

Solution

Upgrade `ros-noetic-roslaunch` to the version containing commit 3d93ac13603438323d7e9fa74e879e45c5fe2e8e or later.

Vulnerable code sample

import yaml
import sys

def set_param(param_name, param_value):
    """
    Sets a ROS parameter using yaml.load.  Vulnerable to CVE-2024-39780.
    """
    try:
        # Vulnerable code: Uses yaml.load without specifying a safe loader.
        loaded_value = yaml.load(param_value)
        print(f"Setting parameter '{param_name}' to: {loaded_value}")
        # In a real ROS context, this would involve interacting with the ROS parameter server.
        # Here, we just print the value for demonstration.
    except yaml.YAMLError as e:
        print(f"Error parsing YAML: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")


if __name__ == "__main__":
    if len(sys.argv) != 3:
        print("Usage: python vulnerable_dynparam.py <param_name> <param_value_yaml>")
        sys.exit(1)

    param_name = sys.argv[1]
    param_value_yaml = sys.argv[2]

    set_param(param_name, param_value_yaml)

Patched code sample

import yaml
try:
    from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
    from yaml import Loader, Dumper


def safe_load_yaml(yaml_string):
    """
    Safely loads YAML data from a string, preventing arbitrary code execution.

    Uses yaml.safe_load instead of yaml.load to avoid vulnerabilities.
    """
    try:
        data = yaml.safe_load(yaml_string)  # Use safe_load
        return data
    except yaml.YAMLError as e:
        print(f"Error parsing YAML: {e}")
        return None

# Example usage to replace yaml.load in dynparam 'set' and 'get' verbs.
def process_yaml_input(yaml_input):
    """
    Processes YAML input using the safe loader.
    """
    data = safe_load_yaml(yaml_input)
    if data:
        print("Successfully parsed YAML data:", data)
        # Further processing of the parsed data goes here.
    else:
        print("Failed to parse YAML input.")

if __name__ == '__main__':
    # Example usage with a potentially malicious YAML payload
    malicious_yaml = """
    !!python/object/apply:os.system ["touch /tmp/pwned"]
    """

    # Process the YAML input using the safe loader.
    process_yaml_input(malicious_yaml)

    # Example with benign YAML data
    benign_yaml = """
    name: Alice
    age: 30
    city: New York
    """

    process_yaml_input(benign_yaml)

Payload

!!python/object/apply:subprocess.check_output
args: ['touch /tmp/pwned']

Cite this entry

@misc{vaitp:cve202439780,
  title        = {{ROS dynparam YAML deserialization allows arbitrary Python code execution.
}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2025},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-39780},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-39780/}}
}
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 ::