Skip to content

Commit 03e42bc

Browse files
committed
fix: fix lookup of golang packages with major versions
Fix a bug causing to false positives for all golang packages with a major version. The bug is caused by the name of golang packages not including the major version. This leads the osv query to look up vulnerabilities to look up the right version, but for the wrong major. E.g. [email protected] instead of go-jose/[email protected]. Solve this by including the subpath of Go PURLs.
1 parent f90deaa commit 03e42bc

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

internal/clients/clientimpl/osvmatcher/osvmatcher.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,22 @@ func (matcher *OSVMatcher) MatchVulnerabilities(ctx context.Context, pkgs []*ext
111111

112112
func pkgToQuery(pkg imodels.PackageInfo) *osvdev.Query {
113113
if pkg.Name() != "" && !pkg.Ecosystem().IsEmpty() && pkg.Version() != "" {
114+
name := pkg.Name()
115+
116+
// Tools like Syft create Go PURLs where the major suffix is part of the
117+
// subpath as opposed to the package name. For a correct match we need to
118+
// add that back
119+
if pkg.Ecosystem().Ecosystem == osvschema.EcosystemGo && pkg.PURL().Subpath != "" {
120+
if pkg.PURL().Subpath[0] != '/' {
121+
name += "/"
122+
}
123+
124+
name += pkg.PURL().Subpath
125+
}
126+
114127
return &osvdev.Query{
115128
Package: osvdev.Package{
116-
Name: pkg.Name(),
129+
Name: name,
117130
Ecosystem: pkg.Ecosystem().String(),
118131
},
119132
Version: pkg.Version(),

0 commit comments

Comments
 (0)