← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

XML Signature Wrapping (XSW)

Security Advanced
debt(d7/e7/b5/t9)
d7 Detectability Operational debt — how invisible misuse is to your safety net

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.

e7 Effort Remediation debt — work required to fix once spotted

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.

b5 Burden Structural debt — long-term weight of choosing wrong

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.

t9 Trap Cognitive debt — how counter-intuitive correct behaviour is

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.

About DEBT scoring →

Also Known As

XSW SAML wrapping XML signature attack SAML vulnerability

TL;DR

An attack on XML digital signatures where the attacker wraps the signed element in a new structure — the signature validates the original but the application processes the attacker's version.

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

Verifying the XML signature is sufficient for SAML security — the signature must be verified AND the application must process the exact signed element, not just any element with the same name.

Why It Matters

XSW attacks allowed authentication bypass in major SAML implementations — an attacker could forge a SAML assertion claiming to be any user, including administrators, bypassing authentication entirely.

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
// 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
✓ Fixed
// 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

Added 16 Mar 2026
Edited 12 Jun 2026
Views 117
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings S 1 ping M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 2 pings S 0 pings M 1 ping T 1 ping W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M
No pings yet today
No pings yesterday
ChatGPT 15 Amazonbot 10 Google 8 SEMrush 7 Ahrefs 6 Perplexity 4 Bing 4 PetalBot 4 Unknown AI 3 Scrapy 3 Twitter/X 2 Brave Search 2 Applebot 2 Sogou 1
crawler 66 crawler_json 4 pre-tracking 1
DEV INTEL Tools & Severity
🔴 Critical ⚙ Fix effort: High
⚡ Quick Fix
Always validate SAML assertions by verifying the signature covers the assertion you're reading — retrieve the assertion by signed ID, not by position, to prevent signature wrapping attacks
📦 Applies To
any web api
🔗 Prerequisites
🔍 Detection Hints
SAML assertion accessed by XPath position not by signed reference; XML signature validation without verifying signed content matches parsed content
Auto-detectable: ✗ No burpsuite saml-raider
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: High Context: File Tests: Update
CWE-347 CWE-345

✓ schema.org compliant