Container security

Reading an SBOM: CycloneDX vs SPDX in Practice

Read a CycloneDX or SPDX SBOM with jq: its subject, components, licenses and relationships, where the formats differ, and what an SBOM cannot tell you.

TrustIvan ·

Somebody has handed you an SBOM, a supplier for a contract or your own pipeline for an audit, and you need to know what is in it. Reading an SBOM is mostly a matter of knowing where each format keeps five things: what the document describes, the component list, licenses, the relationships between components, and who produced it. CycloneDX and SPDX keep them in different places. This guide reads both with jq, compares the formats where the difference matters, and lists what neither format can tell you.

What is the difference between CycloneDX and SPDX?

Both are open, machine-readable formats for a software bill of materials, and both can describe a container image down to its packages. They come from different starting points.

CycloneDXSPDX
OriginOWASP, built for application securityLinux Foundation, built for license compliance
StandardEcma International ECMA-424ISO/IEC 5962:2021 (for SPDX 2.2.1)
Versions in common use1.5, 1.6 and 1.72.3, with 3.0 now published
Component identitybom-ref, usually with a purlSPDXID, with a purl in externalRefs
Relationshipsdependencies graph, plus nested componentsrelationships list with typed edges
Licenseslicenses array: an SPDX ID, a name or an expressionlicenseDeclared and licenseConcluded
Vulnerabilities and VEXBuilt in, vulnerabilities[]External references in 2.3; a security profile in 3.0

SPDX 3.0 is a different shape from 2.3, a JSON-LD graph of typed elements rather than a document with a packages array. Many tools still read and write 2.3, so check which one you have before you write a parser. Every example below uses SPDX 2.3 JSON and CycloneDX JSON.

How do you generate both for the same image?

Syft writes either format, and both at once:

syft registry.example.com/payments-api:1.42.0 \
  -o cyclonedx-json=sbom.cdx.json \
  -o spdx-json=sbom.spdx.json

Current Syft releases default to CycloneDX 1.7 and SPDX 2.3. If a consumer needs an older CycloneDX version, check specVersion in the output rather than assuming.

Trivy produces CycloneDX as well (trivy image --format cyclonedx). Two generators run against the same image will not produce identical component lists, because each recognizes packages differently. That is normal, and it is the first reason to read an SBOM rather than trust its length.

What does the document describe?

Start with the subject and the producer. If either is missing, everything below it is harder to rely on.

In CycloneDX the subject is metadata.component, and the producing tools are under metadata.tools:

jq '{spec: .specVersion,
     subject: .metadata.component.name,
     tools: [.metadata.tools.components[]?.name],
     components: (.components | length)}' sbom.cdx.json

Older documents (before 1.5) list metadata.tools as a plain array, so a query written for one shape returns nothing on the other. That is one of the small version differences that break parsers silently.

In SPDX 2.3 the subject is whatever the document DESCRIBES, and the producer is in creationInfo.creators:

jq '{spec: .spdxVersion, name, creators: .creationInfo.creators,
     packages: (.packages | length)}' sbom.spdx.json
 
jq -r '.relationships[] | select(.relationshipType == "DESCRIBES")
       | .relatedSpdxElement' sbom.spdx.json

Note that SPDX counts the subject itself as a package, so its packages length is usually one more than the number of components.

How do you list the components?

The Package URL (purl) is the field that matters most. It names a package by ecosystem, namespace, name and version in one string, and it is what a vulnerability database or another SBOM can match on. A component without a purl is a name and a version that a tool can only guess about.

CycloneDX:

jq -r '.components[] | [.type, .name, .version, (.purl // "-")] | @tsv' sbom.cdx.json

SPDX 2.3 keeps the purl in externalRefs:

jq -r '.packages[] | [.name, .versionInfo,
       (first(.externalRefs[]? | select(.referenceType == "purl")
              | .referenceLocator) // "-")] | @tsv' sbom.spdx.json

Count the dashes. A high share of components with no purl is the most common quality problem in SBOMs received from suppliers, and it is worth sending back.

To compare two SBOMs of the same image, diff the purl sets:

jq -r '[.components[] | .purl // empty] | sort[]' sbom.cdx.json > cdx.purls
jq -r '[.packages[].externalRefs[]? | select(.referenceType == "purl")
        | .referenceLocator] | sort[]' sbom.spdx.json > spdx.purls
comm -3 cdx.purls spdx.purls

