Skip to content
RCE Write-up Intermediate

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.

0d-amr Follow

Published on 0d-amr.medium.com

Hi, I’m Amr Kadry, a Red Team Consultant and bug hunter, acknowledged by over 50 companies including Mozilla, CrowdStrike, Canva, Vimeo, and others.

Amr, on 0d-amr.medium.com

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

  1. Create a YAML file containing a python object apply tag that calls a system command.
  2. Load that file with yaml.load using the unsafe Loader.
  3. 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.

More by 0d-amr

View all

2 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.