Skip to main content

Free 30-min security demo  — We'll scan your real code and show live findings, no commitment Book Now

Offensive360
Academy SAML Vulnerabilities
Advanced · 25 min

SAML Vulnerabilities

Understand XML signature wrapping attacks and comment injection that bypass SAML authentication.

1 SAML Attack Techniques

SAML (Security Assertion Markup Language) is used for SSO in enterprise environments. Its XML-based structure creates several unique attack vectors.

XML Signature Wrapping (XSW):

SAML responses are XML-signed. A wrapping attack duplicates the signed assertion and adds a malicious assertion. Vulnerable parsers process the signed (legitimate) assertion for signature verification but then use the malicious (unsigned) assertion for authorization.

<!-- Original signed assertion for user: [email protected] -->
<SAMLResponse>
  <SignedAssertion>[email protected]...<Signature>...</Signature></SignedAssertion>
  <!-- Injected malicious assertion (unsigned) -->
  <Assertion>[email protected]...</Assertion>
</SAMLResponse>

Comment injection attack:

<!-- Injected comment in username attribute -->
<NameID>admin<!--comment-->@attacker.com</NameID>
<!-- Some parsers strip comments before processing,
     resulting in: [email protected] → "admin" -->

2 Secure SAML Implementation

Use vetted SAML libraries that handle these edge cases correctly, and enforce strict schema validation.

Key defensive requirements:

  • Use a library with a strong security track record (OneLogin, python-saml, Spring Security SAML)
  • Keep the library updated — most XSW vulnerabilities are patched in library updates
  • Validate the signature against the correct element ID — do not allow any signed element to satisfy the assertion verification
  • Strip XML comments before processing NameID values
  • Canonicalize XML before signature verification to prevent normalization attacks

Configuration validation (python-saml):

settings = {
    "strict": True,  # Enforce strict security validation
    "security": {
        "wantAssertionsSigned": True,
        "wantMessagesSigned": True,
        "signatureAlgorithm": "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",
        "digestAlgorithm": "http://www.w3.org/2001/04/xmlenc#sha256",
    }
}

Defense checklist:

  • Use an actively maintained SAML library, never roll your own
  • Enable strict mode in SAML library settings
  • Require assertions to be signed (wantAssertionsSigned)
  • Validate signatures against specific assertion IDs
  • Strip comments from NameID before processing

Knowledge Check

0/3 correct
Q1

What is the core mechanic of an XML Signature Wrapping (XSW) attack?

Q2

How does the XML comment injection attack affect NameID processing?

Q3

What is the single most important practice for SAML security?

Code Exercise

Enable Strict SAML Validation

The SAML settings below have strict mode disabled and do not require signed assertions. Enable strict mode and require both assertions and messages to be signed.

python