SAML Response Replay and Reuse
What you'll learn: How attackers can intercept and reuse valid SAML responses to impersonate users, and how to prevent these replay attacks.
The Problem
Even if SAML signatures are valid and XML wrapping attacks are prevented, an attacker who intercepts a legitimate SAML response can potentially replay it to gain unauthorized access. Imagine finding someone's valid ticket stub—if the theater doesn't track which tickets have already been used, you could reuse that same ticket repeatedly.
How SAML Responses Can Be Replayed
When a user authenticates through SAML, the Identity Provider (IdP) sends a signed SAML assertion to the Service Provider (SP). If an attacker captures this response through network sniffing or XSS, they might attempt to:
- Replay the entire response to authenticate as the victim
- Reuse the assertion at a different time or from a different location
- Submit the response to a different recipient than intended
Defense Mechanisms
Assertion IDs: Every SAML assertion must contain a unique ID. The SP should track used IDs and reject any assertion with a previously seen ID. Think of this as marking ticket stubs as "used."
Timestamps: SAML assertions include NotBefore and NotOnOrAfter timestamps that define a validity window. The SP must strictly enforce these, typically allowing only a few minutes of validity to minimize replay risk.
Recipient Validation: The assertion should specify the intended recipient (SP). The SP must verify that it matches its own URL—rejecting responses meant for other services.
Together, these controls ensure that even if an attacker captures a valid SAML response, it becomes useless after first use, expires quickly, and cannot be redirected to unintended targets.
Key Takeaway: Prevent SAML replay attacks by maintaining a cache of used assertion IDs, strictly validating timestamp windows, and verifying the intended recipient matches your service.