Skip to content

Commit ac4376f

Browse files
committed
internal/vuln: do not count withdrawn vuln as affecting a package
Currently, withdrawn vulnerabilities are still prominently displayed as if they are regular vulnerabilities when viewing a package. This is likely causing a lot of undue noise for users. Therefore, stop showing withdrawn vulnerabilities, similar to govulncheck. Users who want to see withdrawn vulnerabilities can check it directly on pkg.go.dev/vuln. Fixes golang/go#80941 Change-Id: Idb981b629e4bb31eb3f32e02fbb8cd326a6a6964 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/817440 kokoro-CI: kokoro <noreply+kokoro@google.com> Reviewed-by: Nicholas Husin <husin@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ethan Lee <ethanalee@google.com>
1 parent adbf43b commit ac4376f

6 files changed

Lines changed: 32 additions & 1 deletion

File tree

internal/vuln/client.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ func (c *Client) modulesFilter(ctx context.Context, filter func(*ModuleMeta) boo
126126
}
127127

128128
func isAffected(e *osv.Entry, req *PackageRequest) bool {
129+
if e.Withdrawn != nil {
130+
return false
131+
}
129132
for _, a := range e.Affected {
130133
if a.Module.Path != req.Module || !osv.AffectsSemver(a.Ranges, req.Version) {
131134
continue

internal/vuln/vulns_test.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,25 @@ func TestVulnsForPackage(t *testing.T) {
7474
},
7575
}},
7676
}
77+
withdrawn := osv.Entry{
78+
ID: "GO-2020-0004",
79+
Published: jan1999,
80+
Withdrawn: &jan2000,
81+
Affected: []osv.Affected{{
82+
Module: osv.Module{Path: "bad.com"},
83+
Ranges: []osv.Range{{
84+
Type: osv.RangeTypeSemver,
85+
Events: []osv.RangeEvent{{Introduced: "0"}},
86+
}},
87+
EcosystemSpecific: osv.EcosystemSpecific{
88+
Packages: []osv.Package{{
89+
Path: "bad.com/withdrawn",
90+
}},
91+
},
92+
}},
93+
}
7794

78-
client, err := NewInMemoryClient([]*osv.Entry{&e, &e2, &stdlib})
95+
client, err := NewInMemoryClient([]*osv.Entry{&e, &e2, &stdlib, &withdrawn})
7996
if err != nil {
8097
t.Fatal(err)
8198
}
@@ -115,6 +132,11 @@ func TestVulnsForPackage(t *testing.T) {
115132
name: "match - pkg with no fix",
116133
mod: "unfixable.com", pkg: "unfixable.com", version: "v1.999.999", want: []Vuln{{ID: "GO-1999-0001"}},
117134
},
135+
{
136+
name: "no match - withdrawn",
137+
mod: "bad.com", pkg: "bad.com/withdrawn", version: "v1.0.0",
138+
want: nil,
139+
},
118140
// Vulnerabilities for a module (package == "")
119141
{
120142
name: "no match - module only",

tests/screentest/seed.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ github.com/creack/pty@v1.1.0
1414
github.com/creack/pty/v2@v2.0.1
1515
github.com/envoyproxy/go-control-plane@v0.9.8
1616
github.com/envoyproxy/go-control-plane@v0.9.9
17+
github.com/gorilla/sessions@v1.2.1
1718
github.com/hashicorp/vault/api@v1.0.3
1819
github.com/hashicorp/vault/api@v1.1.1
1920
github.com/hashicorp/vault/api/auth/approle@latest

tests/screentest/testcases.ci.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ path /golang.org/x/crypto?tab=versions
6363
capture viewport
6464
capture viewport 540x1080
6565

66+
test vuln withdrawn module
67+
path /github.com/gorilla/sessions@v1.2.1
68+
capture viewport
69+
capture viewport 540x1080
70+
6671
test vuln search
6772
path /search?q=github.com%2Fbeego&m=vuln
6873
capture viewport
110 KB
Loading
162 KB
Loading

0 commit comments

Comments
 (0)