Skip to content

fix(cyclonedx): preserve metadata.component name and version on decode - #5104

Open
jatinder14 wants to merge 2 commits into
anchore:mainfrom
jatinder14:fix/cyclonedx-preserve-component-version
Open

fix(cyclonedx): preserve metadata.component name and version on decode#5104
jatinder14 wants to merge 2 commits into
anchore:mainfrom
jatinder14:fix/cyclonedx-preserve-component-version

Conversation

@jatinder14

@jatinder14 jatinder14 commented Jul 25, 2026

Copy link
Copy Markdown

Summary

  • extractComponents now always copies metadata.component name/version into source.Description
  • Container and file metadata paths still populate typed Metadata, and containers keep ManifestDigest from the component version
  • Adds unit coverage for application/file/container round-trip preservation

Fixes anchore/grype#2418

Previously, decoding a CycloneDX SBOM (e.g. from syft . --source-version=0.1.0) dropped metadata.component.version, so grype sbom:... --output cyclonedx-json emitted an SBOM without that field.

Test plan

  • go test ./syft/format/internal/cyclonedxutil/helpers/ -run Test_extractComponents_preservesNameAndVersion
  • Manual: syft . --output cyclonedx-json=bom.cdx.json --source-version=0.1.0 then scan with Grype cyclonedx-json output and confirm metadata.component.version is retained (once Grype picks up this Syft fix)

extractComponents dropped Name/Version for application (and other
non-container/file) components, and omitted them for container/file
types as well. That caused metadata.component.version to disappear
when Grype re-emitted a CycloneDX SBOM produced with syft --source-version.

Closes anchore/grype#2418

Signed-off-by: Jatinder Mahajan <jatinder14122000@gmail.com>
@jatinder14
jatinder14 force-pushed the fix/cyclonedx-preserve-component-version branch from fcc9819 to 14b5e91 Compare July 25, 2026 17:20
Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>

@spiffcs spiffcs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👋 Thanks for the PR @jatinder14

I pushed a few changes to the tests and added a couple cases that cover the new default path where we assert that name/version/supplier all flow through and are not dropped.

I'll wait for CI to pass here and then 🟢 or ask someone on @anchore/tools for a second pair of 👀.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Main Component Version gets lost from CycloneDX when throwing Grype at it

2 participants