Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

XML signatures and wrapping attacks

A SAML assertion is protected by an XML signature over one element, not over the whole message. This lesson follows the signature on Avery's assertion through the training service's check, then looks at the attacks that work when a service verifies one element and reads another, and at the tests a service provider runs to prove it refuses them.

A signature over part of a document

XML and XML signatures for identity showed how an XML signature works: a Reference names the signed element by its ID, transforms prepare it, a digest summarizes it, and SignatureValue signs SignedInfo, which holds the digest. Unlike a JSON Web Token, which is signed as one block of bytes, the rest of the document can change without affecting the signature. That flexibility lets one SAML response carry a signed assertion inside an unsigned envelope, and it is also behind the most serious family of SAML vulnerabilities.

Here is the signature from Avery's assertion in Reading an assertion, with long values shortened:

xml
<saml:Assertion ID="_c5e27a9f4d18" ...>
  <saml:Issuer>https://login.cedar.example</saml:Issuer>
  <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
    <ds:SignedInfo>
      <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
      <ds:SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"/>
      <ds:Reference URI="#_c5e27a9f4d18">
        <ds:Transforms>
          <ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/>
          <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"/>
        </ds:Transforms>
        <ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256"/>
        <ds:DigestValue>u5Qx0C9yPq4k...</ds:DigestValue>
      </ds:Reference>
    </ds:SignedInfo>
    <ds:SignatureValue>kF2b7LwQe8Rz...</ds:SignatureValue>
    <ds:KeyInfo><ds:X509Data><ds:X509Certificate>MIIDBzCCAe+g...</ds:X509Certificate></ds:X509Data></ds:KeyInfo>
  </ds:Signature>
  <saml:Subject>...</saml:Subject>
  ...
</saml:Assertion>

The signature sits inside the element it signs, the enveloped form. URI="#_c5e27a9f4d18" names the assertion itself. The enveloped-signature transform leaves the ds:Signature element out of what is hashed, and exclusive canonicalization, exc-c14n, rewrites the assertion into one standard byte form first, so that equivalent copies produce the same digest. The digest and signature use SHA-256 with RSA. KeyInfo carries Cedar Inc.'s certificate as a hint about which key was used.

In this response only the assertion is signed. The samlp:Response around it, with its own Destination and InResponseTo, has no signature, so those values are protected only by their copies inside the assertion, as Reading an assertion described.

How a verifier checks it

When the training service verifies Avery's assertion, its XML signature library follows these steps:

  1. Find the ds:Signature and read SignedInfo. Check that the algorithms are on the training service's allowed list.
  2. Resolve the Reference URI to an element in the document by its ID.
  3. Apply the transforms to that element and hash the result. The hash must equal DigestValue.
  4. Canonicalize SignedInfo and verify SignatureValue over it with Cedar Inc.'s public key from the metadata the two organizations exchanged.

The key in step 4 comes from that metadata, never from KeyInfo. The certificate in KeyInfo was put there by whoever made the document, so trusting it would let anyone sign with their own key and include their own certificate. A library may use KeyInfo to choose among the keys it already trusts, nothing more. Metadata, certificates, and key rollover covered where those trusted keys come from and how they change.

Look closely at what a successful result means. It does not mean "this document is authentic". It means "the element with ID _c5e27a9f4d18, after these transforms, was signed by this key". Everything outside that element, and any other element that happens to look like an assertion, is unprotected. The security of the whole sign-in depends on the training service using exactly the element the signature covered.

Signature wrapping

XML and XML signatures for identity named this family of problems XML signature wrapping, often shortened to XSW. In SAML it takes a concrete form: someone who holds one genuinely signed assertion rearranges the response so that the signature check and the application read different elements. The signature verifies; the application acts on content nobody signed.

The simplest variant adds a second assertion. Cedar Inc.'s signed assertion for Avery stays intact, and an unsigned one naming a different account is placed in front of it:

xml
<samlp:Response ...>
  <saml:Issuer>https://login.cedar.example</saml:Issuer>
  <samlp:Status>...</samlp:Status>
  <saml:Assertion ID="_inserted">                  <!-- unsigned, chosen subject -->
    <saml:Subject><saml:NameID>payroll-admin</saml:NameID>...</saml:Subject>
    ...
  </saml:Assertion>
  <saml:Assertion ID="_c5e27a9f4d18">              <!-- the original, still signed -->
    <ds:Signature>...<ds:Reference URI="#_c5e27a9f4d18">...</ds:Signature>
    ...
  </saml:Assertion>
