Skip to content

Commit 911db6e

Browse files
committed
Handle invalid SBOMs with duplicate components
1 parent 2c4d373 commit 911db6e

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/lib/transformations/graph.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,15 @@ function addEdges(graph: Graph, dependencies: Dependency[] | undefined): void {
3232
}
3333

3434
function addRoot(graph: Graph, component: Component | undefined): void {
35-
if (component) {
36-
graph.addNode(component['bom-ref'], { label: component.name });
35+
if (component && component['bom-ref']) {
36+
const ref = component['bom-ref'];
37+
if (!graph.hasNode(ref)) {
38+
graph.addNode(component['bom-ref'], { label: component.name });
39+
} else {
40+
console.warn(
41+
`Component with duplicate bom-ref ${ref} detected. This is not a valid CycloneDX BOM.`
42+
);
43+
}
3744
}
3845
}
3946

0 commit comments

Comments
 (0)