From a9acec7aac1d968eee8d529e8f640528551c24a4 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Thu, 20 Nov 2025 17:16:49 +0100 Subject: [PATCH 1/3] Add option-flag to XPath utility --- src/Utils/XPath.php | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/src/Utils/XPath.php b/src/Utils/XPath.php index fd2497ec..5504e79c 100644 --- a/src/Utils/XPath.php +++ b/src/Utils/XPath.php @@ -4,12 +4,9 @@ namespace SimpleSAML\XMLSecurity\Utils; -use DOMDocument; -use DOMElement; use DOMNode; use DOMXPath; use SimpleSAML\XMLSecurity\Constants as C; -use SimpleSAML\XMLSecurity\Exception\RuntimeException; use SimpleSAML\XPath\XPath as XPathUtils; /** @@ -23,38 +20,16 @@ class XPath extends XPathUtils * Get a DOMXPath object that can be used to search for XMLDSIG elements. * * @param \DOMNode $node The document to associate to the DOMXPath object. + * @param bool $autoregister Whether to auto-register all namespaces used in the document * * @return \DOMXPath A DOMXPath object ready to use in the given document, with the XMLDSIG namespace already * registered. */ - public static function getXPath(DOMNode $node): DOMXPath + public static function getXPath(DOMNode $node, bool $autoregister = false): DOMXPath { $xp = parent::getXPath($node); $xp->registerNamespace('ds', C::NS_XDSIG); $xp->registerNamespace('xenc', C::NS_XENC); return $xp; } - - - /** - * Search for an element with a certain name among the children of a reference element. - * - * @param \DOMNode $ref The DOMDocument or DOMElement where encrypted data is expected to be found as a child. - * @param string $name The name (possibly prefixed) of the element we are looking for. - * - * @return \DOMElement|false The element we are looking for, or false when not found. - * - * @throws \SimpleSAML\XMLSecurity\Exception\RuntimeException If no DOM document is available. - */ - public static function findElement(DOMNode $ref, string $name): DOMElement|false - { - $doc = $ref instanceof DOMDocument ? $ref : $ref->ownerDocument; - if ($doc === null) { - throw new RuntimeException('Cannot search, no DOM document available'); - } - - $nodeset = self::getXPath($doc)->query('./' . $name, $ref); - - return $nodeset->item(0) ?? false; - } } From 7dcd3f684ee5d4e01cdb4dc5950f02fc8bee343a Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Thu, 20 Nov 2025 17:18:20 +0100 Subject: [PATCH 2/3] Pass option on to parent --- src/Utils/XPath.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Utils/XPath.php b/src/Utils/XPath.php index 5504e79c..c762b9e8 100644 --- a/src/Utils/XPath.php +++ b/src/Utils/XPath.php @@ -27,9 +27,11 @@ class XPath extends XPathUtils */ public static function getXPath(DOMNode $node, bool $autoregister = false): DOMXPath { - $xp = parent::getXPath($node); + $xp = parent::getXPath($node, $autoregister); + $xp->registerNamespace('ds', C::NS_XDSIG); $xp->registerNamespace('xenc', C::NS_XENC); + return $xp; } } From 9ec7b7ffee4cedee3f30260af4f528ebbe637683 Mon Sep 17 00:00:00 2001 From: Tim van Dijen Date: Thu, 20 Nov 2025 18:32:17 +0100 Subject: [PATCH 3/3] Bump xml-common --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 8218810d..e72868e9 100644 --- a/composer.json +++ b/composer.json @@ -44,7 +44,7 @@ "ext-spl": "*", "simplesamlphp/assert": "~1.9", - "simplesamlphp/xml-common": "~2.3" + "simplesamlphp/xml-common": "~2.4" }, "require-dev": { "simplesamlphp/simplesamlphp-test-framework": "~1.10"