cdx-verify and cdx-validate accept unsigned or altered BOM content as verified
Description
The JSF signature verification in cdx-verify, cdx-validate, and the verifyBom() library function could report success for a CycloneDX BOM whose content was never signed by the trusted key. An attacker who can modify a signed BOM (in a registry, in transit, or in a pull request that CI verifies) could add or replace components, or present signatures taken from other documents, without the signer's private key. Verification cost could also be driven up by orders of magnitude with a few kilobytes of extra signature entries.
Details
- Root signature stripping (cdx-verify, 12.2.0+). When a BOM had no root
signaturebut its components, services, or annotations carried signatures,cdx-verifyverified only those nested signatures, ignored every unsigned element, and exited 0 ("✓ N nested signature(s) are valid!"). Removing the root signature of any BOM signed with nested signatures (the default forcdx-signandcdxgensigning) and adding unsigned components therefore passed verification. Signed components could also be copied from any BOM the key had signed into an otherwise unsigned document. - Trust anchor read from the working directory (cdx-verify, 9.5.0+). Without
--public-key,cdx-verifyusedpublic.keyfrom the current directory. A CI job that runscdx-verifyinside a checked-out pull request verified the attacker's BOM with the attacker's key. - Nested signature presented as a BOM signature (12.2.0+). A component, service, or annotation signature covers
{...object, signature}— the same shape as a root signature. When a signer signed a submitted BOM whose component was itself shaped like a BOM (bomFormat,specVersion,components), the component could be extracted and verified as a standalone BOM signed by that key. - Ambiguous JSON (12.2.0+). The signed bytes are the RFC 8785 canonical form of the parsed document.
JSON.parsekeeps the last of repeated member names and rounds numbers to IEEE 754 doubles, and the file was decoded leniently, so text such as{"components":[evil], …signed BOM…},"version": 9007199254740993,1e999(which canonicalizes likenull), or a signed U+FFFD replaced by an invalid byte verified while parsers that keep the first member, use arbitrary-precision numbers, or decode UTF-8 strictly read different values. - Unverifiable entries accepted silently (12.2.0+). For
signersandchainsignatures, verification succeeded when any one entry verified. Entries that no key verified (for example a fabricated "security-team" approval) were neither reported nor rejectable, and removing a co-signer's entry or the last entries of a chain could not be detected. - cdx-validate failed open (12.2.0+).
cdx-validate --public-keywithout--require-signatureexited with the same code for a tampered BOM as for a valid one, and an empty key path or key file skipped verification. - Verification cost amplification (12.2.0+). The whole BOM was canonicalized again for every signature entry, candidate form, and key, with no bound on the number of entries. 800 bogus
signersentries (about 30 KB) took a 3.4 MB BOM from 0.24 s to 16 s;chainentries grew quadratically. - Hardening in the same release:
cdx-sign --mode signersco-signed content without checking that it still matched the existing signatures; RSA and ECDSA signatures did not commit to the signer's key unless one was embedded; ECDSA signatures were emitted in eithersform.
Patches
Fixed in @cdxgen/cdxgen 13.4.0 and @cyclonedx/cdxgen 12.8.6:
cdx-verifyrequires--public-keyor--secret-keyand never reads a key from the working directory.--public-keyis repeatable.- A root signature is required.
--allow-nested-onlyaccepts a BOM without one only when every component, service, and annotation carries a signature that verifies, and names the members no signature covers. - A signed root must carry
bomFormat(orspecFormat) andspecVersionand only CycloneDX root members, and signed nested elements may not carrybomFormat,specFormat, orspecVersion;cdx-signrefuses to produce either shape. - BOMs that are not UTF-8, repeat a member name, hold a number an IEEE 754 double cannot represent exactly, or hold an unpaired surrogate escape are refused by
cdx-verify,cdx-sign, andcdx-validate(when a key is given), including BOMs pulled from OCI registries. - Every root and nested
signers/chainentry is reported.--require-allrequires each entry to verify with one of the keys and each key to verify an entry of the root signature, so removed co-signatures and truncated chains fail. cdx-validateexits 4 whenever a key is given and verification fails (--no-require-signaturerestores report-only behaviour); an empty key path or key file is an error.- At most 32 entries per signature and no members beside the
signersorchainarray; each signed object is canonicalized once and verification memory stays proportional to the document size. cdx-signembeds the signer's public key in the root signature by default, writes low-sECDSA signatures, and requires--verify-existing-with(or--allow-unverified-history) before appending asignersentry.
The signature format is unchanged: BOMs signed by 13.3.0 and 12.8.5 keep verifying.
Workarounds
- Always pass
--public-keywith a key from a trusted location. - Treat a
cdx-verifysuccess without the line "✓ Signature is valid!" as a failure, and reject BOMs without a rootsignature. - Pass
--require-signaturetocdx-validate. - Reject BOM text with repeated member names or invalid UTF-8 before verifying it.
Residual risk
A signature that an affected cdx-sign made over an untrusted nested element carrying bomFormat and specVersion can still be presented as a BOM signature, because the bytes are identical. Re-sign BOMs whose nested elements came from untrusted input. Removed signature entries are only detected with --require-all and the key of every expected signer. With --allow-nested-only, nothing protects which signed elements a BOM lists.
Credits
Found during an internal review of the JSF implementation prompted by Erin Shepherd's post on signature verification (blog.erincandescent.net/