Skip to content

Commit 375241f

Browse files
committed
Add omit_uri option to skip Reference URI attributes.
Lets callers create References without a URI (and without assigning an Id on the target element solely for that fragment).
1 parent dc0fe3e commit 375241f

2 files changed

Lines changed: 20 additions & 11 deletions

File tree

CHANGELOG.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
xmlseclibs.php
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
??, ??? 2026, 4.0.0-beta2
4+
Features:
5+
- Add reference option omit_uri to skip adding a URI attribute on Reference
6+
(also skips Id assignment on the referenced element, which exists only to
7+
support the URI fragment)
8+
49
Security Improvements:
510
- Harden add509Cert() URL fetching against SSRF: only http/https by default
611
(file:// requires options['allow_file_scheme']); resolve the host and reject

src/XMLSecurityDSig.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,7 @@ private function addRefInternal($sinfoNode, $node, $algorithm, $arTransforms=nul
823823
$id_name = 'Id';
824824
$overwrite_id = true;
825825
$force_uri = false;
826+
$omit_uri = false;
826827
$transforms_elem = true;
827828

828829
if (is_array($options)) {
@@ -831,6 +832,7 @@ private function addRefInternal($sinfoNode, $node, $algorithm, $arTransforms=nul
831832
$id_name = empty($options['id_name']) ? 'Id' : $options['id_name'];
832833
$overwrite_id = !isset($options['overwrite']) ? true : (bool) $options['overwrite'];
833834
$force_uri = !isset($options['force_uri']) ? false : (bool) $options['force_uri'];
835+
$omit_uri = !isset($options['omit_uri']) ? false : (bool) $options['omit_uri'];
834836
$transforms_elem = !isset($options['transforms_elem']) ? true : (bool) $options['transforms_elem'];
835837
}
836838

@@ -842,18 +844,20 @@ private function addRefInternal($sinfoNode, $node, $algorithm, $arTransforms=nul
842844
$refNode = $this->createNewSignNode('Reference');
843845
$sinfoNode->appendChild($refNode);
844846

845-
if (! $node instanceof DOMDocument) {
846-
$uri = null;
847-
if (! $overwrite_id) {
848-
$uri = $prefix_ns ? $node->getAttributeNS($prefix_ns, $id_name) : $node->getAttribute($id_name);
849-
}
850-
if (empty($uri)) {
851-
$uri = self::generateGUID();
852-
$node->setAttributeNS($prefix_ns, $attname, $uri);
847+
if (! $omit_uri) {
848+
if (! $node instanceof DOMDocument) {
849+
$uri = null;
850+
if (! $overwrite_id) {
851+
$uri = $prefix_ns ? $node->getAttributeNS($prefix_ns, $id_name) : $node->getAttribute($id_name);
852+
}
853+
if (empty($uri)) {
854+
$uri = self::generateGUID();
855+
$node->setAttributeNS($prefix_ns, $attname, $uri);
856+
}
857+
$refNode->setAttribute("URI", '#'.$uri);
858+
} elseif ($force_uri) {
859+
$refNode->setAttribute("URI", '');
853860
}
854-
$refNode->setAttribute("URI", '#'.$uri);
855-
} elseif ($force_uri) {
856-
$refNode->setAttribute("URI", '');
857861
}
858862

859863
if ($transforms_elem) {

0 commit comments

Comments
 (0)