GHSA-w553-pwx6-3mg9: lightsaml allows Signature wrapping bypass
- Source:
- OSV.dev
- Published:
- Fetched:
- Updated:
- Affects:
- litesaml/lightsaml
https://osv.dev/vulnerability/GHSA-w553-pwx6-3mg9 ↗
lightsaml allows Signature wrapping bypass ### Summary LightSaml 5.0.0 (latest release; also confirmed on 4.6.1) validates an inbound `samlp:Response` by collecting its direct-child `saml:Assertion` elements and validating each one's `ds:Signature` via robrichards/xmlseclibs. The two layers disagree on which element a signature actually covers: LightSaml reads claims from the assertion node it collected, while xmlseclibs resolves the signed `Reference URI="#id"` with a document-wide `//*[@Id]` XPath that returns the first ID-bearing element anywhere in the document. An attacker who has captured one genuine signed assertion can exploit this to surface attacker-authored, unsigned claims. ### Details `Response::deserialize` collects assertions with `manyElementsFromXml`, whose relative XPath `saml:Assertion` matches only direct children of the `Response`. Each collected assertion is validated independently by `AssertionSignatureValidatorAction` against the out-of-band trusted IdP credential (resolved by Issuer entityId, never from the document): https://github.com/litesaml/lightsaml/blob/5.0.0/src/Model/Protocol/Response.php#L122 https://github.com/litesaml/lightsaml/blob/5.0.0/src/Model/AbstractSamlModel.php#L93 https://github.com/litesaml/lightsaml/blob/5.0.0/src/Action/Assertion/Inbound/AssertionSignatureValidatorAction.php#L28 The check delegates to xmlseclibs `XMLSecurityDSig::validateReference()`, which first removes the signature node being validated from the shared document (enveloped-signature removal): ```php if (! $docElem->isSameNode($this->sigNode)) { if ($this->sigNode->parentNode != null) { $this->sigNode->parentNode->removeChild($this->sigNode); // strips sig from shared DOM } } ``` https://github.com/robrichards/xmlseclibs/blob/3.1.5/src/XMLSecurityDSig.php#L596 `processRefNode()` then resolves `URI="#id"` document-wide and takes `item(0)`, the first ID-bearing element in the whole document, any name or namespace, not the one inside the signature's own subtree: ```php $query = '//*['.$iDlist.']'; $dataObject = $xPath->query($query)->item(0); ``` https://github.com/robrichards/xmlseclibs/blob/3.1.5/src/XMLSecurityDSig.php#L525 So the digest target xmlseclibs picks (`//*[@Id]` item(0), anywhere) which isn't necessarily the one from the previous phase. LightSaml then reads claims (Subject/NameID, Conditions, Attributes) from the node it collected: https://github.com/litesaml/lightsaml/blob/5.0.0/src/Model/Assertion/Assertion.php#L288 An example attacker buries the genuine signed bytes (the assertion with its `ds:Signature` element stripped) inside `samlp:Extensions`, so it is the first `@Id` element in document order but not a direct-child assertion. Present one forged direct-child assertion with the same `ID`, attacker claims, and a verbatim copy of the genuine `ds:Signature`: ```xml