Repository navigation
Signing omits a KeyInfo the caller asked for, instead of throwing #598
Description
Summary
Follow-up to #596. With #597, signing leaves out KeyInfo whenever getKeyInfoContent returns no content, because XMLDSig requires KeyInfo to have at least one child element (4.5). That includes configurations that set keyInfoAttributes, so the caller asks for a KeyInfo with those attributes and gets a signature without one, with no error.
The same is true of publicCert. When the default getKeyInfoContent is in use, publicCert is its only input, so a publicCert that holds no certificate is also a request for KeyInfo that signing cannot meet. #605 has the details and covers the non-breaking part in 6.4. This issue covers the error.
#597 omits the element instead of throwing so that configurations that sign in 6.x keep signing. For 7.0, an explicit error is the better contract.
Expected
computeSignature() throws when getKeyInfoContent returns null or an empty string and either:
keyInfoAttributeshas at least one attribute, orgetKeyInfoContentis the default, andpublicCertis a string orBuffer.
For example:
const sig = new SignedXml({
privateKey,
canonicalizationAlgorithm: "http://www.w3.org/2001/10/xml-exc-c14n#",
signatureAlgorithm: "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",
keyInfoAttributes: { Id: "key" },
});
sig.addReference({
xpath: "//*[local-name(.)='book']",
digestAlgorithm: "http://www.w3.org/2001/04/xmlenc#sha256",
transforms: ["http://www.w3.org/2001/10/xml-exc-c14n#"],
});
sig.computeSignature("<library><book/></library>"); // should throwand the same configuration with publicCert set to a PEM public key in place of keyInfoAttributes.
Configurations that set neither keep omitting KeyInfo when there is no content. So does a custom getKeyInfoContent that returns nothing when keyInfoAttributes is unset, because it may not use publicCert at all.
Also decide whether a key object given as the signing publicCert is an error. That is a KeyObject today, and a CryptoKey too once #545 lands. It can never supply a certificate, but 6.x deliberately treats it as producing no KeyInfo.
Release notes
This is a breaking change: the PR needs the breaking-change and semver-major labels and an entry in the README's Upgrading section.
Activity
[-]Signing ignores keyInfoAttributes when there is no KeyInfo content[/-][+]Signing omits a KeyInfo the caller asked for, instead of throwing[/+]cjbarth commentedon Sep 19, 2026
Closing as not planned. Neither case adds anything to security or function.
publicCertwith no certificate.KeyInfois optional (XMLDSig 4.5), so a signature without it is valid. xml-crypto's own verification doesn't depend on it either, becausegetCertFromKeyInfodefaults tonoop. An error would only tell a misconfigured caller sooner. fix: read a signing publicCert given as bare base64, and document that it needs a certificate #610 documents thatpublicCertneeds a certificate to produceKeyInfo, and reads a certificate given as bare base64.keyInfoAttributeswith no content. The signature is valid withoutKeyInfo. A configuration that references theKeyInfoit expected already fails:the following xpath cannot be signed because it was not found.A key object given as the signing
publicCertstays as it is. It holds no certificate, so it produces noKeyInfo.