How do you read licenses?

CycloneDX puts licenses in an array on each component. Each entry holds an SPDX license ID, a free-text name, or an SPDX license expression:

jq -r '.components[] | "\(.name)\t\([.licenses[]?
       | .license.id // .license.name // .expression] | join(" ; "))"' sbom.cdx.json

SPDX separates what the package says from what someone concluded:

jq -r '.packages[] | [.name, .licenseDeclared, .licenseConcluded] | @tsv' sbom.spdx.json

NOASSERTION appears everywhere in generated SPDX documents, especially in licenseConcluded. It means the tool did not determine a license. It does not mean the package has none, and a license review that treats it as "no license, no obligations" is wrong in the direction that causes legal trouble.

How do you follow relationships?

CycloneDX describes the dependency graph in dependencies, a list of ref and dependsOn pairs that point at bom-ref values. A bom-ref is only unique within its document, so look it up first rather than guessing it:

REF=$(jq -r '.components[] | select(.name == "express") | ."bom-ref"' sbom.cdx.json)
jq --arg ref "$REF" '.dependencies[] | select(.ref == $ref) | .dependsOn' sbom.cdx.json

SPDX uses typed relationships. For an image, CONTAINS usually links the image to its packages and DEPENDS_ON links packages to each other:

jq -r '.relationships[]
       | select(.relationshipType == "CONTAINS" or .relationshipType == "DEPENDS_ON")
       | "\(.spdxElementId) \(.relationshipType) \(.relatedSpdxElement)"' sbom.spdx.json

Image SBOMs are often flat: the image contains every package, and the package-to-package edges are missing because the generator read installed files rather than a lockfile. A flat SBOM can answer "is this package present?" but not "why is it here?".

Is the SBOM complete?

CycloneDX can say so explicitly. The compositions field records whether an assembly's component list is complete, incomplete or unknown:

jq -r '.compositions[]? | "\(.aggregate)\t\(.assemblies // [] | join(","))"' sbom.cdx.json

Most generated documents omit it, which means the producer made no claim. SPDX 2.3 has no equivalent field. In both cases, assume a document is incomplete unless the producer says otherwise and you can see why.

Which format should you choose?

Usually the one your consumer asks for. Contracts and procurement rules often name a format, and producing what they name is cheaper than arguing. Without that constraint, the tie-breaker is the work you will do with it. If the SBOM feeds vulnerability management and VEX, CycloneDX keeps components, vulnerabilities and analysis in one document. If it feeds a license review, SPDX's split between declared and concluded licenses maps directly to how that review works. Many teams produce both from the same scan, as above, and keep whichever the recipient reads.

What can an SBOM not tell you?

Whether a component is vulnerable in your use. An SBOM lists what is present. Matching it to advisories tells you which components have known vulnerabilities. Whether those vulnerabilities affect the product is a separate statement, which is what VEX is for.

Whether it is the SBOM of what you run. An SBOM names its subject, but nothing in the document proves the bytes you deployed are the bytes it describes, unless the subject is named by digest and the SBOM is signed or attested by its producer.

Whether a conversion was lossless. Converting CycloneDX to SPDX or back drops whatever has no equivalent: compositions, some relationship types, vulnerability data. Keep the original document you were given.

How does TrustIvan handle SBOMs?

TrustIvan exports every scanned asset's inventory as CycloneDX 1.5 or SPDX 2.3, both JSON, with the document's SHA-256 in the X-TrustIvan-SBOM-Digest response header so you can confirm the file you saved is the one recorded. It imports CycloneDX JSON and SPDX 2.x JSON, detecting the format from the content; SPDX 3.0's JSON-LD form is not read. An import adds and corrects components and never removes what a scan found, components are matched by purl, and entries that cannot be stored are dropped and counted. The response's partial flag and drop_reasons tell you when that happened, which is the check most SBOM tooling skips.

Every document exported or imported is recorded with its format, spec version, digest, producer and component counts, so "where did this inventory come from, and who did we give it to?" has an answer. The same component data drives the license inventory. What TrustIvan does not do is sign or attest the SBOMs it exports for your assets.

For what to do with the components once you have them, see prioritizing container vulnerabilities with EPSS and KEV and writing a VEX statement. The glossary defines the terms used here, starting with SBOM, and container scanning covers how the inventory is built.

Primary sources and further reading

The standards and primary documentation on this subject, for checking a claim at its source: