Skip to content

Commit aa7cf43

Browse files
bedlaDmitriyLewen
andauthored
fix(sbom): add support for file component type of CycloneDX (#9372)
Co-authored-by: DmitriyLewen <[email protected]>
1 parent 81d9425 commit aa7cf43

File tree

3 files changed

+165
-0
lines changed

3 files changed

+165
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"$schema": "http://cyclonedx.org/schema/bom-1.6.schema.json",
3+
"bomFormat": "CycloneDX",
4+
"specVersion": "1.6",
5+
"serialNumber": "urn:uuid:ff7e2292-989f-486b-a18e-29495b085c81",
6+
"version": 1,
7+
"metadata": {
8+
"timestamp": "2025-08-22T09:38:06+02:00",
9+
"tools": {
10+
"components": [
11+
{
12+
"type": "application",
13+
"author": "anchore",
14+
"name": "third-party",
15+
"version": "[not provided]"
16+
}
17+
]
18+
},
19+
"component": {
20+
"bom-ref": "64c458de142e8a93",
21+
"type": "file",
22+
"name": "C:\\dev\\IdeaProjects\\sample-spring-boot\\target\\demo-0.0.1-SNAPSHOT.jar",
23+
"version": "sha256:7444fb30fbf253f431f9b80712ae6bb6fa52f86bae8b0f1b835e124b2baa8203"
24+
}
25+
},
26+
"components": [
27+
{
28+
"bom-ref": "pkg:maven/commons-io/[email protected]?package-id=6033c6b2f2d3cf10",
29+
"type": "file",
30+
"group": "commons-io",
31+
"name": "commons-io",
32+
"version": "2.13.0",
33+
"licenses": [
34+
{
35+
"license": {
36+
"id": "Apache-2.0"
37+
}
38+
}
39+
],
40+
"cpe": "cpe:2.3:a:apache:commons-io:2.13.0:*:*:*:*:*:*:*",
41+
"purl": "pkg:maven/commons-io/[email protected]",
42+
"externalReferences": [
43+
{
44+
"url": "",
45+
"hashes": [
46+
{
47+
"alg": "SHA-1",
48+
"content": "8bb2bc9b4df17e2411533a0708a69f983bf5e83b"
49+
}
50+
],
51+
"type": "build-meta"
52+
}
53+
],
54+
"properties": [
55+
{
56+
"name": "third-party:package:foundBy",
57+
"value": "java-archive-cataloger"
58+
},
59+
{
60+
"name": "third-party:package:language",
61+
"value": "java"
62+
},
63+
{
64+
"name": "third-party:package:type",
65+
"value": "java-archive"
66+
},
67+
{
68+
"name": "third-party:package:metadataType",
69+
"value": "java-archive"
70+
},
71+
{
72+
"name": "third-party:cpe23",
73+
"value": "cpe:2.3:a:apache:commons_io:2.13.0:*:*:*:*:*:*:*"
74+
},
75+
{
76+
"name": "third-party:cpe23",
77+
"value": "cpe:2.3:a:apache:commons:2.13.0:*:*:*:*:*:*:*"
78+
},
79+
{
80+
"name": "third-party:location:0:path",
81+
"value": "\\demo-0.0.1-SNAPSHOT.jar"
82+
},
83+
{
84+
"name": "third-party:metadata:-:artifactID",
85+
"value": "commons-io"
86+
},
87+
{
88+
"name": "third-party:metadata:-:groupID",
89+
"value": "commons-io"
90+
},
91+
{
92+
"name": "third-party:metadata:virtualPath",
93+
"value": "\\demo-0.0.1-SNAPSHOT.jar:BOOT-INF/lib/commons-io-2.13.0.jar"
94+
}
95+
]
96+
}
97+
],
98+
"dependencies": [
99+
{
100+
"ref": "pkg:maven/com.example/[email protected]?package-id=4ba90badb338f3a9",
101+
"dependsOn": [
102+
"pkg:maven/commons-io/[email protected]?package-id=6033c6b2f2d3cf10"
103+
]
104+
}
105+
]
106+
}

pkg/sbom/cyclonedx/unmarshal.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ func (b *BOM) unmarshalType(t cdx.ComponentType) (core.ComponentType, error) {
215215
ctype = core.TypeOS
216216
case cdx.ComponentTypePlatform:
217217
ctype = core.TypePlatform
218+
case cdx.ComponentTypeFile:
219+
ctype = core.TypeFilesystem
218220
default:
219221
return "", ErrUnsupportedType
220222
}

pkg/sbom/cyclonedx/unmarshal_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,63 @@ func TestUnmarshaler_Unmarshal(t *testing.T) {
876876
},
877877
},
878878
},
879+
{
880+
name: "happy path - third-party SBOM scan of `file` root component",
881+
inputFile: "testdata/happy/third-party-scan-file-component.json",
882+
want: types.SBOM{
883+
Applications: []ftypes.Application{
884+
{
885+
Type: "jar",
886+
FilePath: "",
887+
Packages: ftypes.Packages{
888+
ftypes.Package{
889+
ID: "commons-io:commons-io:2.13.0",
890+
Name: "commons-io:commons-io",
891+
Identifier: ftypes.PkgIdentifier{
892+
UID: "",
893+
PURL: &packageurl.PackageURL{
894+
Type: "maven",
895+
Namespace: "commons-io",
896+
Name: "commons-io",
897+
Version: "2.13.0",
898+
Qualifiers: nil,
899+
Subpath: "",
900+
},
901+
BOMRef: "pkg:maven/commons-io/[email protected]?package-id=6033c6b2f2d3cf10",
902+
},
903+
Version: "2.13.0",
904+
Release: "",
905+
Epoch: 0,
906+
Arch: "",
907+
Dev: false,
908+
SrcName: "",
909+
SrcVersion: "",
910+
SrcRelease: "",
911+
SrcEpoch: 0,
912+
Licenses: []string{"Apache-2.0"},
913+
Maintainer: "",
914+
ExternalReferences: nil,
915+
Modularitylabel: "",
916+
BuildInfo: nil,
917+
Indirect: false,
918+
Relationship: 0,
919+
DependsOn: nil,
920+
Layer: ftypes.Layer{
921+
Size: 0,
922+
Digest: "",
923+
DiffID: "",
924+
CreatedBy: "",
925+
},
926+
FilePath: "",
927+
Digest: "",
928+
Locations: nil,
929+
InstalledFiles: nil,
930+
},
931+
},
932+
},
933+
},
934+
},
935+
},
879936
{
880937
name: "invalid serial",
881938
inputFile: "testdata/sad/invalid-serial.json",

0 commit comments

Comments
 (0)