opyebOAuthLab

redirect_uri registration rules and open redirect risk

Security · 10 min read

In one line: Why exact matching matters, and how wildcards, subdomains, path traversal and userinfo (@) confusion turn into account takeover.

redirect_uri is where the authorization code is delivered. If matching is loose, an attacker can receive the code on their own site and sign in as the victim. RFC 6749 therefore requires an exact match with the registered value, and RFC 9700 explicitly forbids wildcards and partial matching.

Exact match

The server compares the request value with the registered value character by character: scheme, host, port, path and trailing slash. https://app.example.com/callback and https://app.example.com/callback/ are different values.

Risky registrations

FormWhy it is dangerous
https://*.example.com/cbEvery subdomain can receive codes. One compromised subdomain opens the account.
https://example.com/cb*Path prefix matching; variants such as /cb/../../evil may pass.
https://example.com@evil.net/cbText before @ is userinfo. The address bar shows example.com while the real host is evil.net.
https://example.com/cb/../adminPath normalisation can send the code to a different path.
http://example.com/cbClear-text delivery; the code can be read on the same network.
https://example.com/cb#fragFragments never reach the server, so the request no longer matches the registration.

Accepted exceptions

Native apps use custom schemes such as myapp://callback. Because another app can claim the same scheme, pair it with PKCE and platform app verification. Desktop and CLI development may use http://127.0.0.1:port/callback. RFC 8252 allows ignoring the port for loopback, but prefer naming 127.0.0.1 and [::1] rather than only the string localhost.

Attack sequence

  1. The attacker sends the victim an authorization URL with valid client_id and redirect_uri.
  2. The victim signs in and the server redirects to the registered redirect_uri with ?code=....
  3. If matching is loose, the attacker manipulates redirect_uri so the code lands on their own address.
  4. The attacker exchanges the code at the token endpoint. Without PKCE, this succeeds.

PKCE breaks step 4: a stolen code without the verifier cannot be exchanged. PKCE does not replace redirect URI validation, so both are needed.

Checklist

  • Are all registrations absolute https URLs (http only for loopback development)?
  • No wildcards, suffix matching or regex patterns?
  • No @ or percent encoding in the host?
  • No .. in the path?
  • No fragment?
  • No dynamically appended query strings?
  • No unnecessary path variants on the same host?

Checking it in OAuthLab

Panel ⑤ takes the candidate list, one per line, and reports high, medium, low and informational findings with reasons. It is a heuristic, not a replacement for the provider's registration policy — confirm the final list against provider documentation and a security review.

PKCE and URL checks run right here in your browser. Nothing you type is stored.

Open OAuthLab

Frequently asked questions

I need to allow every subdomain. Is there a safe way?

Register each exact redirect_uri per subdomain. If that is impractical, use a tenant-aware registration feature on the authorization server rather than a wildcard.

My loopback port changes every run. How do I register it?

RFC 8252 lets the server ignore the port for loopback redirects. Confirm your provider supports that; otherwise pin a fixed port.

Can I pass state in a redirect_uri query?

Not recommended. Pass state in the state parameter and keep redirect_uri fixed to the registered value; dynamic queries open a path around exact matching.

Sources

Read next