YAML

Yet Another Markup Language

Description

First of all, this great article explains all sorts of tricks and weirdness in YAML:

Explanation and examples of many YAML tricks

Insecure Deserialization

In YAML the ! character can mean a tag, which allows you to execute a function in the host language with a parameter that comes right after (because why not). Many parsers implement this as it is required by the spec, but if attackers have control over the YAML file, even partially, they can use these tags to run arbitrary functions with arbitrary arguments.

A common target for this is a function that executes shell commands, where you can gain Remote Code Execution. The following examples all execute the id command and allow you to execute any arbitrary commands:

Ruby

Payload (>2.7, source)

Python

Payload

JavaScript - js-yaml (<4.0)

This popular JavaScript library allows the creation of arbitrary functions like .toString() which can be called accidentally, when using load() instead of safeLoad() in versions below 4:

Payloads

Java - SnakeYAML (<2.0)

Walkthrough of vulnerability as theory and exploitability

Payload

/payload.jar file:

  1. Explanation (search "remote jar file")

  2. Proof of Concept with build.sh script (change exec())

Parser differentials

The complex nature of YAML makes parsing it consistently a hard task. This results in slight differences between implementations that may confuse a check and a use. Below is an example that results in lang: ... with 3 different values depending on which language's standard library parses it.

Another more extreme example that requires some specific features supports a lot more languages (by @taramtrampam):

Watch "Parser Differentials - joernchen at OffensiveCon 2025" to learn more.

Last updated