Interactive Playground
Experiment with the vulnerable code and security rule below. Edit the code to see how the rule detects different vulnerability patterns.
pathfinder scan --ruleset python/PYTHON-LANG-SEC-043 --project .About This Rule
Understanding the vulnerability and how it is detected
ruamel.yaml is a YAML parser that supports multiple loading modes via the typ parameter: 'rt' (round-trip, default), 'safe', 'base', 'unsafe', and 'full'. When configured with typ='unsafe' or typ='full', ruamel.yaml enables Python-specific YAML tags (!!python/object, !!python/apply) that can instantiate arbitrary Python classes during parsing.
Like PyYAML's unsafe loader, this creates a remote code execution vulnerability when processing YAML from untrusted sources. An attacker who can control the YAML content can craft a document that executes arbitrary Python code when the YAML object's load() method is called.
The default typ='rt' (round-trip) loader does not support Python object instantiation and is safe for parsing untrusted YAML content. Always use typ='safe' or the default when processing external data.
Security Implications
Potential attack scenarios if this vulnerability is exploited
Python Object Instantiation via YAML Tags
With typ='unsafe', ruamel.yaml processes !!python/object and !!python/apply YAML tags that import and instantiate arbitrary Python classes. An attacker crafts YAML with !!python/object/apply:os.system to execute system commands when the YAML is parsed.
Configuration File Attack Surface
Infrastructure tools, DevOps scripts, and application configuration loaders that use ruamel.yaml to process user-editable or network-sourced YAML files with typ='unsafe' are vulnerable. This is especially common in Python-based configuration management tools.
CI/CD Pipeline Exploitation
CI/CD tools written in Python that parse pipeline definition files or workflow configurations using ruamel.yaml with unsafe mode allow users who can submit pipeline files to execute code with the pipeline runner's privileges.
Infrastructure-as-Code Attacks
Ansible, SaltStack, and similar Python-based IaC tools use YAML for playbooks and configuration. If any component uses ruamel.yaml with unsafe mode to process playbooks, submitted playbook content could execute code on the management node.
How to Fix
Recommended remediation steps
- 1Replace YAML(typ='unsafe') with YAML(typ='safe') or YAML() (default round-trip) for all external YAML parsing.
- 2Never use typ='full' or typ='unsafe' for YAML content that could be influenced by external users.
- 3If Python object serialization is required for internal use, consider alternative approaches such as explicit JSON schemas or Protocol Buffers.
- 4Audit all ruamel.yaml usage in CI/CD tools, configuration loaders, and infrastructure scripts.
- 5Validate YAML structure and types after safe loading to ensure the input matches the expected schema.
Detection Scope
How Code Pathfinder analyzes your code for this vulnerability
This rule detects YAML() constructor calls where the typ parameter is set to 'unsafe' or 'full'. These are the ruamel.yaml modes that enable Python object instantiation during YAML parsing and are dangerous when processing untrusted YAML content.
Compliance & Standards
Industry frameworks and regulations that require detection of this vulnerability
References
External resources and documentation
Similar Rules
Explore related security rules for Python
Pickle Deserialization of Untrusted Data
pickle.loads() and pickle.load() execute arbitrary Python code during deserialization. Never unpickle data from untrusted sources.
PyYAML Unsafe Load Function
yaml.load() and yaml.unsafe_load() can execute arbitrary Python objects during YAML parsing. Use yaml.safe_load() instead.
jsonpickle Deserialization Detected
jsonpickle.decode() can execute arbitrary Python code during deserialization. Use the standard json module for untrusted data.
Frequently Asked Questions
Common questions about ruamel.yaml Unsafe Loader Configuration
New feature
Get these findings posted directly on your GitHub pull requests
The ruamel.yaml Unsafe Loader Configuration rule runs in CI and posts inline review comments on the exact lines — no dashboard, no SARIF viewer.