# OAuth 2.0 Vulnerabilities > OAuth 2.0 flaws are mostly implementation and configuration mistakes. They let an attacker steal or inject an authorization code or token, or tie a victim's browser to the wrong account, which turns "Log in with X" into account takeover. ## How it works OAuth is a delegation framework that got repurposed for login. The client takes a token (or the `/userinfo` data it unlocks) as proof of identity. The spec is loose, most security controls are optional, and in some grant types secrets travel through the browser ([[raw/portswigger.net/portswigger-oauth-2-0-authentication-vulnerabilities-3899|PortSwigger]]). Every bug class breaks one of these invariants: | Invariant | What breaks it | |---|---| | The code or token goes only to the registered client | Weak `redirect_uri` matching (prefix, wildcard subdomain, path confusion, parameter pollution). An open redirect or proxy page on an allowed origin. `Referer` leakage. Custom-scheme hijacking on mobile. | | The callback belongs to the browser that started the flow | Missing, static or non-single-use `state`. No PKCE. No session binding. The result is login CSRF or attacker-identity linking. | | The token is for *this* client and *this* scope | Client confusion: an implicit-flow token minted for another `client_id` is accepted. Scope upgrade at the token endpoint. | | The identity data is authentic | Implicit flow where the client trusts browser-posted profile data. Unverified email at the provider. | | Only trusted clients exist | Open Dynamic Client Registration with no redirect validation. SSRF through `jwks_uri`, `logo_uri` and similar. | Details per class: - **redirect_uri validation**: the ACSAC '23 study found the RFC's guidance under-specified. 6 of 16 IdPs were vulnerable to path confusion and 10 to parameter pollution, and chained with client bugs this gave full ATO ([[raw/dl.acm.org/oauth-2-0-redirect-uri-validation-falls-short-acm-4081|ACM]]). The allowlist must be per-client and exact ([[raw/blog.doyensec.com/doyensec-common-oauth-vulnerabilities-3891|Doyensec]]). - **Implicit flow**: if the client POSTs the user data it received to its own backend and the backend trusts it, changing the parameters impersonates any user ([[raw/portswigger.net/portswigger-oauth-2-0-authentication-vulnerabilities-3899|PortSwigger]]). OAuth 2.1 drops the implicit flow ([[raw/blog.doyensec.com/doyensec-common-oauth-vulnerabilities-3891|Doyensec]]). - **`state` and PKCE**: `state` should be unguessable and tied to the session. If it is missing or static, an attacker can complete their own flow in the victim's browser. That gives login CSRF, or links the attacker's IdP identity to the victim's account ([[raw/portswigger.net/portswigger-oauth-2-0-authentication-vulnerabilities-3899|PortSwigger]]). With a static `state`, no PKCE and no session binding, the code becomes a portable "log in as this account" token ([[raw/dkryptsecurity.com/login-csrf-via-a-replayable-oauth-code-static-state-no-pkce-15065|dkrypt]]). - **Scope upgrade**: an authorization server that trusts a `scope` parameter sent on the code-for-token request lets a malicious client widen access. The resource server must enforce the scope the user actually granted ([[raw/blog.doyensec.com/doyensec-common-oauth-vulnerabilities-3891|Doyensec]]). - **Hidden OIDC/OAuth surface**: Dynamic Client Registration is "SSRF by design" through `jwks_uri`, `request_uris` and `logo_uri`. The research also covers `redirect_uri` session poisoning and WebFinger user enumeration. Always fetch `/.well-known/openid-configuration` ([[raw/portswigger.net/portswigger-hidden-oauth-attack-vectors-4082|PortSwigger Research]]). - **Token-holder confusion**: OAuth access tokens that the app's session layer also accepts give delegated, narrowly scoped tokens full-session power ([[raw/github.com/nocodb-oauth-authentication-bypass-15291|NocoDB]]). - **Enterprise view**: attackers now target OAuth tokens rather than passwords. Stolen access and refresh tokens bypass MFA and survive password resets. Unit 42 names Cross-User OAuth Session Fixation (COSF), cross-tenant client ID confusion and cross-connector OAuth ATO as current classes ([[raw/unit42.paloaltonetworks.com/the-current-landscape-of-oauth-attacks-12366|Unit 42]]). ## What to check - [ ] Recon: identify the provider, fetch `/.well-known/openid-configuration` and `/.well-known/oauth-authorization-server`, note grant types, `response_mode`, and whether registration is open. - [ ] `redirect_uri`: test subdomains, paths, extra query params, duplicated params, and other origins the client controls (open redirects, proxy pages, dangling CNAMEs). Check whether the token endpoint re-validates it. - [ ] `state`: present? Unpredictable? Bound to the session or browser (not just signed)? Single-use? Cleared after the callback? Is PKCE enforced (not just supported)? - [ ] Account linking via OAuth: can a callback started by the attacker attach to a logged-in victim? - [ ] Implicit flow: can you tamper with the identity data the client sends to its own backend? - [ ] Token audience: does the client accept tokens issued to other `client_id`s? Can `scope` be raised at the token endpoint? - [ ] Where tokens or codes appear in URLs: `Referer`, logs, `postMessage`, post-login redirects. - [ ] Mobile: custom-scheme redirect URIs (can another app register the scheme?). - [ ] Dynamic registration: is it open, and are `redirect_uris`, `jwks_uri` and `logo_uri` fetched server-side (SSRF)? - [ ] Auth proxies in front of apps: how are bypass/skip rules matched (path vs full URI)? ## Notable cases - **@fastify/oauth2**: `state` and PKCE-verifier cookies were set on the login path but cleared with `Path=/`, so they survived the callback. The single-use guarantee failed, enabling login CSRF ([[raw/github.com/fastify-oauth2-login-csrf-via-uncleared-oauth-state-cookie-12793|advisory]]). - **Seamless Auth API <0.19.2**: `state` was HMAC-signed, 10-minute, single-use and PKCE was on, yet nothing bound it to the starting browser, and the PKCE verifier was derived server-side from `state`, so whoever held `state` held everything PKCE checks. That is login CSRF (RFC 9700 §4.7). Fix (#463): `/start` returns a random `binding` kept in `sessionStorage`; only its SHA-256 goes into the signed state; the callback compares it in constant time *before* marking the state used, so a wrong binding cannot burn a legitimate flow. A temporary `OAUTH_ALLOW_UNBOUND_STATE` escape hatch logs a warning at boot ([[raw/seamlessauth.com/we-wrote-an-rfc-9700-matrix-and-it-found-a-bug-oauth-state-binding-15863|Seamless Auth]]). - **Better Auth <1.7.16 (CVE-2026-134312)**: OAuth sign-in trusted unverified provider emails (including `email_verified: "false"` as a string) and ignored profile vs ID-token `sub` mismatches, allowing linking into a victim's local account ([[raw/github.com/better-auth-oauth-signature-issue-high-15981|advisory]]). - **Akeeba SocialLogin (Joomla)**: no session-bound `state`. A crafted callback link linked the attacker's social identity to a logged-in victim's account, followed by login as the victim ([[raw/github.com/akeeba-joomla-account-takeover-via-missing-oauth-state-validation-15450|advisory]]). - **Airbnb, 2016 ($5,000)**: redirect URIs were exact-matched, but a post-login redirect driven by `Referer`, chained with login CSRF on the OAuth start endpoint, delivered Facebook and Google tokens to an attacker page ([[raw/masimshahzad.medium.com/the-referer-header-that-redirected-oauth-tokens-14095|case study]]). - **Wildcard redirect + stale CNAME ($6,000)**: a `*.target.com` callback rule plus a subdomain takeover gave zero-interaction code theft ([[raw/medium.com/how-i-chained-a-stale-cname-record-with-oauth-2-0-wildcards-for-a-6-00-14401|writeup]]). - **MCP OAuth servers**: open DCR, missing redirect URI validation and optional PKCE gave one-click ATO across AI-integration servers ([[raw/blog.sicks3c.io/hunting-account-takeovers-in-the-wild-west-of-mcp-oauth-servers-6255|sicks3c]]). - **Identity injection (Bugcrowd)**: adding an `email` parameter to the profile POST during Facebook login logged the attacker in as any user ([[raw/medium.com/this-oauth-bug-earned-me-account-takeover-via-identity-injection-4357|writeup]]). - **CVE-2025-54576 (OAuth2-Proxy ≤7.10.0)**: `skip_auth_routes` regexes were matched against the full URI including the query string, so a crafted query bypassed authentication ([[raw/zeropath.com/oauth2-proxy-authentication-bypass-cve-2025-54576-4720|ZeroPath]]). - **NocoDB (<2026.10.1)**: OAuth access tokens were signed with the instance JWT secret and accepted as full sessions ([[raw/github.com/nocodb-oauth-authentication-bypass-15291|advisory]]). ## Defenses - Exact-match, per-client `redirect_uri` allowlists. No wildcards. Re-check at the token endpoint ([[raw/blog.doyensec.com/doyensec-common-oauth-vulnerabilities-3891|Doyensec]]). - Use authorization code + PKCE for all clients. Don't use the implicit flow, and use `response_mode=form_post` when tokens must come back through the browser ([[raw/blog.doyensec.com/doyensec-common-oauth-vulnerabilities-3891|Doyensec]]). - Make `state` unguessable, session-bound and single-use, and make the callback refuse a code that has no link to the current browser context ([[raw/dkryptsecurity.com/login-csrf-via-a-replayable-oauth-code-static-state-no-pkce-15065|dkrypt]]). A signed, expiring, single-use `state` is still unbound; bind it to a browser-held secret, and never derive the PKCE verifier from `state` itself ([[raw/seamlessauth.com/we-wrote-an-rfc-9700-matrix-and-it-found-a-bug-oauth-state-binding-15863|Seamless Auth]]). - The server derives identity from the provider (token or userinfo), never from client-supplied parameters. Verify token audience and granted scope. - Lock down or authenticate Dynamic Client Registration. Treat any URL the AS fetches as an SSRF sink ([[raw/portswigger.net/portswigger-hidden-oauth-attack-vectors-4082|PortSwigger Research]]). - Keep delegated OAuth tokens separate from first-party session credentials (different keys and audiences). - Enterprise: disable end-user consent for unverified apps, use admin approval workflows, and continuously audit registered redirect URIs ([[raw/unit42.paloaltonetworks.com/the-current-landscape-of-oauth-attacks-12366|Unit 42]]). ## Related - [[Authentication Security]] · [[OpenID Connect Security]] · [[Account Takeover]] · [[Device Code Phishing]] · [[OAuth Consent Phishing]] - [[Login CSRF]] · [[Cross-Site Request Forgery]] · [[Open Redirect to SSRF]] · [[JSON Web Tokens]] · [[MCP Security]] · [[API Security]] · [[Bug Bounty Hunting]] · [[AI and LLM Security]] See also: [[Open Redirect]] ## Sources - [[raw/portswigger.net/portswigger-oauth-2-0-authentication-vulnerabilities-3899|PortSwigger: OAuth 2.0 authentication vulnerabilities]] - [[raw/blog.doyensec.com/doyensec-common-oauth-vulnerabilities-3891|Doyensec: Common OAuth Vulnerabilities]] - [[raw/dl.acm.org/oauth-2-0-redirect-uri-validation-falls-short-acm-4081|OAuth 2.0 Redirect URI Validation Falls Short (ACM)]] - [[raw/portswigger.net/portswigger-hidden-oauth-attack-vectors-4082|PortSwigger: Hidden OAuth attack vectors]] - [[raw/dkryptsecurity.com/login-csrf-via-a-replayable-oauth-code-static-state-no-pkce-15065|Login CSRF via a replayable OAuth code (static state, no PKCE)]] - [[raw/github.com/fastify-oauth2-login-csrf-via-uncleared-oauth-state-cookie-12793|@fastify/oauth2 login CSRF via uncleared OAuth state cookie]] - [[raw/github.com/akeeba-joomla-account-takeover-via-missing-oauth-state-validation-15450|Akeeba (Joomla) account takeover via missing OAuth state validation]] - [[raw/masimshahzad.medium.com/the-referer-header-that-redirected-oauth-tokens-14095|The Referer Header That Redirected OAuth Tokens]] - [[raw/medium.com/how-i-chained-a-stale-cname-record-with-oauth-2-0-wildcards-for-a-6-00-14401|How I Chained a Stale CNAME Record with OAuth 2.0 Wildcards for a $6,000 Account Takeover (ATO)]] - [[raw/blog.sicks3c.io/hunting-account-takeovers-in-the-wild-west-of-mcp-oauth-servers-6255|Hunting Account Takeovers in the Wild West of MCP OAuth Servers]] - [[raw/medium.com/this-oauth-bug-earned-me-account-takeover-via-identity-injection-4357|This OAuth Bug Earned Me $$: Account Takeover via Identity Injection]] - [[raw/github.com/nocodb-oauth-authentication-bypass-15291|NocoDB OAuth authentication bypass]] - [[raw/zeropath.com/oauth2-proxy-authentication-bypass-cve-2025-54576-4720|OAuth2-Proxy Authentication Bypass (CVE-2025-54576)]] - [[raw/unit42.paloaltonetworks.com/the-current-landscape-of-oauth-attacks-12366|The Current Landscape of OAuth Attacks]] - [[raw/seamlessauth.com/we-wrote-an-rfc-9700-matrix-and-it-found-a-bug-oauth-state-binding-15863|We wrote an RFC 9700 matrix and it found a bug (OAuth state binding)]] - [[raw/github.com/better-auth-oauth-signature-issue-high-15981|Better Auth OAuth signature issue (high)]]