# Code inject via nginx.ingress.kubernetes.io/permanent-redirect annotation

Unsantized permanent-redirect annotation injected into nginx config, letting any ingress-creating user run commands in the controller pod and steal the ServiceAccount token to read cluster secrets.

- Payout: $2,500
- Severity: high
- Program: Kubernetes
- Found by (vendor credit): Jan-Otto Kröpke (Cloudeteer GmbH)
- Found by: jkroepke
- Disclosed: 2023-10-25
- CVE: CVE-2023-5044
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/2039464
- Library page: https://bugbountylibrary.com/r/h1%3A2039464
- Tags: area:cloud domain:cloud domain:web impact:data-leak impact:privesc impact:rce kind:bounty platform:hackerone sev:high tech:kubernetes tech:nginx technique:incomplete-fix vuln:command-injection vuln:misconfiguration

**Target:** ingress-nginx controller annotation handling
**Root cause:** The permanent-redirect annotation value is written into the generated nginx configuration without sanitization, so injected nginx directives (e.g. a hidden server/location) execute in the controller.
**Steps:**
1. Deploy ingress-nginx v1.8.0 with default values and `allow-snippet-annotations=false`.
2. Apply an Ingress whose `nginx.ingress.kubernetes.io/permanent-redirect` annotation contains injected nginx config defining a hidden server/location.
3. Port-forward the controller: `kubectl port-forward deploy/ingress-nginx-controller 8080:80`.
4. Request the hidden server: `curl -v --resolve "kubernetes.api:8080:127.0.0.1" http://kubernetes.api:8080/api/v1/namespaces/kube-system/secrets/` to confirm code execution.
**How found:** Researcher noted the permanent-redirect annotation is passed unsanitized into nginx config, and tested whether snippet-annotation protections (allow-snippet-annotations=false) could be bypassed through this separate annotation.
**Exploitation:** Attacker with RBAC to create/update Ingress objects injects nginx directives via the annotation, achieving command execution in the controller pod. The mounted ServiceAccount token is then used to call the Kubernetes API and read all secrets/configmaps, plus read/write files on the pod filesystem.
**Escalation:** Pivots from ingress-annotation injection to cluster-wide secret exfiltration via the controller's ServiceAccount token.
**Insight:** When a project disables snippet annotations as a hardening measure, audit every other annotation that flows into the same config template — sibling annotations often lack the same sanitization and become the bypass.

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

**Ingress manifest with permanent-redirect annotation payload**

```
apply service and ingress object from attachments
        k apply -f ingress.yaml #ingress.yaml is attached
```

**Curl request triggering injected redirect to secrets API**

```
curl -v --resolve "kubernetes.api:8080:127.0.0.1" http://kubernetes.api:8080/api/v1/namespaces/kube-system/secrets/
```

