Two Names, One Signature: Decoding a Forged SAML Login
The challenge
A contractor's SSO login opened an admin session. Decode the SAML login and check what is signed. Name the account the attacker logged in as.
What you'll learn
- Decode a SAMLResponse from a form POST (URL encoding, then base64)
- Read the structure of a SAML 2.0 Response and its assertions
- Use the ds:Reference URI to tell which element a signature covers
- Explain XML Signature Wrapping and the 2025 ruby-saml parser bugs
- List the checks a service provider needs to stay safe
Skills tested
Prerequisites
- What single sign-on is
- What base64 is
How it works
In SAML single sign-on, the identity provider sends the browser an XML Response that the browser POSTs to the application as SAMLResponse, base64-encoded and then URL-encoded. Inside, an Assertion names the user in its NameID, and an XML signature proves the identity provider issued it.
An XML signature does not protect the element it sits in. It protects the element whose ID its ds:Reference URI names. If the application verifies a signature but then reads a different element, an attacker who holds any validly signed login can add an unsigned assertion with another name. That is XML Signature Wrapping.
In March 2025, CVE-2025-25291 and CVE-2025-25292 showed a twist in ruby-saml (used by GitLab and many Rails apps): it parsed the document with two XML parsers, REXML and Nokogiri, which could disagree, so the verified element and the element used for login were not the same.
Common mistakes
- Answering [email protected]. That is the assertion the signature really covers: the contractor's own, legitimate login. The attacker already had it.
- Trusting where the Signature sits. The Signature element is inside the second assertion, but its Reference URI points at the first. Position proves nothing.
- Pressing base64 first.
%2Band%3Dare URL encoding, which has to come off before base64 decodes.
How to defend against it
- Keep the SAML library patched: for ruby-saml, 1.12.4 and 1.18.0 fix the 2025 parser bugs (update omniauth-saml with it).
- After verifying, take the NameID and attributes only from the element the verified Reference points at, from the same parsed tree.
- Reject responses with more than one assertion, unexpected elements or a DOCTYPE, and validate them against the SAML schema.
- Require signed assertions from the IdP, and check Audience, Recipient, InResponseTo and the time window.