redirect_uri registration rules and open redirect risk
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
| Form | Why it is dangerous |
|---|---|
https://*.example.com/cb | Every 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/cb | Text before @ is userinfo. The address bar shows example.com while the real host is evil.net. |
https://example.com/cb/../admin | Path normalisation can send the code to a different path. |
http://example.com/cb | Clear-text delivery; the code can be read on the same network. |
https://example.com/cb#frag | Fragments 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
- The attacker sends the victim an authorization URL with valid client_id and redirect_uri.
- The victim signs in and the server redirects to the registered redirect_uri with
?code=.... - If matching is loose, the attacker manipulates redirect_uri so the code lands on their own address.
- 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 OAuthLabFrequently 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
- RFC 6749 — The OAuth 2.0 Authorization Framework
- RFC 9700 — Best Current Practice for OAuth 2.0 Security
- OAuth 2.1 (draft-ietf-oauth-v2-1)
Read next
- PKCE S256: computing code_verifier and code_challenge correctlyThe RFC 7636 character set and length rules, the SHA-256 to Base64URL step, and where each value travels in the authorization and token requests.
- Authorization URL parameters: what to send and whyauthorization_endpoint, client_id, redirect_uri, response_type, scope, state, nonce, prompt and code_challenge, with a complete example URL.
- state and nonce: stopping CSRF and ID token replayWhere to store and compare state, where nonce is verified in an ID token, length and expiry, and the multi-tab and SPA failure modes.