</samlp:Response>

The library resolves #_c5e27a9f4d18, verifies the original and reports success. If the application then reads "the first assertion in the response", it reads the inserted one. Other variants hide the signed original somewhere the application never looks, such as inside samlp:Extensions, an element the SAML schema allows in a response for additional data, or a ds:Object inside the signature, and put a different assertion in its place. Some give two elements the same ID and rely on the signature library and the application resolving it differently. When only the response is signed, the whole signed response can be wrapped inside a new one in the same way.

In a wrapped response the signature check and the application look at different elements. The safe path uses only the element the verifier says is signed and refuses a response with more than one assertion.

The defenses all come down to one rule: consume what you verified. A safe service provider asks its library for the element the signature actually covered and reads only that element. It accepts exactly one assertion, at the position the profile expects, and refuses a response containing more. It refuses duplicate ID values, checks the document against the SAML schema, the formal description of which elements may appear where, before trusting any part of it, and requires the signature on the element it consumes, not merely somewhere in the document. Good SAML libraries do all of this together; trouble starts when an application verifies with one tool and then reads values with another.

Comments and canonicalization

A related flaw, disclosed across several SAML libraries in 2018, came from comments. Exclusive canonicalization without comments, the form SAML signatures use, ignores XML comments, so adding a comment to a signed element does not change its digest.

Imagine someone whose real identifier at an identity provider is [email protected], an account they legitimately control at a domain they own. They sign in, receive a genuinely signed assertion, and an empty comment ends up inside the NameID:

xml
<saml:NameID>[email protected]<!---->.attacker.example</saml:NameID>

The signature still verifies, because canonicalization drops the comment and the bytes match what was signed. But the element now holds two separate pieces of text, and a service that reads only "the first text node" gets [email protected], Avery's identifier. The fix is to read the element's complete text content, ignoring comments, exactly as canonicalization does, and the affected libraries were patched to do so. It is another case of the verifier and the application seeing different things.

Algorithms, parsers and libraries

Older SAML deployments sign with http://www.w3.org/2000/09/xmldsig#rsa-sha1 and hash with http://www.w3.org/2000/09/xmldsig#sha1. SHA-1 is broken for collision resistance: practical attacks can produce two different inputs with the same hash. A service provider should refuse SHA-1 signatures and digests, accept SHA-256 or stronger, and check the algorithm against its own allowed list rather than trusting whatever SignatureMethod says.

The parser settings that XML and XML signatures for identity described apply before any signature is checked. SAML messages never need a document type definition, so the parser refuses one outright, which shuts out external entities and entity expansion, and it limits message size and nesting depth.

Some of the most recent signature bypasses came from parser differentials: a library that parsed the same message with two different XML parsers, one for the signature check and one for reading values, where the two disagreed about the document's structure. Flaws of this kind were still being found in widely used SAML libraries in 2024 and 2025. That history is the strongest argument for the plainest advice: use a mature, actively maintained SAML library, keep it updated, follow its security announcements, and never write your own signature verification or patch around a library's checks.

Testing your own service provider

A service provider should prove it refuses broken responses, not only that it accepts good ones. The training service keeps a set of prepared test responses that it sends to its own test environment, each with the result it expects:

The training service's own tests, and what each must produce
Test responseExpected result
An assertion with its signature removedRefused: the agreement requires a signed assertion
A correct signature made with a key that is not in Cedar Inc.'s metadataRefused, even if KeyInfo carries the key's certificate
One attribute value changed after signingRefused: the digest no longer matches
A second, unsigned assertion added before the signed oneRefused: more than one assertion
Two elements with the same IDRefused by schema and ID checks
A comment inside the NameIDThe full identifier is read, so no other account is reached
A response signed with RSA-SHA1Refused: algorithm not allowed
A response containing a document type definitionRefused before parsing continues

Run tests like these only against services you operate. Each one checks that the service consumes the element it verified and nothing else.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

A response reaches the training service holding two assertions. The signature's Reference points at the second, Avery's, and it verifies. The application reads the first, which names payroll-admin. What is this? 1 of 3

Choose one answer.

A signed NameID reaching the training service reads [email protected]<!---->.attacker.example, and its signature verifies. Why does that matter? 2 of 3

Choose one answer.

An assertion's signature verifies with the certificate carried in its own KeyInfo. That certificate is not in Cedar Inc.'s metadata. What should the training service do? 3 of 3

Choose one answer.

Try it in the Lab

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity