From YAML to RCE: The PyYAML Deserialization Story
PyYAML's yaml.load() with unsafe loaders deserialises YAML tags that construct arbitrary Python objects, allowing an attacker who controls YAML input to execute commands. The write-up traces this design flaw through CVE-2017-18342 and later incomplete fixes in FullLoader.
Hi, I’m Amr Kadry, a Red Team Consultant and bug hunter, acknowledged by over 50 companies including Mozilla, CrowdStrike, Canva, Vimeo, and others.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the library's design allowed YAML tags to construct and invoke arbitrary Python objects during parsing, with no validation layer separating data from executable instructions.
Impact
An attacker who controls YAML input could achieve remote code execution with the privileges of the application, though only when an unsafe loader is explicitly used.
What the attacker needed
Attacker controls YAML input; application uses unsafe loader
The fix
Developers should use yaml.safe_load or Loader=yaml.SafeLoader for untrusted input; later PyYAML versions also force an explicit loader choice and block Python object tags in FullLoader.
How it was found
- Create a YAML file containing a python object apply tag that calls a system command.
- Load that file with yaml.load using the unsafe Loader.
- The parser resolves the tag and invokes the callable, running the command with the application's privileges.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
YAML is a text format for configuration. PyYAML is a Python library that reads it. Normally it should only produce simple data like lists and text. But some settings let a YAML file ask Python to create objects and run functions. If a website accepts YAML from users and uses those unsafe settings, an attacker can make the server run their commands.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.