0Pricing
Cryptology Academy · Lesson

OAuth Vulnerabilities and Attack Patterns

Study redirect URI manipulation, CSRF on the authorization endpoint, and token leakage vulnerabilities.

OAuth Vulnerabilities and Attack Patterns is a free Cryptology Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Cryptology Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Open Redirect in redirect_uri

OAuth authorization servers must strictly validate the redirect_uri parameter. If the server allows prefix matching or wildcard matching (e.g., accepting any URL starting with "https://app.example.com"), an attacker crafts an authorization request redirecting to "https://app.example.com.attacker.com/steal" or an open redirect on the legitimate domain, stealing the authorization code.

CSRF on the Authorization Endpoint

Without CSRF protection, an attacker can initiate an OAuth flow and trick a victim's browser into completing the authorization. The victim inadvertently authorizes the attacker's client. The "state" parameter (RFC 6749) prevents this: the client generates a random state, includes it in the request, and verifies it matches in the callback. A mismatch aborts the flow.

Authorization Code Interception

On mobile platforms, malicious apps can register the same custom URI scheme as a legitimate OAuth client and intercept authorization codes redirected after user authentication. PKCE (RFC 7636) is the complete defense: the intercepted code is useless without the code verifier that only the legitimate app generated at the start of the flow.

Token Leakage via Referer Header

When an ID token or access token is included in a URL fragment or query parameter, subsequent navigations from that page include the URL in the Referer header, potentially leaking the token to third-party analytics scripts or CDN providers. Always use the authorization code flow with back-channel token delivery to avoid tokens appearing in URLs.

Mix-Up Attacks in Multi-Provider Setups

When a client supports multiple OAuth providers, mix-up attacks trick the client into sending an authorization code obtained from Provider A to Provider B's token endpoint. The client must validate the "iss" claim in ID tokens and bind the callback to the specific provider that initiated the flow using the state parameter or JARM (JWT-Secured Authorization Response Mode).

SSRF via redirect_uri

Server-side request forgery (SSRF) attacks target OAuth implementations that make server-side HTTP requests to the redirect_uri. If the authorization server fetches the redirect_uri to verify it, an attacker supplies an internal IP address (e.g., http://169.254.169.254/latest/meta-data/) to access cloud instance metadata or internal services. Strict allowlist-based redirect_uri validation prevents this.

Account Takeover via Email Claim Collision

Many applications use the email claim from an OIDC ID token to link accounts across providers. If an attacker controls an email address that matches a victim's account at another provider, they can register with a different provider using that email and gain access to the victim's account. Defense: link accounts by (iss, sub) pair only, never by email alone.

JWT Algorithm Confusion

JWT algorithm confusion attacks exploit implementations that trust the "alg" header to select the verification algorithm. Attack: change "alg" from "RS256" to "HS256" and sign the token with the server's public key as the HMAC secret (since the public key is public). Defense: always specify the expected algorithm explicitly in the verification code, never trust the token header's alg claim.

OAuth Phishing via Consent Screen Spoofing

Attackers register malicious OAuth clients with legitimate-looking names and logos, then send phishing links to targets. The victim sees a genuine OAuth consent screen (hosted by Google, Microsoft, etc.) for a malicious application and grants access. Defense: verify client_id corresponds to the expected application; Google and Microsoft provide client verification programs for legitimate apps.

Scope Escalation Attacks

Scope escalation occurs when a client obtains tokens with broader permissions than what the user authorized. Implementation flaws that skip scope validation on the token endpoint, cache tokens with merged scopes across different requests, or fail to validate that the scope in the issued token does not exceed the authorized scope can all lead to privilege escalation via OAuth.

Security Best Practices Summary

Defend OAuth implementations by: using exact-match redirect_uri validation, requiring PKCE for all public clients, validating the state parameter for CSRF protection, binding ID tokens by (iss, sub) not email, specifying expected JWT algorithms explicitly, requesting minimal scopes, using short-lived access tokens with refresh token rotation, and auditing consent screen appearance for brand impersonation risk.

OAuth redirect_uri Check

An OAuth authorization server accepts any redirect_uri that begins with "https://app.example.com". What attack does this enable?

Lesson Recap: OAuth Attack Patterns

Key OAuth attacks: open redirect via lax redirect_uri validation (use exact match), CSRF via missing state parameter, code interception on mobile (mitigated by PKCE), token leakage in URLs, mix-up in multi-provider setups (validate iss), SSRF via server-fetched redirect_uri, email claim collision (use iss+sub), JWT algorithm confusion (fix expected alg), and phishing via fake consent screens.

Frequently asked questions

Is the “OAuth Vulnerabilities and Attack Patterns” lesson free?

Yes — the full text of “OAuth Vulnerabilities and Attack Patterns” is free to read here on the web, and the Cryptology Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Cryptology Academy course, upgrade to CoddyKit PRO.

What will I learn in “OAuth Vulnerabilities and Attack Patterns”?

Study redirect URI manipulation, CSRF on the authorization endpoint, and token leakage vulnerabilities. You practise Cryptology Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Cryptology Academy?

No prior experience is required. Cryptology Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “OAuth Vulnerabilities and Attack Patterns” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Cryptology Academy lesson?

Yes. Every Cryptology Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. OAuth 2.0 Flows and Token Types
  2. PKCE: Securing Public Clients
  3. OpenID Connect Claims and ID Tokens
  4. OAuth Vulnerabilities and Attack Patterns
← Back to Cryptology Academy