← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

OAuth 2.0 Vulnerabilities

Security CWE-287 OWASP A2:2021 CVSS 8.1 Advanced
debt(d7/e5/b5/t7)
d7 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'only careful code review or runtime testing' (d7). The term's detection_hints list semgrep, owasp-zap, and burpsuite — these are specialist/manual security tools, not default linters. Semgrep can catch missing state or loose redirect_uri patterns, but many application-level flaws (e.g. not verifying aud claim, implicit flow misuse) require manual testing or dynamic analysis with burpsuite/owasp-zap, meaning many issues only surface under deliberate security review and not during routine development.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix names several distinct fixes — state parameter validation, redirect_uri strict allowlist, PKCE for public clients — each of which may touch the OAuth callback handler, client registration logic, and front-end flow. Correcting all common_mistakes (aud verification, implicit flow removal, redirect_uri allowlist) spans multiple files and potentially the auth module, client configuration, and token validation layers, making this more than a single-line patch but stopping short of a full architectural rework.

b5 Burden Structural debt — long-term weight of choosing wrong

Closest to 'persistent productivity tax' (b5). OAuth vulnerabilities apply to web and API contexts broadly, meaning any team building auth flows must continuously carry awareness of these pitfalls. The applies_to scope (web, api) is wide, and the tags (authentication, authorisation) indicate a load-bearing concern. However, the burden is localised to the auth/OAuth integration layer rather than shaping the entire system architecture, so it lands at b5 rather than b7.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap — contradicts how a similar concept works elsewhere' (t7). The misconception field explicitly states that using a well-known OAuth library gives a false sense of security — a competent developer naturally assumes the library handles correctness, but application-level responsibilities (state validation, redirect_uri strictness, PKCE, aud claim verification) remain entirely theirs. This directly contradicts the reasonable expectation that a reputable library confers security, making it a serious and well-documented trap.

About DEBT scoring →

Also Known As

OAuth attack OAuth misconfiguration OAuth 2.0 flaw

TL;DR

Misimplemented OAuth flows expose applications to CSRF, token theft, open redirects, and account takeover.

Explanation

OAuth 2.0 vulnerabilities commonly include: missing state parameter validation (enabling CSRF on the authorisation flow), open redirect_uri validation allowing token theft, implicit flow token leakage via referrer headers, and mixing authorisation code flow with client-side apps. Always validate the state parameter using a CSRF token, enforce strict redirect_uri matching server-side, use PKCE for public clients, and prefer the authorisation code flow with short-lived tokens over implicit flow.

Diagram

flowchart TD
    subgraph State_Parameter_Attack
        LEGIT[Legitimate OAuth flow<br/>state=random123]
        CSRF2[Attacker forges callback<br/>state missing or predictable]
        CSRF2 --> ACCOUNT_LINK[Victim account linked<br/>to attacker identity]
    end
    subgraph Redirect_URI_Attack
        REG[Registered: example.com/callback]
        ATTACK[Attacker uses: evil.com/callback<br/>or example.com.evil.com]
        ATTACK --> TOKEN_LEAK[Auth code sent to attacker]
    end
    subgraph Fix4
        STATE2[Validate state parameter<br/>cryptographically random]
        EXACT[Exact redirect URI match<br/>no wildcards]
    end
style CSRF2 fill:#f85149,color:#fff
style TOKEN_LEAK fill:#f85149,color:#fff
style STATE2 fill:#238636,color:#fff
style EXACT fill:#238636,color:#fff

Common Misconception

Using a well-known OAuth library means your OAuth implementation is secure. The library handles the protocol correctly but application-level flaws — missing state parameter validation, open redirect_uri, or implicit flow misuse — are still entirely your responsibility.

Why It Matters

OAuth flaws allow account takeover without ever knowing the user's password — the attacker hijacks the authorisation flow itself.

Common Mistakes

  • Not validating the state parameter, enabling CSRF against the OAuth callback.
  • Accepting any redirect_uri value — attackers redirect the code to their server.
  • Using the implicit flow for server-side applications — the access token is exposed in the browser history.
  • Not verifying the id_token audience (aud) claim — a token issued to another client is accepted.

Code Examples

✗ Vulnerable
// Missing state parameter — CSRF on OAuth callback
$url = 'https://github.com/login/oauth/authorize?client_id=...';
// GET /callback?code=abc — no state, no CSRF protection
✓ Fixed
// Generate and verify state parameter
$state = bin2hex(random_bytes(16));
$_SESSION['oauth_state'] = $state;

$authUrl = 'https://github.com/login/oauth/authorize?' . http_build_query([
    'client_id'    => $_ENV['GITHUB_CLIENT_ID'],
    'redirect_uri' => 'https://yourapp.com/callback',
    'state'        => $state,
    'scope'        => 'read:user',
]);

// In callback:
if (!hash_equals($_SESSION['oauth_state'], $_GET['state'] ?? '')) abort(403);
unset($_SESSION['oauth_state']); // use once

// Exchange code server-to-server — never expose client_secret to browser

Added 15 Mar 2026
Edited 12 Jun 2026
Views 121
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings W 1 ping T 0 pings F 0 pings S 1 ping S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 1 ping T 1 ping W 0 pings T 0 pings F 0 pings S 1 ping S 1 ping M 2 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T
No pings yet today
No pings yesterday
Amazonbot 10 SEMrush 9 Ahrefs 8 Scrapy 8 PetalBot 8 Google 7 Bing 7 Perplexity 6 Unknown AI 4 ChatGPT 2 Twitter/X 2 Sogou 2 Applebot 2 Majestic 1 Meta AI 1 Brave Search 1
crawler 74 crawler_json 3 pre-tracking 1
DEV INTEL Tools & Severity
🔴 Critical ⚙ Fix effort: High
⚡ Quick Fix
Always validate the state parameter on OAuth callback to prevent CSRF; validate the redirect_uri against a strict allowlist; use PKCE for public clients to prevent code interception
📦 Applies To
any web api
🔗 Prerequisites
🔍 Detection Hints
No state parameter in OAuth flow; redirect_uri validated with prefix match not exact match; no PKCE for mobile or SPA clients; authorization code not validated against client_id
Auto-detectable: ✓ Yes semgrep owasp-zap burpsuite
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Medium ✗ Manual fix Fix: High Context: File Tests: Update
CWE-601 CWE-352 CWE-345


✓ schema.org compliant