Most single sign-on breakages are not protocol weaknesses but relying party code that skips one validation step, and SAML and OpenID Connect (OIDC) fail in remarkably similar ways. This list ranks the ten implementation flaws a code reviewer is most likely to find when an application consumes SAML assertions or OIDC ID tokens, from signature handling through to how the user account is finally looked up. Each entry names the flaw in both protocols, what to look for in code or configuration, and the fix. It is written for developers, application security reviewers and penetration testers working on service providers and relying parties, not identity provider operators. For protocol background see the SAML Security Guide and OAuth 2.0 vs OIDC; for authorisation server and token risks see Top 10 OAuth Security Risks.
The Top 10 at a glance
| Rank | Flaw | SAML form | OIDC form | Typical impact |
|---|---|---|---|---|
| 1 | Signature checked on the wrong data | XML signature wrapping, comment truncation, tag-name element lookup | Claims read from a token before or without verification | Log in as any user |
| 2 | Unsigned or downgraded tokens accepted | Unsigned Response or Assertion accepted, SHA-1 allowed | alg "none", RSA to HMAC confusion, no algorithm allowlist | Forged identity |
| 3 | Trusting keys supplied in the message | Certificate in KeyInfo used for verification | jwk, jku, x5u or kid header followed without allowlist | Forged identity, SSRF |
| 4 | Missing audience binding | AudienceRestriction not checked | aud not checked against client_id, azp ignored | Token for another app accepted |
| 5 | Missing issuer binding and IdP mix-up | Issuer not tied to the tenant or connection | iss not matched exactly, no mix-up defence | Cross-tenant or cross-IdP login |
| 6 | Replay and freshness gaps | No InResponseTo, no assertion ID cache, loose time window | nonce missing or unchecked, exp and iat skew too wide | Captured token reused |
| 7 | Missing recipient and destination checks | Destination and Recipient not matched to ACS URL | Hybrid flow c_hash and at_hash not checked | Token or code substitution |
| 8 | Loose redirect and RelayState handling | RelayState used as an unvalidated URL | Pattern-matched redirect_uri, open redirect after login | Token or code theft, phishing |
| 9 | Login CSRF and unsafe flows | IdP-initiated SSO enabled without need | No state or PKCE, implicit flow still in use | Victim logged into attacker account |
| 10 | Identity mapped from mutable claims | Email attribute or transient NameID used as the key | email or preferred_username used instead of iss plus sub | Account takeover via another IdP or reused address |
The ranking weighs how often the flaw appears in reviews against impact: the first three lead directly to authentication bypass with no user interaction, so they come first even where they are less common than redirect mistakes.
1. Signature checked on the wrong data
The signature verifies, but the application reads identity from a different element or a different parse of the message. In SAML this is XML signature wrapping: an attacker moves the signed assertion and adds an unsigned one that the application's lookup finds first. A related class, documented by CERT/CC in VU#475445 (2018), affected several SAML libraries where XML comments inside a NameID caused text after the comment to be dropped by one API and kept by another, so content could be changed without breaking the signature.
- Look for: getElementsByTagName or relative XPath to find the Assertion or NameID; signature verification and attribute extraction done by different libraries or parsers; schemas fetched from remote locations.
- Fix: select elements with absolute XPath or use the library's "verified assertion" object only; confirm the signature Reference URI points to the exact Response or Assertion you consume; schema-validate against local, hardened schemas, as the OWASP SAML Security Cheat Sheet advises; keep SAML libraries patched.
- OIDC equivalent: decoding the JWT payload for routing or logging and later trusting those claims without verification. Verify first, then read claims only from the verified result.
2. Unsigned or downgraded tokens accepted
The relying party accepts a token that is not signed, or is signed with an algorithm it should not allow.
- SAML: accepting a Response where neither the Response nor the Assertion is signed, or accepting SHA-1 signatures and digests. The OWASP cheat sheet recommends rejecting SHA-1 and requiring at least RSA-SHA256.
- OIDC: accepting alg "none", or letting the token header choose the algorithm so an RSA public key is used as an HMAC secret. RFC 8725 (JWT Best Current Practices, BCP 225) section 3.1 requires libraries to let callers specify allowed algorithms and to use each key with exactly one algorithm. OIDC Core forbids "none" for ID tokens unless the client explicitly registered for it and receives no ID token from the authorisation endpoint.
- Look for: verify calls without an algorithm parameter, a shared verification function used for several token types, configuration flags such as "want assertions signed" set to false.
- Fix: pin the expected algorithm per issuer (the one registered as id_token_signed_response_alg, or RS256 by default), and require signatures on every assertion you consume.
3. Trusting keys supplied in the message
A signature is only meaningful if the verifying key comes from configuration, not from the attacker.
- SAML: verifying with the X.509 certificate embedded in KeyInfo rather than the pinned IdP certificate from metadata. A self-signed certificate then "verifies" a forged assertion.
- OIDC: following the jku or x5u header to fetch keys, accepting an embedded jwk, or passing kid unsanitised into a file path or database query. RFC 8725 section 3.10 calls for sanitising kid and allowlisting jku and x5u URLs, which also prevents server-side request forgery.
- Fix: load keys only from the issuer's configured metadata or JWKS URI, cache them, and refresh on unknown kid from that same trusted URI. Plan key rollover so the pinned set includes the next certificate. See How to rotate a SAML signing certificate in Entra ID without breaking SSO.
Stolen or attacker-added signing keys are a separate, IdP-side problem: see the Golden SAML and Federation Trust Abuse Defence Guide.
4. Missing audience binding
A validly signed token issued to a different application is accepted. Where one IdP signs tokens for many applications with the same key, this turns any low-value app into a source of tokens for high-value ones.
- SAML: the Audience inside AudienceRestriction must equal your SP entity ID.
- OIDC: OIDC Core section 3.1.3.7 requires the aud claim to contain the client's client_id and the token to be rejected if it lists audiences the client does not trust; when azp is present the client should check it equals its client_id. OWASP ASVS 5.0 V10.5.4 states the same requirement.
- Look for: audience checks disabled to "fix" an integration error, or an allowlist containing several client IDs from different applications.
5. Missing issuer binding and IdP mix-up
Multi-tenant and multi-IdP applications must tie each response to the issuer the login started with.
- SAML: the Issuer must match the IdP configured for this connection or tenant, and the signing key must belong to that IdP. Checking that "some trusted IdP" signed it lets tenant A's IdP log in users of tenant B.
- OIDC: the iss claim must exactly match the issuer from discovery. Clients using more than one authorisation server need a mix-up defence: RFC 9700 (OAuth 2.0 Security BCP, BCP 240) prefers checking the issuer, via the iss authorisation response parameter from RFC 9207 or the ID token iss claim, with distinct redirect URIs per issuer as a fallback. RFC 9207 states clients must reject a response whose iss does not match the expected issuer.
- Look for: a single global key set across tenants, issuer compared with "startsWith" or case-insensitively, issuer looked up from the token rather than from the login session. ASVS 5.0 V6.8.1 covers spoofing via another supported IdP.
6. Replay and freshness gaps
- SAML: check InResponseTo against the request ID stored in the user's session, enforce NotBefore and NotOnOrAfter with small clock skew, and keep a cache of consumed assertion IDs for the validity period. ASVS 5.0 V6.8.3 requires SAML assertions to be processed only once within their validity period.
- OIDC: send a nonce bound to the session and require the ID token nonce to match (OIDC Core 3.1.3.7; ASVS 5.0 V10.5.1); reject expired tokens and set a client-specific iat window; check auth_time when you sent max_age.
- Look for: nonce generated but never compared, clock skew set to hours, assertion ID caches that are per-node in a load-balanced cluster.
7. Missing recipient and destination checks
- SAML: the Response Destination must exactly match your Assertion Consumer Service URL, and the SubjectConfirmationData Recipient must match too; reject when either is missing or different. Without these, an assertion captured at one SP of the same IdP may be replayed at another.
- OIDC: in the hybrid flow, validate c_hash against the authorisation code and at_hash against any access token returned from the authorisation endpoint, which binds them to the ID token and stops substitution.
- Look for: ACS URLs compared after normalisation that strips paths or ports; hybrid response types enabled with no hash checks.
8. Loose redirect and RelayState handling
- OIDC and OAuth: RFC 9700 says authorisation servers should compare redirect URIs by exact string match (with a port exception for native app localhost redirects), and ASVS 5.0 V10.4.1 requires a client-specific allowlist with exact comparison. On the relying party, the post-login return URL must not be an open redirect that leaks codes or tokens via the Referer or fragment.
- SAML: RelayState that carries a URL must be validated against an allowlist, as the OWASP cheat sheet advises, or replaced with an opaque key to server-side state.
- Look for: wildcard or prefix redirect patterns, a "returnUrl" parameter passed straight to a redirect. See the Open Redirect Guide.
9. Login CSRF and unsafe flows
- OIDC: use the authorisation code flow with PKCE (S256), and a state value bound to the browser session; RFC 9700 recommends PKCE for confidential clients too and says clients should not use the implicit grant. If the server does not support PKCE, state or nonce must provide CSRF protection. See Client Secret vs PKCE.
- SAML: IdP-initiated SSO has no request to correlate, so it lacks login CSRF protection. Disable it unless a business need exists, and then apply the extra checks in the SAML 2.0 Profiles specification section 4.1.5 that the OWASP cheat sheet points to.
- Look for: state that is static, predictable or not compared; response_type values containing "token" in new code.
10. Identity mapped from mutable claims
Validation can be perfect and the application still log the wrong person in if it keys accounts on a value that can change or be asserted by another IdP.
- OIDC: OIDC Core defines sub as locally unique and never reassigned within the issuer, so iss plus sub identifies the user. ASVS 5.0 V10.5.2 requires the client to identify the user from a claim that cannot be reassigned, usually sub. Matching on email lets anyone who can get an IdP to assert that address, or who later receives a recycled address, take over the account.
- SAML: use a persistent NameID or an immutable attribute agreed with the IdP, scoped to the issuer; never a transient NameID or display name.
- Look for: account linking by email across IdPs without re-authentication, user tables with email as primary key, just-in-time provisioning that merges into existing accounts.
Mapping to OWASP
| Flaw | OWASP ASVS 5.0 requirement | Other OWASP source |
|---|---|---|
| 1. Signature on wrong data | V6.8.2 (signature presence and integrity), V9.1.1 | SAML Security Cheat Sheet (XSW, absolute XPath, local schemas) |
| 2. Unsigned or downgraded | V6.8.2, V9.1.2 (algorithm allowlist) | SAML Security Cheat Sheet (reject SHA-1) |
| 3. Keys from the message | V9.1.3 (trusted pre-configured key sources) | SAML Security Cheat Sheet (pinned IdP certificates) |
| 4. Audience | V10.5.4, V9.2.3 | SAML Security Cheat Sheet (Audience) |
| 5. Issuer and mix-up | V6.8.1, V10.2.2, V10.5.3 | Covered by ASVS requirements |
| 6. Replay and freshness | V6.8.3, V10.5.1, V9.2.1 | SAML Security Cheat Sheet (InResponseTo, time window) |
| 7. Recipient and destination | V9.2.2 (correct type and purpose) | SAML Security Cheat Sheet (Destination, Recipient) |
| 8. Redirect and RelayState | V10.4.1 | SAML Security Cheat Sheet (RelayState allowlist) |
| 9. Login CSRF and flows | V10.2.1, V10.4.4, V10.4.6 | SAML Security Cheat Sheet (IdP-initiated SSO) |
| 10. Mutable identity claims | V10.5.2 | Covered by ASVS requirements |
In the OWASP Top 10 these flaws sit under identification and authentication failures; on APIs that accept ID tokens directly, see the OWASP API Top 10 API2 Broken Authentication Guide.
Testing and detection
| Test case | Expected result | Covers |
|---|---|---|
| Modify a claim or NameID after signing | Rejected | 1, 2 |
| Strip the signature, or change alg to none or HS256 | Rejected | 2 |
| Sign with a key not in configuration and embed it | Rejected | 3 |
| Valid token issued to another app of the same IdP | Rejected | 4 |
| Valid token from a second trusted IdP or tenant | Rejected for this connection | 5 |
| Replay a consumed assertion or ID token; wrong or missing nonce | Rejected | 6 |
| Assertion with a different Destination or Recipient | Rejected | 7 |
| Off-allowlist redirect_uri or RelayState | Rejected, no redirect | 8 |
| Response without matching state, or unsolicited SAML response | Rejected | 9 |
| Second IdP asserting an existing user's email | No access to existing account | 10 |
Run these as automated negative tests in CI against the relying party, using test IdPs and test keys only. In production, log every rejection with the reason (signature, audience, issuer, replay, destination) and alert when a single reason spikes or when a new issuer or signing certificate appears. Useful measures: share of relying parties with the full negative test suite passing; count of applications still using implicit or IdP-initiated flows; count keyed on email rather than iss plus sub; median days to patch SAML and JWT libraries after an advisory.
Where to start
- Inventory relying parties and record for each: protocol, library and version, flows enabled, and the claim used as the account key.
- Patch libraries first: many entries above have historically appeared as library bugs, so current versions remove a large share of the risk.
- Review entries 1 to 3 in code for every service provider and relying party, since they allow login as anyone.
- Add the negative test table to CI so regressions fail the build.
- Disable unneeded flows: implicit grant, IdP-initiated SSO, unsigned assertions and SHA-1.
- Migrate account keys from email to issuer plus subject, with a one-off linking step that re-authenticates the user.
Practitioner checklist
- Read identity only from the verified assertion or token object.
- Pin algorithms and keys per issuer; ignore KeyInfo, jwk, jku and x5u from the message.
- Check audience, issuer, destination and recipient exactly, per connection.
- Enforce nonce, InResponseTo, assertion ID replay caches and tight time windows.
- Use exact redirect URI matching and allowlist any RelayState URL.
- Use code flow with PKCE and state; turn off implicit and unneeded IdP-initiated SSO.
- Key accounts on iss plus sub or a persistent NameID, never on email.
- Run the negative test suite in CI and alert on rejection spikes.
Standards and references
- OpenID Foundation: OpenID Connect Core 1.0
- IETF: RFC 9700, Best Current Practice for OAuth 2.0 Security
- IETF: RFC 8725, JSON Web Token Best Current Practices
- IETF: RFC 9207, OAuth 2.0 Authorization Server Issuer Identification
- OWASP: SAML Security Cheat Sheet
- OWASP: Application Security Verification Standard 5.0
- CERT/CC: VU#475445, SAML libraries and XML canonicalisation
Related NHI Mgmt Group resources: SAML Security Guide · Top 10 OAuth Security Risks · JWT Security Guide · OAuth 2.0 Security Best Current Practice (RFC 9700) Guide