Skip to content
Pwnversity
WEB-OAUTHadvanced · 10 min · upd. 2026-11

OAuth / SAML / SSO

OWASP A07:2025CWE-287

Federated login (“Sign in with Google/Microsoft”) delegates authentication to an identity provider (IdP). Flaws are almost never in the protocol but in how the app implements it: lax validations that let an attacker steal the victim’s code/token and take over their account with no credentials. It’s high-value bug-bounty ground because a single sloppy callback implementation usually yields account takeover (ATO) across all users.

sequenceDiagram
    participant U as User
    participant C as Client (app)
    participant AS as Authorization server
    U->>C: sign in with the provider
    C-->>U: redirect to AS (client_id, redirect_uri, scope, state)
    U->>AS: authenticates and consents
    AS-->>U: redirect to redirect_uri with code
    U->>C: delivers the code
    C->>AS: exchange code for token (client auth + PKCE)
    AS-->>C: access_token (+ id_token in OIDC)

Account takeover (ATO) of the user in the client app, access-token theft, access to whatever the scope grants (email, profile, APIs) and pivot to everything the SSO protects. The most lucrative pattern: divert or leak the victim’s code/token to a domain the attacker controls.

OAuth 2.0 (authorization) defines four roles: resource owner (user), client (the app), authorization server (IdP) and resource server (the API holding the protected resources). The recommended flow is authorization code + PKCE; implicit is deprecated (the token used to ride in the fragment). PKCE and client authentication are not alternatives: a confidential client authenticates with its client_secret and may also use PKCE, which binds the code to the request that created it. Key parameters: client_id, redirect_uri, response_type, scope, state, code and, with PKCE, code_challenge/code_verifier. OIDC adds authentication on top of OAuth with an id_token (a JWT). SAML does the equivalent with signed XML assertions.

The invariants a correct implementation holds —and each attack breaks—: (1) redirect_uri is compared exactly against a registered list; (2) state binds the response to the session that started it (anti-CSRF); (3) the code is single-use, short-lived and bound to the client_id; (4) the id_token is validated (iss, aud, nonce, signature, exp).

  • redirect_uri bypass — divert the code/token to an attacker domain.
  • code/token leak — via Referer, chained open redirect or dangling markup.
  • Missing/unvalidated state — login CSRF and forced account linking.
  • Pre-account-takeover — register the account the victim will later federate.
  • Missing or downgraded PKCE — intercept the code with no code_verifier.
  • id_token flaws — iss/aud/nonce unvalidated, JWT confusion, SSRF via jwks_uri.
  • SAML — signature not validated, XML Signature Wrapping, NameID injection, XXE.

Capture the authorization request in Burp and note: response_type (code vs token), the registered redirect_uri, whether state and nonce travel, whether there’s a code_challenge (PKCE) and the requested scope. Also locate the discovery endpoint (/.well-known/openid-configuration) and the client’s account-linking flow.

The king of flaws: if validation isn’t exact, you divert the code/token to your domain. Test systematically, with registered redirect_uri = https://app.tld/callback:

https://app.tld.attacker.tld/callback # suffix: your domain contains the registered one
https://attacker.tld/app.tld/callback # attacker host, mimicking path
https://app.tld@attacker.tld/callback # userinfo: real host is attacker.tld
https://app.tld/callback/../../redirect # path traversal / normalization
https://app.tld/callback?x=https://attacker.tld # appended parameter
//attacker.tld # protocol-relative
https://app.tld/callback%2f%2e%2e%2f # encoding to slip past the matcher

An exact-match callback can’t be bypassed by an open redirect elsewhere on the origin: the chain only works when redirect_uri validation accepts the open-redirect endpoint itself (e.g. it validates only the origin or a path prefix). Where it does, point redirect_uri at that endpoint so the AS redirects there and it forwards the code to your domain (see Open redirect).

  • Referer: if the callback page loads external resources and uses a permissive referrer policy, the code in the URL leaks in the Referer header. Under the modern default (strict-origin-when-cross-origin) the path and query are stripped cross-origin, so this needs a weakened policy (e.g. unsafe-url).
  • Fragment (implicit): the token sits after #; any URL leak exposes it.
  • Dangling markup / open redirect in the flow: exfiltrate the URL carrying the code.
  • Redeem the stolen code before it expires to log in as the victim. In a compliant flow the token request must reuse the original redirect_uri, and client authentication and PKCE can still block redemption — so this works only where those protections are missing.
  • Missing or unchecked state: login CSRF. Start the flow with your account, capture the callback URL and make the victim visit it → their browser ends up logged into your account (useful so they enter data you later read).
  • Forced account linking: if the client lets a social login be linked to an existing account without state, you force the victim’s account to be linked to your social identity → you log in as them.

