Skip to content

Strip fields newer than the target spec version when downgrading - #278

Open
sueun-dev wants to merge 1 commit into
CycloneDX:masterfrom
sueun-dev:strip-newer-fields-on-downgrade
Open

Strip fields newer than the target spec version when downgrading#278
sueun-dev wants to merge 1 commit into
CycloneDX:masterfrom
sueun-dev:strip-newer-fields-on-downgrade

Conversation

@sueun-dev

Copy link
Copy Markdown

BOM.convert already clears most fields that were introduced after the target spec version, but a few slip through, so encoding some BOMs to an older version produces output that fails that version's own JSON schema.

Three cases:

  • component.cryptoProperties (added in 1.6) survives a downgrade below 1.6. convertCryptoProperties only trims its inner 1.7 fields, so a downgraded CBOM keeps the whole cryptoProperties object.
  • composition.bom-ref and composition.vulnerabilities (added in 1.5) survive a downgrade below 1.5, where convertCompositions only normalized the aggregate.
  • vulnerability.analysis.firstIssued and lastUpdated (added in 1.5) survive a downgrade below 1.5.

Each is now cleared next to the fields the surrounding code already clears for the same versions (Tags, ProofOfConcept, and the rest). This is the same class as #248.

Test_convert_stripsFieldsNewerThanTargetSpec decodes the existing valid-cryptographic-asset / valid-compositions / valid-vulnerability fixtures, re-encodes them at the older version, and validates the result against that version's bundled schema with the existing assertValidBOM helper. Each subtest fails on master (the schema rejects the leftover field) and passes with the change.

go test ./... and go vet ./... are clean.

BOM.convert already clears most fields introduced after the target spec
version, but a few slip through, so encoding some BOMs to an older version
produces output that fails that version's own JSON schema:

- component.cryptoProperties (added in 1.6) survived a downgrade below 1.6;
  convertCryptoProperties only trims its inner 1.7 fields.
- composition.bom-ref and composition.vulnerabilities (added in 1.5)
  survived a downgrade below 1.5.
- vulnerability.analysis.firstIssued and lastUpdated (added in 1.5)
  survived a downgrade below 1.5.

Each is now cleared alongside the fields the surrounding code already
clears for the same versions. Adds Test_convert_stripsFieldsNewerThanTargetSpec,
which downgrades the existing fixtures and validates the result against the
target version's bundled schema.

Signed-off-by: Sueun Cho <sueun.dev@gmail.com>
@sueun-dev
sueun-dev requested a review from a team as a code owner July 22, 2026 15:33
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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.

1 participant