Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sbom): Use UUID as BomRef for packages with empty purl #5448

Merged
merged 3 commits into from
Nov 6, 2023

Conversation

DmitriyLewen
Copy link
Contributor

@DmitriyLewen DmitriyLewen commented Oct 26, 2023

Description

After #5190 we don't create purl for Golang dependencies with replace to local directory.
But we still create CycloneDX component, but BomRef and purl for these packages are incorrect.
See more in #5434

We should skip wrong purl and use UUID for BomRef for these components.

Related Issues

Related PRs

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@DmitriyLewen DmitriyLewen self-assigned this Oct 26, 2023
@DmitriyLewen
Copy link
Contributor Author

I thought about this case for a long time.
We don't create PURL for dependencies with local path as name:

trivy/pkg/purl/purl.go

Lines 368 to 371 in 26b4959

// The PURL will be skipped when the package name is a local path, since it can't identify a software package.
if strings.HasPrefix(pkgName, "./") || strings.HasPrefix(pkgName, "../") {
return "", ""
}

But perhaps we need to skip these dependencies when parsing Go files in go-dep-parser:
https://github.com/aquasecurity/go-dep-parser/blob/6f348921ea39b74251940077b07d337bb468f3c8/pkg/golang/binary/parse.go#L47-L66

@knqyf263 wdyt?

@DmitriyLewen DmitriyLewen marked this pull request as ready for review October 26, 2023 04:37
@DmitriyLewen
Copy link
Contributor Author

As @knqyf263 correctly said - we need to save Go local packages using the UUID as the BomRef.

@DmitriyLewen DmitriyLewen changed the title fix(sbom): don't include packages with empty purl in CycloneDX fix(sbom): Use UUID as BomRef for packages with empty purl Oct 30, 2023
} else if p.Type != "" {
root.PackageURL = &p
}
if p != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Is there any reason to make it an independent if-statement rather than else if?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't see point of using else if, because we return error when err != nil.
And independent if seems to me more readable.

pkg/sbom/cyclonedx/marshal.go Show resolved Hide resolved
@knqyf263 knqyf263 added this pull request to the merge queue Nov 6, 2023
Merged via the queue into aquasecurity:main with commit 772d1d0 Nov 6, 2023
14 checks passed
@DmitriyLewen DmitriyLewen deleted the fix/cyclonedx-empty-purl branch November 7, 2023 04:10
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.

bug(cyclonedx): wrong purl for local Go dependencies
3 participants