fix(sbom): dedupe per-node dependsOn / relationships#9311
Open
mikaelkristiansson wants to merge 1 commit intonpm:latestfrom
Open
fix(sbom): dedupe per-node dependsOn / relationships#9311mikaelkristiansson wants to merge 1 commit intonpm:latestfrom
mikaelkristiansson wants to merge 1 commit intonpm:latestfrom
Conversation
A node can have multiple outgoing edges resolving to the same `name@version` (e.g. when a package declares both a direct dependency and an alias to the same package: `foo: ^1` plus `foo-aliased: npm:foo@^1`). The SBOM generators map each edge to a CycloneDX ID or SPDX relationship, which produces duplicate entries inside the per-node `dependsOn` array (CycloneDX) and per-node `DEPENDENCY_OF` relationships (SPDX). CycloneDX 1.5 requires `dependsOn` items to be unique, so downstream schema validators (e.g. Dependency Track) reject the SBOM with "must have only unique items in the array". PR npm#7992 fixed the analogous duplication at the top level (`components` / `dependencies` / `packages`) but left the per-node arrays untouched. This change closes that gap by deduplicating both: - CycloneDX: `dependsOn` is wrapped in `[...new Set(...)]` - SPDX: per-source-node relationships are deduped by the `(spdxElementId, relatedSpdxElement, relationshipType)` triple Fixes npm#9310
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the per-node duplication gap left by #7992.
A node can have multiple outgoing edges resolving to the same
name@version— typically when a package declares both a direct dependency and an npm alias to the same package, e.g.:{ "dependencies": { "lodash": "^4.17.21", "lodash-aliased": "npm:lodash@^4.17.21" } }toCyclonedxDependencyand the SPDX relationship loop both map each edge throughname@versionID generation without deduplicating, so the per-nodedependsOnarray (CycloneDX) andDEPENDENCY_OFrelationships (SPDX) end up with duplicate entries.CycloneDX 1.5 requires
dependsOnitems to be unique, so downstream validators (e.g. Dependency Track) reject the SBOM with:Changes
lib/utils/sbom-cyclonedx.js: wrap thedependsOnarray in[...new Set(...)]after mapping edges to refs.lib/utils/sbom-spdx.js: dedupe per source-node relationships by the(spdxElementId, relatedSpdxElement, relationshipType)triple.test/lib/utils/sbom-cyclonedx.jsandtest/lib/utils/sbom-spdx.jscovering the duplicate-edges-to-same-target scenario, with explicit assertions plus snapshot updates.Test plan
node . run test -- test/lib/utils/sbom-cyclonedx.js test/lib/utils/sbom-spdx.js— passesdependsOnand SPDX relationships are now dedupedFixes #9310