# Ingress-nginx path allows retrieval of ingress-nginx serviceaccount token

Ingress path annotation injection into nginx.conf lets an ingress-creator read the controller's serviceaccount token, escalating to cluster-wide secret listing.

- Payout: $2,500
- Severity: high
- Program: Kubernetes
- Found by: 0ria
- Disclosed: 2022-08-06
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/1382919
- Library page: https://bugbountylibrary.com/r/h1%3A1382919
- Tags: area:cloud domain:cloud impact:data-leak impact:privesc kind:bounty platform:hackerone sev:high tech:kubernetes tech:nginx technique:chained technique:source-review vuln:misconfiguration vuln:privilege-escalation

**Target:** ingress-nginx controller nginx.conf generation via Ingress path field
**Root cause:** Ingress path is interpolated unsanitized into nginx.conf; crafted path injects an `alias` directive mapping /gaf to the pod's serviceaccount token directory.
**Steps:**
1. Create user with Role granting get/create/update on networking.k8s.io/ingresses in default namespace.
2. Apply Ingress with path `/gaf{alias /var/run/secrets/kubernetes.io/serviceaccount/;}location ~* ^/aaa` and pathType Prefix.
3. Request `https://<host>/gaf/token` from the ingress loadbalancer.
4. Decode returned JWT to confirm it is the ingress-nginx serviceaccount token.
5. Use token to list secrets cluster-wide via the nginx-ingress ClusterRole.
**How found:** Recognized that user-controlled Ingress path is templated into nginx.conf, hypothesized nginx directive injection, and crafted a path using `{...}` block syntax plus `alias` to expose the SA token mount path.
**Exploitation:** Attacker with only ingress-create RBAC writes a malicious path that injects an nginx `alias` directive into the controller's generated config, then fetches /gaf/token over the ingress LB to steal the controller SA token, which has cluster-wide secret list permission.
**Escalation:** Low-privilege ingress creator pivots to cluster-wide secret read via the controller's over-privileged ClusterRole binding.
**Insight:** When a controller templates user input into a config language (nginx, envoy, haproxy), test whether block/brace syntax and directives like `alias`/`root` can be injected via fields assumed to be plain paths; target well-known in-pod secret mount paths.

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

**Ingress path injection payload for nginx alias**

```
/gaf{alias /var/run/secrets/kubernetes.io/serviceaccount/;}location ~* ^/aaa
          pathType: Prefix
```

**Request to retrieve serviceaccount token**

```
Access to nginx ingress loadbalancer to /gaf/token path.

https://<host>/gaf/token
```

