Cybersecurity/saml failure modes

From Cramsession
Revision as of 06:44, 25 November 2026 by Mflavell (talk | contribs) (→‎The Classic Trade-Off: mTLS vs. OAuth/JWT at Scale)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search
✍️ Verified Author: Mflavell • Click to view professional profile & credentials

SAML 2.0 Failure Modes (XML & Assertion Trust)

SAML relies on XML Digital Signatures (XMLDSig) and browser-mediated redirects. Most critical failures stem from the gap between what the XML signature verifier checks and what the application parser actually extracts.

Failure Mode How It Breaks First-Principles Fix
XML Signature Wrapping (XSW) An attacker copies a legitimately signed <Assertion>, moves it to another element in the XML tree, and injects an unsigned, forged <Assertion> (e.g., admin@company.com) where the app looks for it. The verifier validates the real signature, while the app reads the forged assertion. Validate against a strict XML schema before signature verification; ensure the application extracts identity strictly from the exact DOM nodewhose ID was cryptographically verified.
XML Comment Injection The app parses NameID as user@company.com.evil.com. If the XML parser strips comments before lookup, user@company.com.evil.com can authenticate as user@company.com while the original signature remains valid. Canonicalize XML properly (C14Nwithout comments) or reject assertions containing XML comments inside NameID and attribute elements.
Assertion Replay An attacker captures a valid SAML Response (via logs, XSS, or MITM) and replays it to the Assertion Consumer Service (ACS) endpoint to mint a new session. Enforce short NotOnOrAfter windows, track consumed Assertion IDs in a distributed cache until expiration, and validate InResponseTo matches an active SP-initiated request ID (avoid IdP-initiated SSO where possible).
Audience / Recipient Confusion An assertion issued for App A is replayed against App B (which shares the same IdP). If App B only checks the IdP's signature, it accepts App A's token. Strictly validate <Audience> (matches this SP's EntityID) and <Recipient>(matches this exact ACS URL).
XXE / Parser Abuse A misconfigured XML parser resolves external entities (<!DOCTYPE ...>) during SAML ingestion, leading to SSRF or local file disclosure. Disable DTDs and external entity resolution completely at the XML parser layer.


OAuth 2.0 & OIDC Failure Modes (RFC 9700 / Modern Standard)

OAuth 2.0 is delegated authorization; OIDC adds an authentication layer (id_token JWT) on top. Under the current RFC 9700 security best practice, older flows (Implicit Grant and Resource Owner Password Credentials) are deprecated.

Failure Mode How It Breaks First-Principles Fix
Open Redirect / Loose redirect_uri Using wildcard or prefix matching on redirect_uri lets an attacker redirect the authorization code (or token) to an attacker-controlled URL or an open redirector on the same domain, enabling account takeover. Enforce exact string matching against pre-registered redirect_uri values. No wildcards, no path traversal.
Auth Code Interception & Injection In public clients (SPAs, mobile) or shared environments, an attacker intercepts the authorization code in transit/history and exchanges it for tokens—or injects their own code into a victim's session. Mandate Authorization Code + PKCE (S256) for all clients (both public and confidential). The attacker cannot redeem the code without the client's code_verifier.
OAuth CSRF (Login CSRF) Missing or unvalidated state lets an attacker force a victim's browser to complete an OAuth callback tied to the attacker's account (linking the victim's activity or payment method to the attacker). Bind the authorization request to the user's browser session via an unguessable, per-request state parameter (or PKCE binding) and validate it strictly on callback.
IdP Mix-Up Attack When a client supports multiple IdPs, an attacker tricks the client into sending an authorization code issued by an honest IdP to a malicious IdP's token endpoint. Verify the iss (issuer) parameter returned in the authorization response matches the exact authorization server that initiated the flow (RFC 9207 / RFC 9700).
JWT / OIDC Validation Flaws Accepting "alg": "none", algorithm confusion (signing an HS256 token with the server's public RSA key), failing to check aud/iss/exp/nonce, or trusting an OAuth access_token as proof of user login. Pin allowed algorithms server-side (never trust the JWT header's alg), validate iss, aud, exp, and nonce (for OIDC replay defense), and never use an access token for authentication.
Bearer Token Replay Standard OAuth access tokens are bearer tokens—anyone who steals one (via XSS, leaked logs, or compromised proxy) can replay it until it expires. Keep access tokens short-lived, use refresh token rotation with reuse detection (revoking the whole token family on reuse), and adopt sender-constrained tokens (DPoP or mTLS-bound tokens) for high-value APIs.

mTLS & PKI Failure Modes (At Massive Scale)

In mTLS, both client and server present X.509 certificates during the TLS 1.3 handshake. The cryptography rarely breaks—certificate lifecycle management, revocation, and identity enforcement are where systems fail.

Failure Mode How It Breaks First-Principles Fix
Broken Revocation (CRL / OCSP) CRLs grow too large to fetch reliably; OCSPadds handshake latency, leaks privacy, and relies on soft-fail (if an attacker blocks the OCSP responder, the client accepts the revoked cert anyway—which is why major CAs like Let's Encrypt ended OCSP support). For internal mTLS, replace revocation with short-lived certificates (1 to 24 hours) via automated issuance (SPIFFE/SPIRE or service mesh). If a key leaks, the blast radius expires automatically.
CA as a Single Point of Failure (Thundering Herd) Short-lived certs dramatically multiply issuance volume. If the internal CA suffers an outage or rate-limits during a cluster restart, valid workloads cannot renew certs and trigger a cascading production outage. Run highly available, regionally distributed intermediate CAs, use staggered jittered renewals (renew at ~50% TTL), and decouple workload runtime from CA reachability for the remaining cert lifetime.
AuthN Confused with AuthZ A service verifies that the client cert is signed by the internal CA, but never checks who the client is. Any compromised low-privilege microservice with a valid org cert can now call the payments database. Always extract and enforce authorization against the SAN / SPIFFE ID (e.g., spiffe://prod.internal/ns/checkout/sa/api) rather than just trusting the CA chain.
Proxy / Edge Header Spoofing An L7 load balancer terminates mTLS and passes the client identity downstream in a header (e.g., X-Forwarded-Client-Cert). If the edge fails to strip attacker-supplied headers—or an internal caller bypasses the edge—attackers spoof any identity. Strip and overwrite identity headers unconditionally at the trust boundary, and enforce network-level isolation (or end-to-end mTLS) so backends only accept traffic from the trusted proxy.
Clock Skew & Silent Expiry Short-lived certs have tight NotBefore/NotOnOrAfter windows; NTP drift causes immediate handshake failures. Meanwhile, static certs outside the mesh (DBs, legacy LBs) silently expire and cause outages. Enforce strict NTP synchronization across nodes, build small grace windows into NotBefore, and maintain automated inventory/alerting across the entire certificate estate—not just the service mesh.

The Classic Trade-Off: mTLS vs. OAuth/JWT at Scale

How would you authenticate service-to-service traffic across 10,000 microservices? - frame it around layering, latency, and delegation:

  • mTLS (Transport-Layer Workload Identity): Best for hop-by-hop, machine-to-machine authentication. It proves Service A is talking directly to Service B with zero extra network round trips per request once the TLS session is established, and eliminates static bearer secrets. Limitation: Identity terminates at L7 proxies/load balancers and does not naturally carry end-user context across multi-hop call chains (Service A ➡️ Service B ➡️ Service C).


  • OAuth / Signed JWTs (Application-Layer Delegation): Best for end-user context, fine-grained scopes, and multi-hop propagation across L7 boundaries. Limitation: Standard JWTs are bearer tokens vulnerable to replay if leaked, and revocation requires either very short TTLs or stateful introspection (which adds latency and a central bottleneck).


  • Defense in Depth: Combine both—use mTLS with short-lived SPIFFE SVIDs for transport-level workload identity, paired with short-lived, sender-constrained / attenuated tokens (binding the token to the mTLS cert or using Google-style ALTS + end-user context tickets) so a compromised intermediate service cannot replay a user's full privileges elsewhere.