cdx-verify accepts forged BOM signatures that declare an HMAC algorithm
Description
Impact
cdx-verify, cdx-validate --require-signature, and the verifyBom and verifyNode library functions trusted the algorithm named inside a BOM's JSF signature block. When a signature declared HS256, HS384 or HS512, the verifier computed an HMAC using the verification key it had been given as the shared secret. In the normal workflow that key is the signer's public key, which is published by design. Anyone holding the public key could therefore produce a signature that verifies for any BOM content they choose.
An attacker who can place a BOM in front of a verifier, for example by replacing the SBOM attached to an OCI image, tampering with an artifact store or mirror, or intercepting the BOM in transit, could have a modified BOM reported as validly signed by the vendor's key. Pipelines that gate deployment, admission or vulnerability management on this check would then act on attacker-chosen content, such as a component list that hides a malicious dependency.
The signer's private key is not exposed, and signatures produced by cdxgen are not weakened. The problem is that verification accepted documents the key holder never signed.
Affected versions
@cyclonedx/cdxgen 12.2.0 through 12.8.4 and @cdxgen/cdxgen 13.0.0 through 13.2.0, together with the container images and the standalone cdx-verify, cdx-sign and cdx-validate binaries built from those versions. Releases before 12.2.0 did not include JSF signature verification.
Patches
Fixed in 12.8.5 and 13.3.0. The declared algorithm is now honoured only when the verification key has exactly the matching type, so an Ed25519 signature needs an Ed25519 key, an ES256 signature needs a P-256 key, and so on. HMAC signatures are checked only against a shared secret passed explicitly with the new --secret-key option, or a secret KeyObject from loadSharedSecret() when using the library. A key given with --public-key is always treated as a public key.
The same releases also bring signing in line with the JSF specification: each signature now covers its own algorithm, keyId and publicKey, and each chain entry covers the entries before it. As a result, BOMs signed with an affected version no longer verify and must be re-signed with the fixed cdx-sign, as described in the cdx-sign documentation. cdxgen also now exits with a non-zero status when signing is configured but fails, instead of writing or uploading an unsigned BOM.
Fix branches and commits
The 13.x fix is on the fix/jsf-signature-binding branch. The core change, which binds each algorithm to its key type and requires an explicit shared secret for HMAC, is in 8c98d7f8 and 46b2f8bb. The follow-up hardening from review, covering fail-closed signing in cdxgen, chain history checks in cdx-sign, and nested signature checks in cdx-validate, is in 75de567d and b10b5ed8. Documentation is in 8e89565a and 87e1b54e.
The 12.8 backport is on the fix/jsf-signature-binding-v12 branch, based on release/12.0.x. It carries the same changes in 6887cfa9 and 31898f34, with documentation in 40193631.
Workarounds
Upgrading is the only complete fix. Until then, refuse any BOM that declares an HMAC algorithm anywhere in its signatures before running cdx-verify, unless you deliberately use shared-secret signing. The following command exits with status 0 when such a signature is present:
jq -e '[.. | objects | .signature? | objects | .. | objects | .algorithm? | strings] | any(startswith("HS"))' bom.jsonReferences
The fix for 13.x is in pull request #4400, and the 12.8 backport is in pull request #4401. The re-signing steps are in the cdx-sign documentation, and the signature format is the JSON Signature Format (JSF).
Credits
Thanks to @richilino for reporting that cdxgen did not check the declared signature algorithm against the key type. Following that report led to this issue.