@@ -211,10 +211,11 @@ function HMACSHA1() {
211
211
*
212
212
* @param {object } doc - Usually a product from `new DOMParser().parseFromString()`
213
213
* @param {string } docSubsetXpath - xpath query to get document subset being canonicalized
214
+ * @param {object } namespaceResolver - xpath namespace resolver
214
215
* @returns {Array } i.e. [{prefix: "saml", namespaceURI: "urn:oasis:names:tc:SAML:2.0:assertion"}]
215
216
*/
216
- function findAncestorNs ( doc , docSubsetXpath ) {
217
- var docSubset = xpath . select ( docSubsetXpath , doc ) ;
217
+ function findAncestorNs ( doc , docSubsetXpath , namespaceResolver ) {
218
+ var docSubset = xpath . selectWithResolver ( docSubsetXpath , doc , namespaceResolver ) ;
218
219
219
220
if ( ! Array . isArray ( docSubset ) || docSubset . length < 1 ) {
220
221
return [ ] ;
@@ -442,7 +443,7 @@ SignedXml.prototype.getCanonReferenceXml = function(doc, ref, node) {
442
443
* Search for ancestor namespaces before canonicalization.
443
444
*/
444
445
if ( Array . isArray ( ref . transforms ) ) {
445
- ref . ancestorNamespaces = findAncestorNs ( doc , ref . xpath )
446
+ ref . ancestorNamespaces = findAncestorNs ( doc , ref . xpath , this . namespaceResolver )
446
447
}
447
448
448
449
var c14nOptions = {
@@ -732,6 +733,13 @@ SignedXml.prototype.computeSignature = function(xml, opts, callback) {
732
733
attrs = opts . attrs || { } ;
733
734
location = opts . location || { } ;
734
735
var existingPrefixes = opts . existingPrefixes || { } ;
736
+
737
+ this . namespaceResolver = {
738
+ lookupNamespaceURI : function ( prefix ) {
739
+ return existingPrefixes [ prefix ] ;
740
+ }
741
+ }
742
+
735
743
// defaults to the root node
736
744
location . reference = location . reference || "/*" ;
737
745
// defaults to append action
@@ -874,7 +882,7 @@ SignedXml.prototype.createReferences = function(doc, prefix) {
874
882
if ( ! this . references . hasOwnProperty ( n ) ) continue ;
875
883
876
884
var ref = this . references [ n ]
877
- , nodes = xpath . select ( ref . xpath , doc )
885
+ , nodes = xpath . selectWithResolver ( ref . xpath , doc , this . namespaceResolver )
878
886
879
887
if ( nodes . length == 0 ) {
880
888
throw new Error ( 'the following xpath cannot be signed because it was not found: ' + ref . xpath )
0 commit comments