XML Signature Wrapping (XSW)
debt(d7/e7/b5/t9)
Closest to 'only careful code review or runtime testing' (d7). The detection_hints list burpsuite and saml-raider as tools, but these are specialist penetration testing tools requiring active manual effort — not passive linters or static analyzers. The code_pattern requires identifying whether XPath position vs. signed reference is used, which demands careful code review or dedicated security testing. Automated detection is explicitly marked 'no' in the term metadata.
Closest to 'cross-cutting refactor across the codebase' (e7). The quick_fix describes a conceptual change (retrieve assertion by signed ID, not position), but common_mistakes reveal that custom XML signature validation code and incorrect library usage are often involved. Remediating this requires auditing all SAML assertion handling paths, potentially replacing custom validation logic with a well-audited library, verifying certificate pinning, and testing across authentication flows — this is a cross-cutting security refactor affecting authentication infrastructure throughout the codebase.
Closest to 'persistent productivity tax' (b5). The applies_to scope is web and API contexts, which is broad. Any team working with SAML authentication must continuously ensure they use the correct element-by-ID retrieval pattern, use well-maintained libraries, and pin IdP certificates. This imposes an ongoing review and testing burden on authentication-related work streams, though it doesn't necessarily shape every change in the system.
Closest to 'catastrophic trap — the obvious way is always wrong' (t9). The misconception field states explicitly: 'Verifying the XML signature is sufficient for SAML security.' A competent developer who has implemented XML signature verification will reasonably believe their validation is complete and correct, yet the attack succeeds precisely because the signature is valid — the flaw is in which element is processed after validation. The 'obvious' implementation (check signature passes → use the element) is exactly wrong, enabling full authentication bypass and admin impersonation.
Also Known As
TL;DR
Explanation
XML Signature Wrapping attacks exploit the difference between what is signed and what is processed. A SAML response contains a signed assertion. The attacker copies the original signed assertion, creates a new forged assertion, and wraps it: the signature still validates the original (copied) assertion, but the application processes the forged one placed earlier in the document. The fix: applications must process only the element that is referenced by the signature's ds:Reference, not just the first matching element. This class of attack compromised many SAML implementations including major SSO providers.
Common Misconception
Why It Matters
Common Mistakes
- Processing the first matching XML element rather than the element referenced by the signature.
- Using a SAML library that does not validate signature references correctly.
- Not pinning the IdP's signing certificate — allows key substitution attacks.
- Custom XML signature validation code — use a well-audited library instead.
Avoid When
- Never implement XML signature validation from scratch — the wrapping attack exploits subtle spec interpretations.
- Do not trust the signed element ID alone — verify the signature references the correct element in the expected position.
When To Use
- Validate XML signatures using a library that verifies the signature covers the entire document, not just a fragment.
- Use well-maintained SAML/XML-DSig libraries (e.g. php-saml, onelogin) rather than rolling your own signature validation.
Code Examples
// Vulnerable: processes first NameID in document, not the signed one:
$doc = new DOMDocument();
$doc->loadXML($samlResponse);
// Verify signature... passes (original still there)
$nameId = $doc->getElementsByTagName('NameID')->item(0)->textContent;
// But item(0) is the ATTACKER'S forged assertion, not the signed one!
$user = User::findByEmail($nameId); // attacker@evil.com becomes admin@company.com
// Use a library that handles XSW correctly:
// php-saml, simplesamlphp, or lasso
// They validate that:
// 1. Signature is valid
// 2. The signed element is the EXACT element processed
// 3. No unsigned elements precede the signed assertion
use OneLogin\Saml2\Auth;
$auth = new Auth($settings);
$auth->processResponse();
if (!$auth->isAuthenticated()) throw new AuthException($auth->getLastErrorReason());
$nameId = $auth->getNameId(); // Library ensures this is from the signed assertion