☼
⌃
☰

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)

  1. User clicks "Login with X"
  2. App redirects to authorisation server with client_id, redirect_uri, scope, state
  3. User authenticates and grants permission
  4. Authorisation server redirects back with a code
  5. App exchanges code for access_token server-side
  6. App uses access_token to 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.

  1. Initiate OAuth flow and intercept the authorisation URL
  2. Drop your request before completing authentication
  3. 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

  • [ ] Is redirect_uri strictly validated?
  • [ ] Is the state parameter 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_uri bypass is the highest-value target — account takeover is the typical impact
  • Missing state is common and easy to spot — check the authorisation request
  • On CTFs, OAuth implementations are often simplified and missing multiple controls simultaneously