Skip to content
RCE Disclosed report Advanced CVE-2021-25742

Ingress-nginx annotation injection allows retrieval of ingress-nginx serviceaccount token and secrets across all namespaces

The ingress-nginx controller did not properly escape or validate the connection-proxy-header annotation, allowing an attacker who could create or modify ingresses to inject arbitrary nginx directives. This let them read arbitrary files from the controller, including its service account token, which had permission to read secrets in all namespaces.

amlweems Follow

Originally disclosed on HackerOne

High 7.6 View original
  • Triaged in 25 days
  • Fixed in 9 months
  • Paid in 2 months
  • Disclosed after 10 months

I submitted the following report to [email protected]:

I've been exploring CVE-2021-25742 and believe I've discovered a variant (although it appears there may be many). Most template variables are not escaped properly in nginx.tmpl, leading to injection of arbitrary nginx directives. For example, the nginx.ingress.kubernetes.io/connection-proxy-header annotation is not validated/escaped and is inserted directly into the nginx.conf file.

An attacker in a multi-tenant cluster with permission to create/modify ingresses can inject content into the connection-proxy-header annotation and read arbitrary files from the ingress controller (including the service account).

I've created a secret gist demonstrating the issue against ingress-nginx v1.0.4: https://gist.github.com/amlweems/1cb7e96dca8ada8aee8dc019d4163f2c

Impact

An attacker with permission to create/modify ingresses in one namespace can inject content into the connection-proxy-header annotation and read arbitrary files from the ingress controller (including the service account). This service account has permission to read secrets in all namespaces.

The original report as published on HackerOne, by amlweems. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the template used to generate nginx.conf inserted the connection-proxy-header annotation without escaping or validation, allowing nginx directive injection.

Impact

An attacker with permission to create or modify ingresses in one namespace could read arbitrary files from the ingress controller, including a service account token that could read secrets in all namespaces.

What the attacker needed

Permission to create or modify ingresses; multi-tenant cluster

How it was found

  1. Create or modify an ingress in a namespace you control.
  2. Put crafted content into the connection-proxy-header annotation.
  3. The controller writes the unescaped annotation into nginx.conf.
  4. The injected nginx directives cause the controller to read arbitrary files, including its service account token.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

An ingress controller is a component that routes incoming web traffic to the right service inside a Kubernetes cluster. It builds its configuration from annotations, which are small notes attached to ingress objects. Here, one annotation was copied into the configuration without cleaning it, so someone allowed to create ingresses could sneak in extra configuration that made the controller read files it should not, including a credential that could access secrets everywhere.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More from Kubernetes

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.