Skip to content

Conversation

@rezmoss
Copy link
Contributor

@rezmoss rezmoss commented Nov 20, 2025

Description

fixed wrong go module purl when module paths had version suffixes like /v5

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have added unit tests that cover changed behavior
  • I have tested my code in common scenarios and confirmed there are no regressions
  • I have added comments to my code, particularly in hard-to-understand sections

kzantow
kzantow previously requested changes Dec 3, 2025
Copy link
Contributor

@kzantow kzantow left a comment

Choose a reason for hiding this comment

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

I did some digging into this, are you seeing this issue when scanning source code with go.mod or Go binaries?

I think the go.mod case should have a different fix, and I think the go binary case could also have a slightly different fix. I assume we are, in fact, using the packages library now to determine the go.mod case, which should be returning the correct modules, that match the go.mod, and similarly should just use those directly rather than being split to subpaths at all.

For go.mod, I think we should be using the full value we found in the go.mod or go.sum, not processing it to have any subpaths -- these are modules already. The subpath from the PURL spec is "used to point to a subpath inside a package" -- package, not module.

For the binary case, we could think about extending the online license lookup to include identification of the module paths (not asking for this as part of your PR here), but default to a slightly different behavior that looks for a /v# anywhere within the path before falling back to <host>/<segment1>/<segment2>, though a package with /v# doesn't necessarily mean the module has that, we need the go.mod to be able to tell for sure, though I suspect most modules are good citizens and update when using this versioning scheme. EDIT: I was conflating this with something else we're working on, but today with binaries, we also get module names, not packages, and these should similarly be used directly. At such time as we surface packages, we will have some additional metadata that may be output in a PURL subpath somewhere, but for all current processing we should use module names directly.

@kzantow kzantow linked an issue Dec 3, 2025 that may be closed by this pull request
@rezmoss
Copy link
Contributor Author

rezmoss commented Dec 8, 2025

@kzantow t main issue the user reported in #4316 was about go.mod, not the go binary

t purl returned something like "pkg:golang/github.com/golang-jwt/[email protected]#v5" but it should be "pkg:golang/github.com/golang-jwt/jwt/[email protected]"

and this is the output from my implementation

Before

b2

After

b3

to reproduce, just create a go.mod file

module tst_gomod

go 1.25.3

require github.com/golang-jwt/jwt/v5 v5.3.0 // indirect

and scan

@kzantow
Copy link
Contributor

kzantow commented Dec 8, 2025

@rezmoss right, read the comment I left on the issue -- I think when reading go.mod that we should be using the module names directly from that file, not looking for v# or any special processing, really. If we did that, it would solve the problem you mentioned here as well as the other, related issue.

@rezmoss
Copy link
Contributor Author

rezmoss commented Dec 9, 2025

@kzantow added new func to handle modules straight from go.mod, no processing needed, kept the original packageurl() for binary scan support, jwt/v5 and aws sdk edge cases are now handled

@kzantow kzantow linked an issue Dec 11, 2025 that may be closed by this pull request
@kzantow kzantow changed the title fixed #4316 go mod with ver purl fix: golang PURL should include full module Dec 11, 2025
@kzantow
Copy link
Contributor

kzantow commented Dec 11, 2025

I believe this PR will also partially fix the following Grype issues:

@wagoodman wagoodman merged commit e0b61a3 into anchore:main Dec 12, 2025
23 of 30 checks passed
spiffcs added a commit that referenced this pull request Dec 19, 2025
* main: (76 commits)
  feat: snap can be queried by revision and ```track/risk/branch``` (#4439)
  fix: 4423 dotnet-deps cataloger skips project type by def
  signpost to docs site (#4483)
  chore(deps): bump github/codeql-action from 4.31.8 to 4.31.9 (#4481)
  chore(deps): bump github.com/goccy/go-yaml from 1.19.0 to 1.19.1 (#4482)
  Detect embedded deps.json in .NET binaries (#4375)
  chore(deps): bump actions/cache from 5.0.0 to 5.0.1 (#4476)
  chore(deps): bump actions/cache in /.github/actions/bootstrap (#4477)
  chore(deps): update tools to latest versions (#4473)
  unapply base path for resolver inbound requests (#4478)
  fix: golang PURL should include full module (#4395)
  fix:best effort to get the os info of an ELF binary (#4438)
  Improve PR template (#4472)
  feat: add support for Gemfile.next.lock (#4457)
  chore:cancel in-progress workflows for new commits on same PR (#4465)
  chore(deps): update tools to latest versions (#4466)
  chore(deps): bump github/codeql-action from 4.31.7 to 4.31.8 (#4468)
  chore(deps): bump actions/cache from 4.3.0 to 5.0.0 (#4469)
  chore(deps): bump github.com/anchore/stereoscope from 0.1.14 to 0.1.16 (#4470)
  chore(deps): bump actions/cache in /.github/actions/bootstrap (#4471)
  ...

Signed-off-by: Christopher Phillips <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants