diff --git a/lib/saml2.coffee b/lib/saml2.coffee index 6fd0b12..7bdbb5f 100644 --- a/lib/saml2.coffee +++ b/lib/saml2.coffee @@ -243,10 +243,15 @@ decrypt_assertion = (dom, private_keys, cb) -> # This checks the signature of a saml document and returns either array containing the signed data if valid, or null # if the signature is invalid. Comparing the result against null is NOT sufficient for signature checks as it doesn't # verify the signature is signing the important content, nor is it preventing the parsing of unsigned content. -check_saml_signature = (xml, certificate) -> +check_saml_signature = (_xml, certificate) -> + # xml-crypto requires that whitespace is normalized as such: + # https://github.com/yaronn/xml-crypto/commit/17f75c538674c0afe29e766b058004ad23bd5136#diff-5dfe38baf287dcf756a17c2dd63483781b53bf4b669e10efdd01e74bcd8e780aL69 + xml = _xml.replace(/\r\n?/g, '\n') doc = (new xmldom.DOMParser()).parseFromString(xml) - signature = xmlcrypto.xpath(doc, "./*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']") + # Calling xpath failed to capture the direct descendents' nodes. + # Be explicit, and call documentElement to start from the root element of the document. + signature = xmlcrypto.xpath(doc.documentElement, "./*[local-name(.)='Signature' and namespace-uri(.)='http://www.w3.org/2000/09/xmldsig#']") return null unless signature.length is 1 sig = new xmlcrypto.SignedXml() sig.keyInfoProvider = getKey: -> format_pem(certificate, 'CERTIFICATE') diff --git a/package.json b/package.json index 79a0a04..bee6cc4 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "async": "^2.5.0", "debug": "^2.6.0", "underscore": "^1.8.0", - "xml-crypto": "^0.10.0", + "xml-crypto": "^2.0.0", "xml-encryption": "^1.2.1", "xml2js": "^0.4.0", "xmlbuilder": "~2.2.0",