OAuth delegates authorization, not authentication. The authorization server makes a decision about a resource owner and hands a code or token to a client. Every weak comparison of redirect_uri, missing state, reusable code or accepted implicit token moves that handoff to an attacker-chosen origin.
The authorization endpoint sends credentials to whatever redirect_uri passes validation. Prefix matching, suffix matching, path-only checks and open redirects on the client let an attacker satisfy the check while receiving the code elsewhere. Without state binding, a victim can be logged into the attacker's account. Without PKCE or code binding, a stolen code can be exchanged. Implicit flow puts the token in the fragment, where attacker JavaScript reads it directly.
The victim sees the real identity provider and the real consent screen. Only the final redirect belongs to the attacker, and it arrives after trust has already been granted.
What is actually at stake?
Before touching a payload, map the assets, the actors and the boundary that is supposed to protect them. A finding only becomes a vulnerability when you can connect the failed boundary to a real asset.
Assets
- Authorization codes and access tokens
- User profile, email, role and tenant claims
- Refresh tokens that outlive access tokens
- Consent decisions and account linking state
Actors
- Attacker who can lure a victim to an attacker-controlled page
- Malicious OAuth client registered with a weak redirect policy
- Attacker who has stolen a code or token and can replay it
- Compromised subdomain or open redirect on the trusted client
Trust boundaries
- Browser to client application
- Client to authorization server
- Authorization server to redirect_uri
- Client back channel to token endpoint
- Resource server trust in token issuer and audience
Abuse cases
- Use a redirect_uri that passes a prefix or suffix check but lands on the attacker origin
- Exploit an open redirect on the registered callback to forward the code
- Replay an authorization code that is not bound to the client or PKCE verifier
- Read an implicit-flow access token from the URL fragment
- Perform login CSRF by omitting state and binding the victim to the attacker's account
Follow the decision, not the payload
Every family has a moment where trusted data becomes an authorization, parsing or state decision. Learn to point at that moment in the request path.
- 01
Request
The client sends the browser to /authorize with client_id, redirect_uri, scope, state and response_type.
- 02
Decide
The authorization server authenticates the user, checks consent and validates the redirect_uri against its registration.
- 03
Redirect
The server sends a code or token to the redirect_uri. A weak comparison or open redirect sends it to the attacker.
- 04
Exchange
The client posts the code and client credentials or PKCE verifier to /token in exchange for an access token.
- 05
Use
The client calls the resource server, which must verify signature, issuer, audience, scope and expiry before returning data.
Redirect_uri bypasses and login CSRF in OAuth deployments
RFC 9700, OAuth 2.0 Security Best Current Practice, and public OAuth vulnerability advisoriesAcross many OAuth deployments, authorization servers validated redirect_uri with prefix, suffix or path-only comparisons, or trusted a client that contained an open redirect. RFC 9700 documents these patterns as recurring causes of code and token theft.
Researchers constructed redirect URIs such as https://trusted.example@attacker.example/callback, https://attacker.example/callback?trusted=trusted.example, or a path on an open redirector that forwarded to the attacker. The authorization server accepted the URI and delivered the code.
The attacker exchanged the code for a token and read the victim's profile, email or other scopes. Missing state also enabled login CSRF, binding a victim's browser to an attacker-controlled account.
Redirect URI validation was not an exact match, and codes were not tightly bound to the client, redirect URI and PKCE verifier. Some clients also enabled the implicit flow.
Register exact redirect URIs, reject all variants, require state and PKCE S256, bind codes to client and redirect URI, make codes one-time, disable implicit flow, and validate audience and issuer at the API.
Read it as a chain: discovery → failed decision → impact → fix. Then ask which link would have broken earliest.
A repeatable testing sequence
- Map the client_id, redirect_uri allowlist, response_type, scope and state handling.
- Test exact matching: userinfo tricks, trailing dots, subdomains, path traversal, open redirects and case differences.
- Check whether the code is bound to the client, redirect_uri and PKCE verifier, and whether it can be replayed.
- Check whether the implicit flow is still enabled and whether the token is exposed in the fragment or referrer.
- Exchange or replay what you captured and call a protected API to prove the identity you obtained.
Where smart people get fooled
- A redirect_uri that merely starts with the trusted origin is not an exact match; userinfo and subdomain tricks can redirect elsewhere.
- State prevents CSRF and login CSRF, but it does not prevent code theft after a bad redirect_uri decision.
- PKCE helps public clients, but only when the verifier is actually checked and bound to the code and client.
- A token in the URL fragment is not sent to the server, but attacker JavaScript on the callback origin can read it.
What would the logs show?
A control is stronger when someone can see it fail. These signals are starting points for a detection rule, not a complete SIEM use case.
- Authorization requests with redirect_uri values containing userinfo, encoded separators or unexpected hosts
- A single code exchanged from an IP or client that differs from the one that requested it
- Multiple failed token exchanges followed by a success for the same code
- Implicit response_type=token use in browser clients
- Token use at an API whose audience does not match the client
index=idp sourcetype=oauth | eval suspicious=if(match(redirect_uri, "@|%40|%2f%2f|%252f|\?.*https?://|#"),1,0) | stats count values(redirect_uri) values(client_id) by user, src_ip | where suspicious=1 OR count > 5Fix the decision, then prove it stays fixed
- Compare redirect_uri with an exact registered value, including scheme, host, port and path; reject everything else.
- Require and validate state, bind codes to client and redirect_uri, enforce PKCE S256 for public clients, and use one-time codes.
- Prefer authorization code with PKCE; disable implicit and password grants for browser clients.
- Keep access tokens out of URLs, use short lifetimes and sender constraints, and validate issuer, audience and nonce in OIDC.
if (!redirectUri.startsWith('https://app.example')) return reject();
const code = issueCode(user, redirectUri);
return redirect(redirectUri + '?code=' + code);const registered = clients[clientId]?.redirectUris ?? [];
if (!registered.includes(redirectUri)) return reject('invalid_redirect_uri');
if (!state || !isValidState(state, request.session)) return reject('invalid_state');
const code = issueCode({ user, clientId, redirectUri, codeChallenge, expiresAt: Date.now() + 60000 });
await storeCode(code);
return redirect(appendQuery(redirectUri, { code, state }));Use exact string matching against registered URIs, not prefix or suffix logic. Bind the code to client, redirect URI and PKCE challenge, make it single-use and short-lived, and verify issuer, audience and scope at the resource server.
Regression tests a reviewer would ask for
Exact redirect match
GivenA registered redirect_uri of https://app.example/callback
WhenThe client sends https://app.example/callback/extra or https://app.example@attacker.example/callback
ThenThe authorization server rejects the request before issuing a code
State is required
GivenAn authorization request without state
WhenThe callback returns to the client
ThenThe client rejects the response and does not establish a session
PKCE binding
GivenA code issued with an S256 challenge
WhenThe token request omits the verifier or supplies a different one
ThenThe token endpoint rejects the exchange
Audience enforcement
GivenA valid token issued for client A
WhenClient B calls the resource server with it
ThenThe resource server rejects the token because the audience does not match
What this finding is not
Strong testers kill their own findings before someone else does. These are the shortcuts that turn a real bug into a weak report — or a false alarm into a wasted escalation.
- The redirect_uri is reflected in an error page but the authorization server refuses to redirect there.
- The attacker can change redirect_uri only for a client they own, with no victim consent or data.
- State is missing but the flow is same-site and the impact is limited to a self-login, not another user's account.
- A token appears in the URL fragment but the callback immediately removes it and the attacker origin cannot read it.
Terms you should be able to use precisely
- Authorization code
- A short-lived, one-time credential returned to the client and exchanged at the token endpoint.
- redirect_uri
- The callback registered by the client; it must match exactly to prevent code delivery to another origin.
- State
- An opaque value that binds the authorization response to the user's browser session and prevents CSRF.
- PKCE
- Proof Key for Code Exchange: a verifier and challenge that bind the code exchange to the client that started it.
- Nonce
- An OIDC value that binds an ID token to the authentication request and prevents replay.
- Audience
- The intended recipient of a token; APIs must reject tokens issued for another service.
Answer these without reciting a payload
Why is prefix matching on redirect_uri unsafe?
An attacker can satisfy the prefix and still control the destination, for example through userinfo syntax, a subdomain, or a path on an open redirector. Only an exact match against a registered URI is safe.
What does state protect against, and what does it not protect?
State protects against CSRF and login CSRF by binding the response to the browser session. It does not stop code theft if the redirect_uri decision itself is wrong.
Why disable the implicit flow?
It returns the access token in the URL fragment, where attacker JavaScript or a leaked URL can read it, and it lacks the code exchange protections of the authorization code flow.
Can you separate the mechanism from the payload?
Four questions, graded on the server. Answers and explanations are released only after you submit, and signed-in learners keep a best score.
OAuth ليست مصادقة جاهزة، بل إطار تفويض. أخطر الأخطاء أن يتحقق الخادم من redirect_uri بمقارنة بادئة أو لاحقة أو مسار فقط، فيقبل عنوانًا يتحكم به المهاجم. استخدم مطابقة تامة لعناوين مسجلة، واشترط state لربط الاستجابة بالجلسة، وPKCE S256 لربط الكود بالعميل، واجعل الكود أحادي الاستخدام وقصير العمر. أوقف implicit flow، وتحقق في الـAPI من التوقيع والمُصدر والجمهور والصلاحيات. لا تضع التوكنات في الروابط، وتذكّر أن توقيع التوكن صحيح لا يعني أنه مخصص لخدمتك.
If the redirect is perfect but the client accepts a token issued for another client or audience, what stops the attack?