Invalid OAuth2 authorization URL in OpenAPI 3.0

Check that the OAuth2 authorization URL in OpenAPI 3.0 identifies the correct authorization server endpoint.

Description

For the OpenAPI 3.0 OAuth2 authorizationCode and implicit flows, authorizationUrl is where users sign in and grant consent.

Potential impact

An incorrect endpoint can interrupt consent or direct users to an untrusted site.

Remediation

In the flow under components.securitySchemes, set authorizationUrl to the provider’s published HTTPS authorization endpoint. Match its host and path and exclude any URL fragment beginning with #.

Examples

For the authorizationCode flow shown here, configure PKCE in the client and authorization server.

Before

json
{
  "openapi": "3.0.0",
  "components": {
    "securitySchemes": {
      "petstore_auth": {
        "type": "oauth2",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://api.invalid.company.com#@evil.com/oauth/authorize",
            "tokenUrl": "https://api.my.company.com/oauth/token",
            "scopes": {
              "write:api": "modify apis in your account",
              "read:api": "read your apis"
            }
          }
        }
      }
    }
  }
}

After

json
{
  "openapi": "3.0.0",
  "components": {
    "securitySchemes": {
      "petstore_auth": {
        "type": "oauth2",
        "flows": {
          "authorizationCode": {
            "authorizationUrl": "https://api.my.company.com/oauth/authorize",
            "tokenUrl": "https://api.my.company.com/oauth/token",
            "scopes": {
              "write:api": "modify apis in your account",
              "read:api": "read your apis"
            }
          }
        }
      }
    }
  }
}

References