diff --git a/README.md b/README.md index 3e8eefb7..baba6079 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,15 @@ The `enveloped-signature` transform removes only the `Signature` element being v - `getCanonXml()` finds the loaded signature in the node's document the same way, and removes nothing when the signature is not there. +### Documents with a DOCTYPE + +`computeSignature()` and `checkSignature()` do not process a document type declaration. An entity +it declares is not expanded and a default attribute it declares is not added, though +[Canonical XML](https://www.w3.org/TR/xml-c14n#Terminology) requires both, so the canonical form is +not the one an implementation that processes the declaration computes. Signing or verifying a +document that has a DOCTYPE is deprecated and will throw in 7.0. Until then it prints a +`DeprecationWarning`. + ### Malformed certificates A certificate whose encapsulated data is not base64 is rejected rather than decoded as far as it diff --git a/src/signed-xml.ts b/src/signed-xml.ts index bbad4e61..2a7fee3b 100644 --- a/src/signed-xml.ts +++ b/src/signed-xml.ts @@ -108,6 +108,12 @@ const warnOriginalXmlWithIds = deprecate( "XML_CRYPTO_GET_ORIGINAL_XML_WITH_IDS", ); +const warnDocumentTypeDeclaration = deprecate( + () => {}, + "Signing or verifying a document that has a document type declaration (``) is deprecated and will throw in version 7.0. The declaration is not processed, so an entity it declares is not expanded and a default attribute it declares is not added to what is signed or verified.", + "XML_CRYPTO_DOCUMENT_TYPE_DECLARATION", +); + const warnValidateElementAgainstReferences = deprecate( () => {}, "`validateElementAgainstReferences()` is deprecated and will be removed in a future version. After `checkSignature()` succeeds, use the XML that `getSignedReferences()` returns instead of nodes from the original document.", @@ -365,6 +371,9 @@ export class SignedXml { this.signedXml = xml; const doc = new xmldom.DOMParser().parseFromString(xml); + if (doc.doctype != null) { + warnDocumentTypeDeclaration(); + } // Reset the references as only references from our re-parsed signedInfo node can be trusted this.references = []; @@ -1034,6 +1043,9 @@ export class SignedXml { } const doc = new xmldom.DOMParser().parseFromString(xml); + if (doc.doctype != null) { + warnDocumentTypeDeclaration(); + } let xmlNsAttr = "xmlns"; const signatureAttrs: string[] = []; let currentPrefix: string;