Skip to content

fix(sbom): dedupe per-node dependsOn / relationships#9318

Merged
owlstronaut merged 1 commit intorelease/v11from
backport/v11/9311
May 6, 2026
Merged

fix(sbom): dedupe per-node dependsOn / relationships#9318
owlstronaut merged 1 commit intorelease/v11from
backport/v11/9311

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot commented May 6, 2026

Backport of #9311 to release/v11.

## 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.:

```json
{
  "dependencies": {
    "lodash": "^4.17.21",
    "lodash-aliased": "npm:lodash@^4.17.21"
  }
}
```

`toCyclonedxDependency` and the SPDX relationship loop both map each
edge through `name@version` ID generation without deduplicating, so the
per-node `dependsOn` array (CycloneDX) and `DEPENDENCY_OF` relationships
(SPDX) end up with duplicate entries.

CycloneDX 1.5 requires `dependsOn` items to be unique, so downstream
validators (e.g. Dependency Track) reject the SBOM with:

```
$.dependencies[N].dependsOn: must have only unique items in the array
```

## Changes

- `lib/utils/sbom-cyclonedx.js`: wrap the `dependsOn` array 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 cases added to both `test/lib/utils/sbom-cyclonedx.js` and
`test/lib/utils/sbom-spdx.js` covering the
duplicate-edges-to-same-target scenario, with explicit assertions plus
snapshot updates.

## Test plan

- [x] `node . run test -- test/lib/utils/sbom-cyclonedx.js
test/lib/utils/sbom-spdx.js` — passes
- [x] 100% coverage on both touched files
- [x] Snapshot diff is purely additive (no existing snapshots changed)
- [x] Schema-validation tests in both files still pass for all snapshots
- [x] Reproduced original issue locally with the alias example, ran
patched npm against it, confirmed both CycloneDX `dependsOn` and SPDX
relationships are now deduped

Fixes #9310

(cherry picked from commit d623988)
@github-actions github-actions Bot requested a review from a team as a code owner May 6, 2026 17:36
@owlstronaut owlstronaut closed this May 6, 2026
@owlstronaut owlstronaut reopened this May 6, 2026
@owlstronaut owlstronaut merged commit 6c17544 into release/v11 May 6, 2026
39 checks passed
@owlstronaut owlstronaut deleted the backport/v11/9311 branch May 6, 2026 17:46
@github-actions github-actions Bot mentioned this pull request May 6, 2026
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.

2 participants