Skip to content

Commit

Permalink
Clone document before manipulating it
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Jul 25, 2024
1 parent 5bf9bdd commit 3edca77
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/XML/SignedElementTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,17 @@ private function validateReference(SignedInfo $signedInfo): SignedElementInterfa
$sigNode = XPath::xpQuery($xml, 'child::ds:Signature', $xp);
Assert::minCount($sigNode, 1, NoSignatureFoundException::class);
Assert::maxCount($sigNode, 1, 'More than one signature found in object.', TooManyElementsException::class);
$xml->removeChild($sigNode[0]);

$data = XML::processTransforms($reference->getTransforms(), $xml);
// Clone the document so we don't mess up the original DOMDocument
$doc = DOMDocumentFactory::create();
$node = $doc->importNode($xml->ownerDocument->documentElement, true);
$doc->appendChild($node);

$xp = XPath::getXPath($doc);
$sigNode = XPath::xpQuery($doc->documentElement, 'child::ds:Signature', $xp);
$doc->documentElement->removeChild($sigNode[0]);

$data = XML::processTransforms($reference->getTransforms(), $doc->documentElement);
$algo = $reference->getDigestMethod()->getAlgorithm();
Assert::keyExists(
C::$DIGEST_ALGORITHMS,
Expand Down

0 comments on commit 3edca77

Please sign in to comment.