Skip to content

fix: use full namespaced name for db search PURLs#3531

Open
arpitjain099 wants to merge 1 commit into
anchore:mainfrom
arpitjain099:chore/db-search-purl-module-path
Open

fix: use full namespaced name for db search PURLs#3531
arpitjain099 wants to merge 1 commit into
anchore:mainfrom
arpitjain099:chore/db-search-purl-module-path

Conversation

@arpitjain099

Copy link
Copy Markdown

Fixes #3508.

grype db search --pkg with a golang PURL doesn't match because the package specifier is built from purl.Name only. For ecosystems that carry part of the name in the PURL namespace, that drops the rest of the name. So pkg:golang/github.com/gin-gonic/gin gets searched as just gin, and nothing matches (the DB keys the record under the full module path github.com/gin-gonic/gin).

This adds an ecosystem-aware packageNameFromPURL in PostLoad that reconstructs the stored name:

  • golang and npm join namespace/name (e.g. github.com/gin-gonic/gin, @babel/core)
  • Maven joins groupId:artifactId
  • everything else keeps purl.Name (unchanged behavior for flat-namespaced ecosystems)

It's the same reconstruction the openvex build transformer already does (grype/db/v6/build/transformers/openvex), so the search side and the data side now agree on the name. I extended it to cover golang since that's what the issue hit.

Testing

Added table cases to TestDBSearchPackagesPostLoad for the golang module path, npm scope, and Maven group:artifact mappings (the plain-name fallback was already covered).

$ go test ./cmd/grype/cli/options/...
ok      github.com/anchore/grype/cmd/grype/cli/options

grype db search --pkg only used purl.Name when building the package
specifier from a PURL. For ecosystems that carry part of the name in the
PURL namespace this drops the rest of the name, so the search never
matches. A golang module PURL like pkg:golang/github.com/gin-gonic/gin
was searched as just "gin" instead of github.com/gin-gonic/gin.

Reconstruct the stored name per ecosystem: golang and npm join
namespace/name, Maven joins groupId:artifactId, everything else keeps
purl.Name. This mirrors the openvex build transformer so search and the
data side agree on the name.

Fixes anchore#3508

Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
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.

grype db search does not properly parse golang PURL

1 participant