OAuth Redirect URI Not Validated

The OAuth or OpenID Connect authorisation server does not strictly check the redirect URI, so a crafted link can send a user's authorisation code or token to an attacker.

SeverityHigh
CVSS 3.18.1 CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:N Open in the calculator
CVSS 4.08.5 CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:A/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-601: URL Redirection to Untrusted Site ('Open Redirect')
OWASP Top 10A01:2025 Broken Access Control
MITRE ATT&CKT1528 Steal Application Access Token, T1566.002 Spearphishing Link
CategoryBroken Access Control

Description

In OAuth 2.0 and OpenID Connect, the authorisation server returns the user to the client application with an authorisation code or token at the address given in the redirect_uri parameter. The server must compare that address with the values registered for the client and refuse anything else. The authorisation server accepts addresses that were not registered, or checks them loosely, so an attacker can craft an authorisation link that delivers the result of the user's sign-in to a location the attacker controls or can read. A user who follows the link while signed in to the authorisation server, or who signs in when prompted, has their code or token sent to the attacker, and users who have already consented to the client may see nothing unusual.

Where an access token is returned directly, as in the implicit flow, the attacker can use it at once to reach the user's data within the granted scopes. Where an authorisation code is leaked, the attacker can often use it to sign in to the client application as the user, particularly where the token endpoint does not check that the redirect URI matches the one in the original request. The usual result is takeover of the user's account in the client application.

Common forms are: no validation at all; matching only the start of the address, so extra path segments, path traversal sequences or a different port are accepted; matching only the domain or a wildcard subdomain, so any page or subdomain qualifies, including one with an open redirect or content an attacker can place; and parsing differences, where the server and the browser interpret an unusual address (with embedded credentials, encoded characters or a second redirect_uri parameter) differently.

The weakness is identified by changing redirect_uri in an authorisation request to each of these variants, including an external domain, and observing whether the server redirects to it with a code or token. The same test applies to a custom-built authorisation server and to an identity platform configured with wildcard or overly broad redirect addresses.

Remediation

Enforce exact matching of redirect addresses at the authorisation server:

  • Register the complete redirect URI for each client and compare the value in each request with the registered values by exact string comparison, as the OAuth 2.0 Security Best Current Practice requires. Do not use prefix, domain, wildcard or pattern matching. The only accepted exception is the port number of a loopback address used by native applications.
  • Reject a request with a missing, unregistered or repeated redirect_uri parameter by showing an error at the authorisation server, without redirecting.
  • At the token endpoint, check that the redirect URI sent with the code is identical to the one used in the authorisation request.
  • In identity platforms such as Microsoft Entra ID, Okta, Auth0 or Keycloak, review each application's registered redirect URIs, remove wildcards, unused entries and development addresses such as localhost from production clients, and register only HTTPS addresses for web clients.
  • Use the authorisation code flow with PKCE, and remove open redirects from the client's domains, so that a leaked code or a redirect chain is of less use.

Confirm the fix by repeating the modified redirect_uri tests and checking that every variant is refused without a redirect.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Authentication and Sessions Findings

Every Authentication and Sessions finding