Skip to content

Conversation

@ReiPenguin
Copy link
Contributor

@ReiPenguin ReiPenguin commented Oct 15, 2025

What did you implement:

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

$ vuls report -format-spdx-json -to-localfile

Checklist:

You don't have to satisfy all of the following.

  • Write tests
  • Write documentation
  • Check that there aren't other open pull requests for the same issue/feature
  • Format your source code by make fmt
  • Pass the test by make test
  • Provide verification config / commands
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES

Reference

@ReiPenguin ReiPenguin changed the title feat SBOM SPDX reporter [WIP] feat/SBOM SPDX reporter Oct 15, 2025
@ReiPenguin ReiPenguin changed the title [WIP] feat/SBOM SPDX reporter feat(report): Implement SBOM SPDX-JSON format reporter Oct 16, 2025
@ReiPenguin ReiPenguin marked this pull request as ready for review October 16, 2025 09:51
@MaineK00n MaineK00n requested review from MaineK00n and shino October 16, 2025 15:21
@MaineK00n
Copy link
Collaborator

@ReiPenguin
It seems that SPDX v3.0 has been released, but why did you choose v2.3?
https://spdx.github.io/spdx-spec/v3.0.1/

@ReiPenguin
Copy link
Contributor Author

@ReiPenguin It seems that SPDX v3.0 has been released, but why did you choose v2.3? https://spdx.github.io/spdx-spec/v3.0.1/

The spec for SPDX v3.0 is out, but we're only supporting up to v2.3 for the time being for a couple of reasons:

  • The official spdx/tools-golang library doesn't support v3.0 yet (PR)
  • Most SBOM generation tools still only support up to v2.3, so we feel it's more important to support that first.

Comment on lines 508 to 525
if pi.PackageName != pj.PackageName {
if pi.PackageName < pj.PackageName {
return -1
}
return 1
}
if pi.PackageVersion != pj.PackageVersion {
if pi.PackageVersion < pj.PackageVersion {
return -1
}
return 1
}
if pi.PackageSPDXIdentifier < pj.PackageSPDXIdentifier {
return -1
} else if pi.PackageSPDXIdentifier > pj.PackageSPDXIdentifier {
return 1
}
return 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use cmp.Or, cmp.Compare

https://pkg.go.dev/cmp#Compare

Comment on lines 206 to 210
if urls, exists := packageToURLMap[pack.Name]; exists {
for _, url := range urls {
externalRefs = appendExternalRefs(externalRefs, categorySecurity, securityAdvisory, url)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are just looping through urls, you don't need to evaluate exists.

Suggested change
if urls, exists := packageToURLMap[pack.Name]; exists {
for _, url := range urls {
externalRefs = appendExternalRefs(externalRefs, categorySecurity, securityAdvisory, url)
}
}
for _, url := range packageToURLMap[pack.Name] {
externalRefs = appendExternalRefs(externalRefs, categorySecurity, securityAdvisory, url)
}

@ReiPenguin ReiPenguin requested review from MaineK00n and shino October 21, 2025 07:42
@shino
Copy link
Collaborator

shino commented Oct 22, 2025

Just a memo to save my brain memory.

When report is executed twice, there will be an error in parsing spdx json files:

## First time
% go run ./cmd/vuls report -format-spdx-json -to-localfile
[Oct 22 13:41:59]  INFO [localhost] vuls-`make build` or `make install` will show the version-
[snip]
[Oct 22 13:42:00]  INFO [localhost] : 0 CVEs filtered by --confidence-over=80

## Second time
% go run ./cmd/vuls report -format-spdx-json -to-localfile
[Oct 22 13:42:03]  INFO [localhost] vuls-`make build` or `make install` will show the version-
[Oct 22 13:42:03]  INFO [localhost] Validating config...
[Oct 22 13:42:03]  INFO [localhost] cveDict.type=sqlite3, cveDict.url=, cveDict.SQLite3Path=/data/vulsctl/docker/cve.sqlite3
[Oct 22 13:42:03]  INFO [localhost] ovalDict.type=sqlite3, ovalDict.url=, ovalDict.SQLite3Path=/data/vulsctl/docker/oval.sqlite3
[Oct 22 13:42:03]  INFO [localhost] gost.type=sqlite3, gost.url=, gost.SQLite3Path=/home/shino/g/vuls/gost.sqlite3
[Oct 22 13:42:03]  INFO [localhost] exploit.type=sqlite3, exploit.url=, exploit.SQLite3Path=/data/vulsctl/docker/go-exploitdb.sqlite3
[Oct 22 13:42:03]  INFO [localhost] metasploit.type=sqlite3, metasploit.url=, metasploit.SQLite3Path=/data/vulsctl/docker/go-msfdb.sqlite3
[Oct 22 13:42:03]  INFO [localhost] kevuln.type=sqlite3, kevuln.url=, kevuln.SQLite3Path=/data/vulsctl/docker/go-kev.sqlite3
[Oct 22 13:42:03]  INFO [localhost] cti.type=sqlite3, cti.url=, cti.SQLite3Path=/data/vulsctl/docker/go-cti.sqlite3
[Oct 22 13:42:04] ERROR [localhost] Failed to parse /home/shino/g/vuls-another/results/2025-09-29T19-38-53+0900/ubuntu_2004_spdx.json: json: cannot unmarshal array into Go struct field ScanResult.packages of type models.Packages
exit status 1

Also, two files are created under results/:

% ll results/
total 16K
drwx------ 2 shino shino 4.0K Oct 22 13:42 2025-09-29T19-38-53+0900/
-rw------- 1 shino shino 5.6K Oct 22 13:42 2025-09-29T19-38-53+0900.json
-rw------- 1 shino shino  412 Oct 22 13:42 2025-09-29T19-38-53+0900_spdx.json

For cdx format, no error happens but two extra strange files are created


If we can not come up with a nice idea to fix these, It's acceptable for now, I think, they are "known bugs", isn't it?
If so, this comment should be an separate issue.

Copy link
Collaborator

@shino shino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal is in sight!

@ReiPenguin ReiPenguin requested a review from shino October 23, 2025 14:33
Copy link
Collaborator

@shino shino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost done! Some nitpicky comments added.

@ReiPenguin ReiPenguin requested a review from shino October 24, 2025 16:17
Copy link
Collaborator

@shino shino left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great feature! Thanks a lot!! 🍻 🍶 🍷 🥂

@shino shino merged commit 0ba85f8 into future-architect:master Oct 25, 2025
7 checks passed
@shino shino deleted the sbom-spdx-report branch October 25, 2025 02:18
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.

3 participants