If the client creates or merges accounts by email without verifying it, register with the victim’s email before they use “Sign in with…”. When she federates, the client (relying party) joins her federated identity to your pre-existing account and you share access — the merge happens at the client, not the IdP.

Two variants of the same mistake:

  • Reverse: the attacker signs in through a federated provider that lets them use an email they haven’t verified; when the victim later signs in with her password, the application merges both identities.
  • Session: even if the merge voids the attacker’s password, their earlier session or refresh token stays alive because linking doesn’t invalidate the account’s existing sessions.

The common defense: only merge on emails verified on both sides, require re-authentication when linking and invalidate previous credentials and sessions. More account cases in business logic.

Without PKCE the code loses its binding to the request that created it, so an intercepted code can be redeemed by the attacker — unless a confidential client still enforces client_secret authentication. Try omitting code_challenge or exchanging a code without the right verifier.

Check what the client validates on the id_token: iss, aud, nonce, signature and exp. If it accepts alg:none, algorithm confusion or a jwks_uri you control, you forge an id_token (see JWT attacks); a manipulable jwks_uri often chains with SSRF.

  • Signature not validated or validated on the wrong part → forged assertions.
  • XML Signature Wrapping (XSW): restructure the XML so a signed node is validated and an injected one is processed.
  • NameID / comment injection and XXE in the parser (see XXE).

Burp Suite with EsPReSSO (SSO analysis), SAML Raider (manipulate and re-sign assertions), and your own server to capture leaked code/token.

Direct ATO, API access with the stolen token (combine with IDOR/BOLA and API security), and compromise of the whole corporate SSO.

  • Authorization requests with redirect_uri outside the registered list or with normalization anomalies (.., @, %2e, or an authority-relative value beginning with //) — parse the URL rather than substring-matching //, which appears in every normal https:// URI.
  • Missing state/PKCE; id_token with wrong iss/aud/nonce.
  • Spikes of account linkings or code exchanges from anomalous IPs/UAs.
  • SAML assertions with invalid signatures or anomalous structure (XSW).

IdP and OAuth-client logs (authorization requests and token exchanges), WAF, and token/assertion validation.

  1. Exact-match redirect_uri (full allow-list, no wildcards or prefix/suffix matching).
  2. Mandatory state bound to the session + PKCE on all flows; use authorization code, never implicit.
  3. Validate iss, aud, nonce, exp and signature of the id_token; fixed, trusted jwks_uri.
  4. Verify the email before merging accounts; require re-authentication to link a social login.
  5. SAML: validate the signature strictly (schema + canonicalization), disable DTD (anti-XXE) and use libraries robust against XSW.

Invalidate issued sessions and tokens, fix callback validation, and review suspicious account linkings and code exchanges.

  • XML Signature Wrapping in SAML — a flaw class that hit multiple enterprise SSO products and SDKs for years (implementations that validated one node and processed another).
  • “Sign in with…” misconfigurations — lax redirect_uri/state and email-based account merging without verification have produced many ATOs reported in bug bounty; they rarely get a CVE because they’re client-specific.
  • alg:none / id_token confusion — when the OIDC client delegates validation to a vulnerable JWT library (see JWT).

Product-specific CVEs in NVD (https://nvd.nist.gov/vuln/search) and GitHub Advisories (https://github.com/advisories).

  • redirect_uri validation (suffix, prefix, userinfo, path traversal, chained open redirect).
  • state present and validated; PKCE required; implicit disabled.
  • code/token leak via Referer, logs or fragment.
  • Account linking without state and pre-ATO via unverified email.
  • id_token: iss/aud/nonce/signature and jwks_uri (see JWT).
  • SAML: signature, XSW, NameID injection, XXE in the parser.
  • Impact proven (ATO) with a minimal PoC and without touching real third-party accounts.