Skip to content

Commit 4245188

Browse files
committed
Add guard to limit amount of namespaces and transforms
1 parent 674686c commit 4245188

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/Constants.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,13 @@ class Constants extends \SimpleSAML\XML\Constants
163163

164164
public const string XMLENC_EXI = 'http://www.w3.org/2009/xmlenc11#EXI';
165165

166+
/**
167+
* Library default limits
168+
*/
169+
public const int MAX_TRANSFORMS = 2;
170+
171+
public const int MAX_XPATH_NAMESPACES = 20;
172+
166173

167174
/** @var string[] */
168175
public static array $KEY_WRAP_ALGORITHMS = [

src/XML/CanonicalizableElementTrait.php

Lines changed: 8 additions & 0 deletions
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,6 +121,13 @@ 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;

0 commit comments

Comments
 (0)