mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
Longer CPEs for golang modules to avoid false positives (#1006)
* golang module CPE with full path Signed-off-by: Jonas Xavier <jonasx@anchore.com> * add note on longer Golang CPEs Signed-off-by: Jonas Xavier <jonasx@anchore.com>
This commit is contained in:
parent
d41afe05eb
commit
c990f425a6
@ -534,6 +534,19 @@ func TestGeneratePackageCPEs(t *testing.T) {
|
|||||||
"cpe:2.3:a:someone:something:3.2:*:*:*:*:*:*:*",
|
"cpe:2.3:a:someone:something:3.2:*:*:*:*:*:*:*",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "go product with vendor candidates and an extra sub-item",
|
||||||
|
p: pkg.Package{
|
||||||
|
Name: "github.com/someone/something/more",
|
||||||
|
Version: "3.2",
|
||||||
|
FoundBy: "go-cataloger",
|
||||||
|
Language: pkg.Go,
|
||||||
|
Type: pkg.GoModulePkg,
|
||||||
|
},
|
||||||
|
expected: []string{
|
||||||
|
"cpe:2.3:a:someone:something\\/more:3.2:*:*:*:*:*:*:*",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "generate no CPEs for indeterminate golang package name",
|
name: "generate no CPEs for indeterminate golang package name",
|
||||||
p: pkg.Package{
|
p: pkg.Package{
|
||||||
|
|||||||
@ -28,7 +28,9 @@ func candidateProductForGo(name string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
return pathElements[1]
|
// returning the rest of the path here means longer CPEs, it helps avoiding false-positives
|
||||||
|
// ref: https://github.com/anchore/grype/issues/676
|
||||||
|
return strings.Join(pathElements[1:], "/")
|
||||||
}
|
}
|
||||||
|
|
||||||
// candidateVendorForGo attempts to find a single vendor name in a best-effort attempt. This implementation prefers
|
// candidateVendorForGo attempts to find a single vendor name in a best-effort attempt. This implementation prefers
|
||||||
|
|||||||
@ -41,7 +41,11 @@ func TestCandidateProductForGo(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
pkg: "github.com/someone/something/long/package/name",
|
pkg: "github.com/someone/something/long/package/name",
|
||||||
expected: "something",
|
expected: "something/long/package/name",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pkg: "",
|
||||||
|
expected: "",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user