OAuth / SAML / SSO
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)
Threat model
Section titled “Threat model”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.
Anatomy
Section titled “Anatomy”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).
Variants
Section titled “Variants”redirect_uribypass — divert thecode/tokento an attacker domain.code/tokenleak — viaReferer, 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
codewith nocode_verifier. id_tokenflaws —iss/aud/nonceunvalidated, JWT confusion, SSRF viajwks_uri.- SAML — signature not validated, XML Signature Wrapping, NameID injection, XXE.
Red Team
Section titled “Red Team”Discovery
Section titled “Discovery”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.
redirect_uri bypass
Section titled “redirect_uri bypass”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 onehttps://attacker.tld/app.tld/callback # attacker host, mimicking pathhttps://app.tld@attacker.tld/callback # userinfo: real host is attacker.tldhttps://app.tld/callback/../../redirect # path traversal / normalizationhttps://app.tld/callback?x=https://attacker.tld # appended parameter//attacker.tld # protocol-relativehttps://app.tld/callback%2f%2e%2e%2f # encoding to slip past the matcherAn 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).
Stealing the code/token
Section titled “Stealing the code/token”Referer: if the callback page loads external resources and uses a permissive referrer policy, thecodein the URL leaks in theRefererheader. 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
tokensits after#; any URL leak exposes it. - Dangling markup / open redirect in the flow: exfiltrate the URL carrying the
code. - Redeem the stolen
codebefore it expires to log in as the victim. In a compliant flow the token request must reuse the originalredirect_uri, and client authentication and PKCE can still block redemption — so this works only where those protections are missing.
state / CSRF and account linking
Section titled “state / CSRF and account linking”- 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.
Pre-account-takeover
Section titled “Pre-account-takeover”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.
Missing or downgraded PKCE
Section titled “Missing or downgraded PKCE”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.
OIDC / id_token
Section titled “OIDC / id_token”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).
Tooling
Section titled “Tooling”Burp Suite with EsPReSSO (SSO analysis), SAML Raider (manipulate and re-sign
assertions), and your own server to capture leaked code/token.
Impact and chaining
Section titled “Impact and chaining”Direct ATO, API access with the stolen token (combine with IDOR/BOLA and API security), and compromise of the whole corporate SSO.
Blue Team
Section titled “Blue Team”Detection
Section titled “Detection”- Authorization requests with
redirect_urioutside 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 normalhttps://URI. - Missing
state/PKCE;id_tokenwith wrongiss/aud/nonce. - Spikes of account linkings or
codeexchanges from anomalous IPs/UAs. - SAML assertions with invalid signatures or anomalous structure (XSW).
Telemetry and sources
Section titled “Telemetry and sources”IdP and OAuth-client logs (authorization requests and token exchanges), WAF, and token/assertion validation.
Hardening
Section titled “Hardening”- Exact-match
redirect_uri(full allow-list, no wildcards or prefix/suffix matching). - Mandatory
statebound to the session + PKCE on all flows; use authorization code, never implicit. - Validate
iss,aud,nonce,expand signature of theid_token; fixed, trustedjwks_uri. - Verify the email before merging accounts; require re-authentication to link a social login.
- SAML: validate the signature strictly (schema + canonicalization), disable DTD (anti-XXE) and use libraries robust against XSW.
Response
Section titled “Response”Invalidate issued sessions and tokens, fix callback validation, and review suspicious
account linkings and code exchanges.
CVEs and real-world cases
Section titled “CVEs and real-world cases”- 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/stateand 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_tokenconfusion — 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).
Testing checklist
Section titled “Testing checklist”-
redirect_urivalidation (suffix, prefix, userinfo, path traversal, chained open redirect). -
statepresent and validated; PKCE required; implicit disabled. -
code/token leak viaReferer, logs or fragment. - Account linking without
stateand pre-ATO via unverified email. -
id_token:iss/aud/nonce/signature andjwks_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.