OAuth 2.0
Table of Contents
An authorisation framework that allows third-party applications to access resources on behalf of a user without exposing credentials. Widely used for API authentication and social login. Frequently misconfigured in ways that allow account takeover.
Related: API Testing Methodology JWT Attacks Authorisation MFA
Flow Overview
Authorization Code Flow (most common)
- User clicks "Login with X"
- App redirects to authorisation server with
client_id,redirect_uri,scope,state - User authenticates and grants permission
- Authorisation server redirects back with a
code - App exchanges
codeforaccess_tokenserver-side - App uses
access_tokento access resources
Common Vulnerabilities
Open Redirect via redirecturi
If redirect_uri is not strictly validated, redirect the
authorisation code to an attacker-controlled server.
https://auth.target.com/oauth/authorize ?client_id=abc &redirect_uri=https://attacker.com/callback &response_type=code &scope=openid
Variations to try:
redirect_uri=https://attacker.com redirect_uri=https://target.com@attacker.com redirect_uri=https://target.com.attacker.com redirect_uri=https://target.com/callback/../../../attacker
Missing State Parameter (CSRF)
The state parameter prevents CSRF attacks on the OAuth flow. If
missing or not validated, force a victim to link their account to
yours.
- Initiate OAuth flow and intercept the authorisation URL
- Drop your request before completing authentication
- Send the URL to a victim — their account gets linked to your OAuth identity
Token Leakage via Referrer
If the access token appears in the URL and the application loads external resources, the token leaks via the Referrer header.
Check for access_token in the URL fragment or query string:
https://target.com/callback#access_token=<token>
Scope Manipulation
Test whether requesting additional scopes beyond what is granted is enforced server-side.
scope=openid email profile admin
Insecure Token Storage
Check where tokens are stored client-side:
- localStorage — accessible via XSS
- sessionStorage — accessible via XSS
- Cookies without HttpOnly — accessible via XSS
- Cookies with HttpOnly — safer but check SameSite
Testing Checklist
[ ]Isredirect_uristrictly validated?[ ]Is thestateparameter present and validated?[ ]Does the authorisation code expire quickly?[ ]Can the authorisation code be used more than once?[ ]Are scopes enforced server-side?[ ]Where are tokens stored client-side?[ ]Does the token appear in URLs or logs?
Tips
- Start by mapping the full OAuth flow in Burp Suite before tampering with anything
- The
redirect_uribypass is the highest-value target — account takeover is the typical impact - Missing
stateis common and easy to spot — check the authorisation request - On CTFs, OAuth implementations are often simplified and missing multiple controls simultaneously