# The Fragile Lock: Novel Bypasses For SAML Authentication

Ruby-SAML and php-saml accept forged SAML assertions via parser-differential XSW, namespace confusion, and void canonicalization, enabling full authentication bypass.

- Payout: Research
- Severity: critical
- Program: Ruby-SAML
- Write-up by: PortSwigger Research
- Disclosed: 2025-12-10
- CVE: CVE-2025-66568, CVE-2025-66567
- Write-up quality: 9/10
- Original: https://portswigger.net/research/the-fragile-lock
- Library page: https://bugbountylibrary.com/r/blog%3Aportswigger-net-research-the-fragile-lock
- Tags: area:web domain:web impact:ato impact:privesc kind:research platform:research sev:critical tech:saml technique:chained technique:parser-differential vuln:access-control vuln:auth-bypass

**Target:** SAML Service Provider signature validation (Ruby-SAML, php-saml, xmlseclibs)
**Root cause:** Signature verification (REXML) and assertion processing (Nokogiri/libxml2) use separate parsers with inconsistent namespace/attribute handling; libxml2 canonicalization returns empty string on relative-URI errors, so digest is computed over empty input.
**Steps:**
1. Obtain any IdP-signed XML (signed metadata via `?sign=true`, signed error response to malformed AuthnRequest, or WS-Fed metadata).
2. Place the real enveloped Signature inside an Extensions/StatusDetail extension point wrapped in `<Parent xmlns='http://www.w3.org/2000/09/xmldsig#'><Child xml:xmlns='#other'>` so Nokogiri sees it but REXML hides it.
3. Add a fake Signature inside the malicious Assertion with DigestValue of empty string (`47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=` for SHA-256).
4. Declare a relative namespace `xmlns:ns="1"` to force libxml2 canonicalization error, making Nokogiri return empty string for the canonicalized input.
5. Use attribute pollution (`ID` vs `samlp:ID` ordering) so the signature Reference URI resolves to the attacker-controlled Assertion ID.
6. Submit forged Response to SP; signature validates against digest of empty string and attacker Assertion is consumed.
**How found:** Studied Ruby-SAML 1.12.4 patch (DTD/well-formedness checks) and noticed it didn't fix dual-parser architecture (REXML vs Nokogiri). Read libxml2 xmlGetProp docs noting namespace-ignoring attribute lookup, tested attribute ordering to confirm parser disagreement. Then examined XML Signature Recommendation warning on relative URIs and observed Nokogiri returns empty string on canonicalization error, yielding void digest.
**Exploitation:** Attacker needs only a publicly obtainable IdP-signed XML document (signed metadata, signed error response, or WS-Fed metadata). They graft that signature into an extension point, hide it from SAML processing via reserved xml namespace redeclaration, and place a fake Signature with empty-string digest in the Assertion. Relative namespace URI triggers libxml2 canonicalization failure returning empty string, so digest matches. Attribute pollution aligns the Reference URI with the malicious Assertion ID, yielding a Golden SAML Response that authenticates as any user.
**Escalation:** Chained with email-atom parser splitting to create a new account and bypass authentication in a large SaaS deployment.
**Insight:** When a library uses two XML parsers for signature vs. business logic, hunt for inputs where they disagree: duplicate attributes differing only by namespace prefix (order-dependent), reserved `xml:` prefix redeclaration to hide elements from one parser's XPath, and relative namespace URIs that make canonicalization silently return empty string so a precomputed empty-string digest validates.

## Proof of concept (copied exactly from the original report)

**Golden SAML Response with void canonicalization**

```
<samlp:Response xmlns:ns="1">
 <samlp:Extensions>
 <Parent xmlns="http://www.w3.org/2000/09/xmldsig#">
 <Child xml:xmlns="#other">
 <Signature>
 <SignedInfo>REAL SIGNATURE</SignedInfo>
 </Signature>
 </Child>
 </Parent>
 </samlp:Extensions>
 <Assertion>
 <Signature>
 <SignedInfo>EMPTY STRING DIGEST VALUE</SignedInfo
 </Signature>
 </Assertion>
</samlp:Response>
```

**Attribute pollution ID collision SAML response**

```
<samlp:Response ID="attack" samlp:ID="ID">
 <Signature>
 <Reference URI="#ID"/>
 </Signature>
 <samlp:Extensions>
 <Assertion ID="#ID"/>
 </samlp:Extensions>
 <Assertion ID="evil"/>
</samlp:Response>
```

**REXML namespace confusion hiding Signature**

```
<Parent xmlns='http://www.w3.org/2000/09/xmldsig#'>
 <Child xml:xmlns='#anything'>
 <Signature/>
 </ Child>
</Parent>
```

