Skip to content

Commit a287559

Browse files
committed
Add guard to limit amount of namespaces and transforms
1 parent 3cc4dd9 commit a287559

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Constants.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,10 @@ class Constants extends \SimpleSAML\XML\Constants
253253
self::C14N11_INCLUSIVE_WITH_COMMENTS,
254254
self::C14N11_INCLUSIVE_WITHOUT_COMMENTS,
255255
];
256+
257+
/**
258+
* Library default limits
259+
*/
260+
public const int MAX_TRANSFORMS = 2;
261+
public const int MAX_XPATH_NAMESPACES = 20;
256262
}

src/XML/CanonicalizableElementTrait.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace SimpleSAML\XMLSecurity\XML;
66

77
use DOMElement;
8+
use SimpleSAML\XMLSecurity\Assert\Assert;
89
use SimpleSAML\XMLSecurity\Constants as C;
910
use SimpleSAML\XMLSecurity\Exception\CanonicalizationFailedException;
1011
use SimpleSAML\XMLSecurity\Exception\ReferenceValidationFailedException;
@@ -120,9 +121,18 @@ public function processTransforms(
120121
Transforms $transforms,
121122
DOMElement $data,
122123
): string {
124+
Assert::maxCount(
125+
$transforms->getTransform(),
126+
C::MAX_TRANSFORMS,
127+
ReferenceValidationFailedException::class,
128+
'Too many transforms.',
129+
);
130+
123131
$canonicalMethod = C::C14N_EXCLUSIVE_WITHOUT_COMMENTS;
124132
$arXPath = null;
125133
$prefixList = null;
134+
$xpCache = XPath::getXPath($data);
135+
126136
foreach ($transforms->getTransform() as $transform) {
127137
$canonicalMethod = $transform->getAlgorithm()->getValue();
128138
switch ($canonicalMethod) {
@@ -144,7 +154,6 @@ public function processTransforms(
144154
$arXPath['query'] = '(.//. | .//@* | .//namespace::*)[' . $xpathValue . ']';
145155
$arXpath['namespaces'] = $xpath->getNamespaces();
146156

147-
$xpCache = XPath::getXPath($data);
148157
$nslist = $xpCache->query('./namespace::*', $xpath->toXML());
149158
Assert::lessThanEq(
150159
$nslist->count(),

0 commit comments

Comments
 (0)