55namespace SimpleSAML \XMLSecurity \XML ;
66
77use DOMElement ;
8+ use SimpleSAML \XMLSecurity \Assert \Assert ;
89use SimpleSAML \XMLSecurity \Constants as C ;
910use SimpleSAML \XMLSecurity \Exception \CanonicalizationFailedException ;
11+ use SimpleSAML \XMLSecurity \Exception \ReferenceValidationFailedException ;
1012use SimpleSAML \XMLSecurity \XML \ds \Transforms ;
1113use SimpleSAML \XPath \Constants as XPATH_C ;
1214
@@ -118,6 +120,13 @@ public function processTransforms(
118120 Transforms $ transforms ,
119121 DOMElement $ data ,
120122 ): string {
123+ Assert::maxCount (
124+ $ transforms ->getTransform (),
125+ C::MAX_TRANSFORMS ,
126+ ReferenceValidationFailedException::class,
127+ 'Too many transforms. ' ,
128+ );
129+
121130 $ canonicalMethod = C::C14N_EXCLUSIVE_WITHOUT_COMMENTS ;
122131 $ arXPath = null ;
123132 $ prefixList = null ;
@@ -140,9 +149,16 @@ public function processTransforms(
140149 $ arXPath = [];
141150 $ xpathValue = $ xpath ->getContent ()->getValue ();
142151 $ arXPath ['query ' ] = '(.//. | .//@* | .//namespace::*)[ ' . $ xpathValue . '] ' ;
143-
144152 $ arXpath ['namespaces ' ] = $ xpath ->getNamespaces ();
145- $ nslist = $ xp ->query ('./namespace::* ' , $ node );
153+
154+ $ nslist = $ xpCache ->query ('./namespace::* ' , $ xpath ->toXML ());
155+ Assert::lessThanEq (
156+ $ nslist ->count (),
157+ C::MAX_XPATH_NAMESPACES ,
158+ ReferenceValidationFailedException::class,
159+ 'Too many namespaces. ' ,
160+ );
161+
146162 foreach ($ nslist as $ nsnode ) {
147163 if ($ nsnode ->localName != "xml " ) {
148164 $ arXPath ['namespaces ' ][$ nsnode ->localName ] = $ nsnode ->nodeValue ;
0 commit comments