Commit 7f5e83a69e

7f5e83a69eeffefd78652707c86e154f65621325

parent: d189296142

Verified · cmc ci/build: success ci/quality: success ci/test: success ci/vuln: success

cmc <hello@cleberg.net> · 2026-11-01 08:36 UTC

Dependency advisories: match imported packages, and dismissal

- A Go advisory whose OSV record names packages counts only when a Go
  file at the checked commit imports one of them, tests included,
  vendor and testdata left out. The files are read only when such an
  advisory matched. The rest are stored as not imported and named in
  the issue.
- repo deps dismiss <repo> <advisory>... --reason
  not-affected|wont-fix|dev-only, and repo deps reopen, by advisory id
  (migration 0084). Either rewrites the issue at once.
- The issue lists open advisories, counts dismissed ones, and closes
  when none are open. repo deps status and the settings page show the
  open, dismissed and not imported ones; the page can dismiss and
  reopen.

Closes #345

Layout: unified · split

.gitbay/wiki/Architecture/06-Data-and-Cryptography.org +1 −1
@@ -19,7 +19,7 @@ content (as confidential as the repository), *O* operational.
19| Notifications | =notifications= (mail queue), =inbox=, =push_devices= (APNs token), =push_queue=, =mail_replies= (Message-IDs of posted replies) | P | device tokens sealed; looked up by SHA-256 | 19| Notifications | =notifications= (mail queue), =inbox=, =push_devices= (APNs token), =push_queue=, =mail_replies= (Message-IDs of posted replies) | P | device tokens sealed; looked up by SHA-256 |
20| Signatures | =commit_signatures=, =settings.key_epoch= | O | verification cache | 20| Signatures | =commit_signatures=, =settings.key_epoch= | O | verification cache |
21| Audit and feed | =audit_log=, =events= | O, P | actor ids, pruned argv, fingerprints and IPs in some audit rows, a hash chain (=prev_hash=, =hash=) | 21| Audit and feed | =audit_log=, =events= | O, P | actor ids, pruned argv, fingerprints and IPs in some audit rows, a hash chain (=prev_hash=, =hash=) |
22| Dependencies | =dep_checks=, =dep_reports=, =dep_advisories= | O | 22| Dependencies | =dep_checks=, =dep_reports=, =dep_advisories=, =dep_advisory_dismissals= | O |
23| Code scanning | =security_scans=, =security_findings=, =security_dismissals= | O | | 23| Code scanning | =security_scans=, =security_findings=, =security_dismissals= | O | |
24 24
25Outside the database: 25Outside the database:
.gitbay/wiki/Parity.org +9
@@ -253,6 +253,7 @@ there shows the app's rendering rather than the one the web page shows.
253| code scan ignores, rules | yes | yes | no | 253| code scan ignores, rules | yes | yes | no |
254| dependency checks on/off | yes | yes | yes | 254| dependency checks on/off | yes | yes | yes |
255| dependency status | yes | yes | yes | 255| dependency status | yes | yes | yes |
256| advisory dismiss, reopen | yes | yes | no |
256| delete, transfer | yes | yes | yes | 257| delete, transfer | yes | yes | yes |
257| rename | yes | yes | yes | 258| rename | yes | yes | yes |
258| release delete | yes | yes | yes | 259| release delete | yes | yes | yes |
@@ -295,6 +296,14 @@ under the toggle — last check, last error, the two tracking issues, and
295the rows. The issues the worker opens, rewrites and closes are still the 296the rows. The issues the worker opens, rewrites and closes are still the
296copies every other surface reads. 297copies every other surface reads.
297 298
299A Go advisory whose OSV record names packages counts only when a Go
300file at the checked commit (tests included, =vendor= and =testdata=
301left out) imports one of them; the rest are listed as not imported.
302Imports through another module are not seen, which =govulncheck=
303covers. A writer can dismiss an advisory (=repo deps dismiss=, reason
304=not-affected=, =wont-fix= or =dev-only=) and reopen it; the issue
305lists open advisories only and closes when none are left.
306
298The wiki row covers reading. A wiki lives at =.gitbay/wiki/= on the 307The wiki row covers reading. A wiki lives at =.gitbay/wiki/= on the
299default branch, so editing one is editing a file in the repository — 308default branch, so editing one is editing a file in the repository —
300a push, or =repo commit-file= — and there is no wiki-specific edit row 309a push, or =repo commit-file= — and there is no wiki-specific edit row
.gitbay/wiki/Users.org +3
@@ -243,6 +243,9 @@ gitbay repo settings secret-scan-allow you/project 'testdata/**' # paths whose
243gitbay repo secret-scan you/project # scan the whole history 243gitbay repo secret-scan you/project # scan the whole history
244gitbay repo security enable you/project # scheduled code scan, where the instance offers one 244gitbay repo security enable you/project # scheduled code scan, where the instance offers one
245gitbay repo security status you/project # its findings, also kept in an issue 245gitbay repo security status you/project # its findings, also kept in an issue
246gitbay repo deps status you/project # dependency updates and advisories
247gitbay repo deps dismiss you/project GO-2026-5932 --reason not-affected # or wont-fix, dev-only
248gitbay repo deps reopen you/project GO-2026-5932
246gitbay repo security dismiss you/project 3f9a0c1d2e --reason false-positive # or wont-fix, test 249gitbay repo security dismiss you/project 3f9a0c1d2e --reason false-positive # or wont-fix, test
247gitbay repo security reopen you/project 3f9a0c1d2e 250gitbay repo security reopen you/project 3f9a0c1d2e
248gitbay repo settings security-ignore you/project 'testdata/**' # paths set aside from the scan 251gitbay repo settings security-ignore you/project 'testdata/**' # paths set aside from the scan
cmd/gitbay/main.go +2
@@ -609,6 +609,8 @@ func repoCmd() *cobra.Command {
609 pass("enable", passOpts{server: []string{"repo", "deps", "enable"}, needsRepo: true}), 609 pass("enable", passOpts{server: []string{"repo", "deps", "enable"}, needsRepo: true}),
610 pass("disable", passOpts{server: []string{"repo", "deps", "disable"}, needsRepo: true}), 610 pass("disable", passOpts{server: []string{"repo", "deps", "disable"}, needsRepo: true}),
611 pass("status", passOpts{server: []string{"repo", "deps", "status"}, needsRepo: true}), 611 pass("status", passOpts{server: []string{"repo", "deps", "status"}, needsRepo: true}),
612 pass("dismiss", passOpts{server: []string{"repo", "deps", "dismiss"}, needsRepo: true}),
613 pass("reopen", passOpts{server: []string{"repo", "deps", "reopen"}, needsRepo: true}),
612 ), 614 ),
613 group("secret", "build secrets (values on stdin, injected into build env)", 615 group("secret", "build secrets (values on stdin, injected into build env)",
614 pass("set", passOpts{server: []string{"repo", "secret", "set"}, needsRepo: true, alwaysStdin: true, stdinWhat: "the secret value", stdinSecret: true}), 616 pass("set", passOpts{server: []string{"repo", "secret", "set"}, needsRepo: true, alwaysStdin: true, stdinWhat: "the secret value", stdinSecret: true}),
cmd/gitbay/summaries_gen.go +2
@@ -166,7 +166,9 @@ var summaries = map[string]string{
166 "repo deploy-key list": "list deploy keys", 166 "repo deploy-key list": "list deploy keys",
167 "repo deploy-key remove": "remove a deploy key", 167 "repo deploy-key remove": "remove a deploy key",
168 "repo deps disable": "stop checking dependencies", 168 "repo deps disable": "stop checking dependencies",
169 "repo deps dismiss": "dismiss dependency advisories, which then stay out of the issue",
169 "repo deps enable": "check dependencies for updates and advisories", 170 "repo deps enable": "check dependencies for updates and advisories",
171 "repo deps reopen": "take back dismissals of dependency advisories",
170 "repo deps status": "show dependency check state", 172 "repo deps status": "show dependency check state",
171 "repo diff": "the patch between two refs, from their merge base", 173 "repo diff": "the patch between two refs, from their merge base",
172 "repo domain add": "claim a custom pages domain (verify with a DNS TXT record)", 174 "repo domain add": "claim a custom pages domain (verify with a DNS TXT record)",
internal/control/deps.go +140 −3
@@ -4,8 +4,11 @@ import (
4 "errors" 4 "errors"
5 "fmt" 5 "fmt"
6 "io" 6 "io"
7 "slices"
7 "strconv" 8 "strconv"
9 "strings"
8 10
11 "gitbay.org/gitbay/internal/deps"
9 "gitbay.org/gitbay/internal/policy" 12 "gitbay.org/gitbay/internal/policy"
10 "gitbay.org/gitbay/internal/protocol" 13 "gitbay.org/gitbay/internal/protocol"
11 "gitbay.org/gitbay/internal/store" 14 "gitbay.org/gitbay/internal/store"
@@ -30,8 +33,24 @@ func init() {
30 Usage: "repo deps status <owner/name>", 33 Usage: "repo deps status <owner/name>",
31 Examples: []string{"repo deps status krz/gitbay"}, 34 Examples: []string{"repo deps status krz/gitbay"},
32 ReadOnly: true, Run: runDepsStatus}) 35 ReadOnly: true, Run: runDepsStatus})
36 register(Command{Path: []string{"repo", "deps", "dismiss"},
37 Summary: "dismiss dependency advisories, which then stay out of the issue",
38 Usage: "repo deps dismiss <owner/name> <advisory>... --reason not-affected|wont-fix|dev-only",
39 Flags: []Flag{
40 {"--reason", "not-affected|wont-fix|dev-only", "why: does not apply, accepted, or only in development", ""},
41 },
42 Examples: []string{"repo deps dismiss krz/gitbay GO-2026-5932 --reason not-affected"},
43 Run: runDepsDismiss})
44 register(Command{Path: []string{"repo", "deps", "reopen"},
45 Summary: "take back dismissals of dependency advisories",
46 Usage: "repo deps reopen <owner/name> <advisory>...",
47 Examples: []string{"repo deps reopen krz/gitbay GO-2026-5932"},
48 Run: runDepsReopen})
33} 49}
34 50
51// Reasons an advisory is dismissed for.
52var advisoryReasons = []string{"not-affected", "wont-fix", "dev-only"}
53
35// DepsOut is what `repo deps status` emits: the check's state and what 54// DepsOut is what `repo deps status` emits: the check's state and what
36// the last run found behind or matching an advisory. Named so the web 55// the last run found behind or matching an advisory. Named so the web
37// decodes the same struct the command writes. 56// decodes the same struct the command writes.
@@ -43,6 +62,11 @@ type DepsOut struct {
43 AdvisoryIssueNumber int64 `json:"advisory_issue_number,omitempty"` 62 AdvisoryIssueNumber int64 `json:"advisory_issue_number,omitempty"`
44 Behind []DepBehind `json:"behind"` 63 Behind []DepBehind `json:"behind"`
45 Advisories []DepAdvisory `json:"advisories"` 64 Advisories []DepAdvisory `json:"advisories"`
65 // Dismissed and NotImported are matching advisories left out of the
66 // issue: dismissed by a writer, or Go advisories for packages no file
67 // imports.
68 Dismissed []DepAdvisory `json:"dismissed"`
69 NotImported []DepAdvisory `json:"not_imported"`
46} 70}
47 71
48// DepBehind is one dependency with a newer release than the manifest pins. 72// DepBehind is one dependency with a newer release than the manifest pins.
@@ -62,6 +86,8 @@ type DepAdvisory struct {
62 Summary string `json:"summary"` 86 Summary string `json:"summary"`
63 Severity string `json:"severity,omitempty"` 87 Severity string `json:"severity,omitempty"`
64 Fixed string `json:"fixed,omitempty"` 88 Fixed string `json:"fixed,omitempty"`
89 Reason string `json:"reason,omitempty"`
90 By string `json:"dismissed_by,omitempty"`
65} 91}
66 92
67func runDepsEnable(c *Ctx, args []string) int { 93func runDepsEnable(c *Ctx, args []string) int {
@@ -127,15 +153,28 @@ func runDepsStatus(c *Ctx, args []string) int {
127 if err != nil { 153 if err != nil {
128 return c.fail(protocol.ExitFailure, "%v", err) 154 return c.fail(protocol.ExitFailure, "%v", err)
129 } 155 }
156 dismissed, err := c.Store.AdvisoryDismissals(repo.ID)
157 if err != nil {
158 return c.fail(protocol.ExitFailure, "%v", err)
159 }
130 out := DepsOut{Enabled: true, LastCheck: check.LastCheck, LastError: check.LastError, 160 out := DepsOut{Enabled: true, LastCheck: check.LastCheck, LastError: check.LastError,
131 IssueNumber: check.IssueNumber, AdvisoryIssueNumber: check.AdvisoryIssueNumber, 161 IssueNumber: check.IssueNumber, AdvisoryIssueNumber: check.AdvisoryIssueNumber,
132 Behind: []DepBehind{}, Advisories: []DepAdvisory{}} 162 Behind: []DepBehind{}, Advisories: []DepAdvisory{}, Dismissed: []DepAdvisory{}, NotImported: []DepAdvisory{}}
133 for _, r := range reports { 163 for _, r := range reports {
134 out.Behind = append(out.Behind, DepBehind{r.Ecosystem, r.Name, r.Current, r.Latest}) 164 out.Behind = append(out.Behind, DepBehind{r.Ecosystem, r.Name, r.Current, r.Latest})
135 } 165 }
136 for _, a := range advisories { 166 for _, a := range advisories {
137 out.Advisories = append(out.Advisories, 167 o := DepAdvisory{Ecosystem: a.Ecosystem, Name: a.Name, Version: a.Version, ID: a.ID,
138 DepAdvisory{a.Ecosystem, a.Name, a.Version, a.ID, a.Summary, a.Severity, a.Fixed}) 168 Summary: a.Summary, Severity: a.Severity, Fixed: a.Fixed}
169 switch d, ok := dismissed[a.ID]; {
170 case a.NotImported:
171 out.NotImported = append(out.NotImported, o)
172 case ok:
173 o.Reason, o.By = d.Reason, d.By
174 out.Dismissed = append(out.Dismissed, o)
175 default:
176 out.Advisories = append(out.Advisories, o)
177 }
139 } 178 }
140 return c.emitView(out, func(w io.Writer) { 179 return c.emitView(out, func(w io.Writer) {
141 tracked, advised := "", "" 180 tracked, advised := "", ""
@@ -169,6 +208,22 @@ func runDepsStatus(c *Ctx, args []string) int {
169 } 208 }
170 tb.flush() 209 tb.flush()
171 } 210 }
211 if len(out.Dismissed) > 0 {
212 v.section("dismissed")
213 tb := c.table(w, "ADVISORY", "NAME", "REASON", "BY")
214 for _, a := range out.Dismissed {
215 tb.row(cText(a.ID), cRef(a.Name), cText(a.Reason), cText(a.By))
216 }
217 tb.flush()
218 }
219 if len(out.NotImported) > 0 {
220 v.section("not imported")
221 tb := c.table(w, "ADVISORY", "NAME", "VERSION")
222 for _, a := range out.NotImported {
223 tb.row(cText(a.ID), cRef(a.Name), cText(a.Version))
224 }
225 tb.flush()
226 }
172 }, func() screen { 227 }, func() screen {
173 state := []cell{cGlyph("ok"), cText("on")} 228 state := []cell{cGlyph("ok"), cText("on")}
174 if check.LastError != "" { 229 if check.LastError != "" {
@@ -200,7 +255,89 @@ func runDepsStatus(c *Ctx, args []string) int {
200 advised.rows = append(advised.rows, rowOf(cRef(a.Name), cMark(a.ID, sgrRed), cMeta(fix))) 255 advised.rows = append(advised.rows, rowOf(cRef(a.Name), cMark(a.ID, sgrRed), cMeta(fix)))
201 } 256 }
202 s.sections = []section{behind, advised} 257 s.sections = []section{behind, advised}
258 if len(out.Dismissed) > 0 {
259 gone := section{title: "Dismissed", n: len(out.Dismissed)}
260 for _, a := range out.Dismissed {
261 gone.rows = append(gone.rows, rowOf(cRef(a.Name), cText(a.ID), cState(a.Reason)))
262 }
263 s.sections = append(s.sections, gone)
264 }
265 if len(out.NotImported) > 0 {
266 aside := section{title: "Not imported", n: len(out.NotImported)}
267 for _, a := range out.NotImported {
268 aside.rows = append(aside.rows, rowOf(cRef(a.Name), cText(a.ID), cMeta(a.Version)))
269 }
270 s.sections = append(s.sections, aside)
271 }
203 s.actions = []action{{"Deps", []string{"repo", "deps", "disable", repo.Path()}}} 272 s.actions = []action{{"Deps", []string{"repo", "deps", "disable", repo.Path()}}}
273 if len(out.Advisories) > 0 {
274 s.actions = append(s.actions, action{"Deps", []string{"repo", "deps", "dismiss", repo.Path(), "<id>", "--reason", "<why>"}})
275 }
204 return s 276 return s
205 }) 277 })
206} 278}
279
280func runDepsDismiss(c *Ctx, args []string) int {
281 f, err := c.parseArgs(args, flagSpec{Values: []string{"--reason"}, MaxPos: -1, Usage: c.Cmd.Usage})
282 if err != nil {
283 return c.fail(protocol.ExitUsage, "%v", err)
284 }
285 if len(f.Pos) < 2 {
286 return c.usage()
287 }
288 reason := f.Value("--reason")
289 if !slices.Contains(advisoryReasons, reason) {
290 return c.fail(protocol.ExitUsage, "--reason is one of %s", strings.Join(advisoryReasons, ", "))
291 }
292 return changeAdvisoryDismissals(c, f.Pos[0], f.Pos[1:], func(repoID int64, ids []string) error {
293 return c.Store.DismissAdvisories(repoID, c.User.ID, ids, reason)
294 }, "dismissed")
295}
296
297func runDepsReopen(c *Ctx, args []string) int {
298 if len(args) < 2 {
299 return c.usage()
300 }
301 return changeAdvisoryDismissals(c, args[0], args[1:], c.Store.ReopenAdvisories, "reopened")
302}
303
304// changeAdvisoryDismissals checks advisory ids against the last check's
305// matches, applies change, and rewrites the issue to match. Writers may do
306// it, as for code scanning.
307func changeAdvisoryDismissals(c *Ctx, name string, ids []string, change func(int64, []string) error, verb string) int {
308 repo, code := resolveRepo(c, name, policy.CanWrite)
309 if code >= 0 {
310 return code
311 }
312 if _, err := c.Store.DepCheckFor(repo.ID); errors.Is(err, store.ErrNotFound) {
313 return c.fail(protocol.ExitFailure, "dependency checks are off on %s (repo deps enable %s)", repo.Path(), repo.Path())
314 } else if err != nil {
315 return c.fail(protocol.ExitFailure, "%v", err)
316 }
317 matched, err := c.Store.ReportedAdvisories(repo.ID)
318 if err != nil {
319 return c.fail(protocol.ExitFailure, "%v", err)
320 }
321 var known []string
322 for _, a := range matched {
323 known = append(known, a.ID)
324 }
325 var unique []string
326 for _, id := range ids {
327 if !slices.Contains(known, id) {
328 return c.fail(protocol.ExitNotFound, "no advisory %q in the last check", id)
329 }
330 if !slices.Contains(unique, id) {
331 unique = append(unique, id)
332 }
333 }
334 if err := change(repo.ID, unique); err != nil {
335 return c.fail(protocol.ExitFailure, "%v", err)
336 }
337 if err := deps.MaintainAdvisories(c.Store, c.Cfg, repo, matched, true, func() error { return nil }); err != nil {
338 return c.fail(protocol.ExitFailure, "%v", err)
339 }
340 return c.emit(map[string]any{verb: unique}, func(w io.Writer) {
341 fmt.Fprintf(w, "%s %d on %s\n", verb, len(unique), repo.Path())
342 })
343}
internal/control/stage3repo_test.go +55
@@ -350,3 +350,58 @@ func TestRepoDepsStatusAdvisories(t *testing.T) {
350 } 350 }
351 checkLegend(t, out) 351 checkLegend(t, out)
352} 352}
353
354// Dismissing an advisory takes it out of the issue and closes the issue
355// once none are open; one nothing imports is listed apart; reopening brings
356// a dismissed one back.
357func TestRepoDepsDismiss(t *testing.T) {
358 st, repo, u, root := browseFixture(t)
359 p := repo.Path()
360 dispatchIn(t, st, u, root, "", "repo", "deps", "enable", p)
361 matched := []store.DepAdvisory{
362 {Ecosystem: "go", Name: "golang.org/x/net", Version: "v0.1.0", ID: "GO-2026-1", Summary: "reset flood"},
363 {Ecosystem: "go", Name: "golang.org/x/crypto", Version: "v0.58.0", ID: "GO-2026-5932", Summary: "openpgp", NotImported: true},
364 }
365 if err := st.ReplaceDepAdvisories(repo.ID, matched); err != nil {
366 t.Fatal(err)
367 }
368 c, out := runnerCtx(st, u.ID, root)
369 if code := runDepsDismiss(c, []string{p, "GO-2026-1", "--reason", "nope"}); code != protocol.ExitUsage {
370 t.Errorf("bad reason: %d %s", code, out)
371 }
372 c, out = runnerCtx(st, u.ID, root)
373 if code := runDepsDismiss(c, []string{p, "GO-9", "--reason", "not-affected"}); code != protocol.ExitNotFound {
374 t.Errorf("unknown advisory: %d %s", code, out)
375 }
376 // Reopen first so there is an issue to watch: a reopen of nothing
377 // dismissed still rewrites it.
378 c, out = runnerCtx(st, u.ID, root)
379 if code := runDepsReopen(c, []string{p, "GO-2026-1"}); code != protocol.ExitOK {
380 t.Fatalf("reopen: %d %s", code, out)
381 }
382 check, _ := st.DepCheckFor(repo.ID)
383 issue, _ := st.IssueByNumber(repo.ID, check.AdvisoryIssueNumber)
384 if issue.State != "open" || !strings.Contains(issue.Body, "GO-2026-1:") || !strings.Contains(issue.Body, "imports: GO-2026-5932") {
385 t.Fatalf("issue (%s):\n%s", issue.State, issue.Body)
386 }
387 c, out = runnerCtx(st, u.ID, root)
388 if code := runDepsDismiss(c, []string{p, "GO-2026-1", "--reason", "not-affected"}); code != protocol.ExitOK {
389 t.Fatalf("dismiss: %d %s", code, out)
390 }
391 if closed, _ := st.IssueByNumber(repo.ID, check.AdvisoryIssueNumber); closed.State != "closed" {
392 t.Errorf("issue with nothing open is %s", closed.State)
393 }
394 var got struct {
395 Data DepsOut `json:"data"`
396 }
397 json.Unmarshal([]byte(dispatchIn(t, st, u, root, "", "repo", "deps", "status", p, "--json")), &got)
398 if len(got.Data.Advisories) != 0 || len(got.Data.Dismissed) != 1 || got.Data.Dismissed[0].Reason != "not-affected" ||
399 len(got.Data.NotImported) != 1 || got.Data.NotImported[0].ID != "GO-2026-5932" {
400 t.Errorf("status = %+v", got.Data)
401 }
402 screen := atTerminalIn(t, st, u, root, "repo", "deps", "status", p)
403 if !strings.Contains(screen, "Dismissed (1)") || !strings.Contains(screen, "Not imported (1)") {
404 t.Errorf("screen:\n%s", screen)
405 }
406 checkLegend(t, screen)
407}
internal/deps/imports.go added +83
@@ -0,0 +1,83 @@
1package deps
2
3import (
4 "context"
5 "go/parser"
6 "go/token"
7 "strconv"
8 "strings"
9
10 "gitbay.org/gitbay/internal/gitutil"
11 "gitbay.org/gitbay/internal/store"
12)
13
14// maxGoFiles bounds the Go files read for their imports. A repository with
15// more is not judged: its Go advisories are all reported.
16const maxGoFiles = 5000
17
18// GoImports returns the packages the Go files at sha import, tests
19// included, outside vendor and testdata. ok is false when they could not
20// all be read.
21func GoImports(ctx context.Context, dir, sha string) (map[string]bool, bool) {
22 entries, err := gitutil.ListBlobs(ctx, dir, sha)
23 if err != nil {
24 return nil, false
25 }
26 var shas []string
27 for _, e := range entries {
28 if !strings.HasSuffix(e.Name, ".go") || underAny(e.Name, "vendor", "testdata") {
29 continue
30 }
31 shas = append(shas, e.SHA)
32 }
33 if len(shas) > maxGoFiles {
34 return nil, false
35 }
36 out := map[string]bool{}
37 fset := token.NewFileSet()
38 err = gitutil.CatBlobs(ctx, dir, shas, func(_ int, data []byte) bool {
39 f, err := parser.ParseFile(fset, "", data, parser.ImportsOnly)
40 if err != nil {
41 return true // a file that does not parse does not build either
42 }
43 for _, imp := range f.Imports {
44 if p, err := strconv.Unquote(imp.Path.Value); err == nil {
45 out[p] = true
46 }
47 }
48 return true
49 })
50 if err != nil {
51 return nil, false
52 }
53 return out, true
54}
55
56func underAny(path string, dirs ...string) bool {
57 for _, part := range strings.Split(path, "/") {
58 for _, d := range dirs {
59 if part == d {
60 return true
61 }
62 }
63 }
64 return false
65}
66
67// MarkNotImported sets NotImported on each Go advisory that names packages
68// none of which imported holds.
69func MarkNotImported(matched []store.DepAdvisory, imported map[string]bool) {
70 for i, a := range matched {
71 if a.Ecosystem != EcoGo || len(a.Imports) == 0 {
72 continue
73 }
74 used := false
75 for _, p := range a.Imports {
76 if imported[p] {
77 used = true
78 break
79 }
80 }
81 matched[i].NotImported = !used
82 }
83}
internal/deps/osv.go +24 −1
@@ -64,6 +64,11 @@ type osvVuln struct {
64 Fixed string `json:"fixed"` 64 Fixed string `json:"fixed"`
65 } `json:"events"` 65 } `json:"events"`
66 } `json:"ranges"` 66 } `json:"ranges"`
67 EcosystemSpecific struct {
68 Imports []struct {
69 Path string `json:"path"`
70 } `json:"imports"`
71 } `json:"ecosystem_specific"`
67 } `json:"affected"` 72 } `json:"affected"`
68 DatabaseSpecific struct { 73 DatabaseSpecific struct {
69 Severity string `json:"severity"` 74 Severity string `json:"severity"`
@@ -98,7 +103,8 @@ func (c *Client) Advisories(ctx context.Context, found []Dep) ([]store.DepAdviso
98 out = append(out, store.DepAdvisory{ 103 out = append(out, store.DepAdvisory{
99 Ecosystem: d.Ecosystem, Name: d.Name, Version: d.Current, ID: v.ID, 104 Ecosystem: d.Ecosystem, Name: d.Name, Version: d.Current, ID: v.ID,
100 Summary: summarize(v), Severity: strings.ToLower(v.DatabaseSpecific.Severity), 105 Summary: summarize(v), Severity: strings.ToLower(v.DatabaseSpecific.Severity),
101 Fixed: fixedAfter(v, osvEcosystems[d.Ecosystem], d.Name, d.Current), 106 Fixed: fixedAfter(v, osvEcosystems[d.Ecosystem], d.Name, d.Current),
107 Imports: importsOf(v, osvEcosystems[d.Ecosystem], d.Name),
102 }) 108 })
103 } 109 }
104 } 110 }
@@ -300,3 +306,20 @@ func fixedAfter(v osvVuln, ecosystem, name, current string) string {
300 } 306 }
301 return best 307 return best
302} 308}
309
310// importsOf returns the packages of a module an advisory names, which Go
311// advisories carry and others do not.
312func importsOf(v osvVuln, ecosystem, name string) []string {
313 var out []string
314 for _, a := range v.Affected {
315 if a.Package.Ecosystem != ecosystem || a.Package.Name != name {
316 continue
317 }
318 for _, imp := range a.EcosystemSpecific.Imports {
319 if imp.Path != "" {
320 out = append(out, imp.Path)
321 }
322 }
323 }
324 return out
325}
internal/deps/osv_test.go +3 −2
@@ -55,7 +55,7 @@ func TestAdvisories(t *testing.T) {
55 "affected":[{"package":{"ecosystem":"PyPI","name":"flask"}, 55 "affected":[{"package":{"ecosystem":"PyPI","name":"flask"},
56 "ranges":[{"events":[{"introduced":"0"},{"fixed":"1.9.0"}]},{"events":[{"introduced":"2.0.0"},{"fixed":"2.3.2"}]},{"events":[{"introduced":"2.0.0"},{"fixed":"2.2.5"}]}]}]}`, 56 "ranges":[{"events":[{"introduced":"0"},{"fixed":"1.9.0"}]},{"events":[{"introduced":"2.0.0"},{"fixed":"2.3.2"}]},{"events":[{"introduced":"2.0.0"},{"fixed":"2.2.5"}]}]}]}`,
57 "PYSEC-1": `{"id":"PYSEC-1","summary":"duplicate","aliases":["GHSA-aaaa"]}`, 57 "PYSEC-1": `{"id":"PYSEC-1","summary":"duplicate","aliases":["GHSA-aaaa"]}`,
58 "GO-2": `{"id":"GO-2","details":"First line.\nSecond line.","affected":[{"package":{"ecosystem":"Go","name":"golang.org/x/net"},"ranges":[{"events":[{"fixed":"0.7.0"}]}]}]}`, 58 "GO-2": `{"id":"GO-2","details":"First line.\nSecond line.","affected":[{"package":{"ecosystem":"Go","name":"golang.org/x/net"},"ranges":[{"events":[{"fixed":"0.7.0"}]}],"ecosystem_specific":{"imports":[{"path":"golang.org/x/net/http2"}]}}]}`,
59 "GO-withdrawn": `{"id":"GO-withdrawn","withdrawn":"2026-01-01T00:00:00Z"}`, 59 "GO-withdrawn": `{"id":"GO-withdrawn","withdrawn":"2026-01-01T00:00:00Z"}`,
60 "GHSA-vapor": `{"id":"GHSA-vapor","summary":"no fix"}`, 60 "GHSA-vapor": `{"id":"GHSA-vapor","summary":"no fix"}`,
61 }) 61 })
@@ -73,7 +73,8 @@ func TestAdvisories(t *testing.T) {
73 if len(got) != 3 { 73 if len(got) != 3 {
74 t.Fatalf("advisories = %+v, want GO-2, GHSA-aaaa once, GHSA-vapor", got) 74 t.Fatalf("advisories = %+v, want GO-2, GHSA-aaaa once, GHSA-vapor", got)
75 } 75 }
76 if a := got[0]; a.ID != "GO-2" || a.Summary != "First line." || a.Fixed != "0.7.0" || a.Severity != "" { 76 if a := got[0]; a.ID != "GO-2" || a.Summary != "First line." || a.Fixed != "0.7.0" || a.Severity != "" ||
77 strings.Join(a.Imports, " ") != "golang.org/x/net/http2" {
77 t.Errorf("go advisory = %+v", a) 78 t.Errorf("go advisory = %+v", a)
78 } 79 }
79 // The alias is folded in, the summary's whitespace collapsed, and the 80 // The alias is folded in, the summary's whitespace collapsed, and the
internal/deps/report.go +80 −12
@@ -5,6 +5,8 @@ import (
5 "sort" 5 "sort"
6 "strings" 6 "strings"
7 7
8 "gitbay.org/gitbay/internal/botissue"
9 "gitbay.org/gitbay/internal/config"
8 "gitbay.org/gitbay/internal/store" 10 "gitbay.org/gitbay/internal/store"
9) 11)
10 12
@@ -53,15 +55,25 @@ func Body(branch string, reports []store.DepReport) string {
53 return b.String() 55 return b.String()
54} 56}
55 57
58// AdvisoryReport is what the advisories issue says: the advisories still
59// open, how many were dismissed, and the Go ones set aside because no file
60// imports the packages they name.
61type AdvisoryReport struct {
62 Repo, Branch string
63 Open []store.DepAdvisory
64 Dismissed int
65 NotImported []store.DepAdvisory
66}
67
56// AdvisoryBody renders the advisories issue: a table per ecosystem, then 68// AdvisoryBody renders the advisories issue: a table per ecosystem, then
57// each advisory's summary and link, which would make the table too wide to 69// each advisory's summary and link, which would make the table too wide to
58// read as plain text. 70// read as plain text, then what is not listed.
59func AdvisoryBody(branch string, matched []store.DepAdvisory) string { 71func AdvisoryBody(r AdvisoryReport) string {
60 var b strings.Builder 72 var b strings.Builder
61 fmt.Fprintf(&b, "Dependencies resolved on `%s` match published advisories. "+ 73 fmt.Fprintf(&b, "Dependencies resolved on `%s` match published advisories. "+
62 "This issue is kept up to date as that changes, and closed once none match.\n", branch) 74 "This issue is kept up to date as that changes, and closed once none are open.\n", r.Branch)
63 byEco := map[string][]store.DepAdvisory{} 75 byEco := map[string][]store.DepAdvisory{}
64 for _, a := range matched { 76 for _, a := range r.Open {
65 byEco[a.Ecosystem] = append(byEco[a.Ecosystem], a) 77 byEco[a.Ecosystem] = append(byEco[a.Ecosystem], a)
66 } 78 }
67 for _, eco := range order { 79 for _, eco := range order {
@@ -76,18 +88,73 @@ func AdvisoryBody(branch string, matched []store.DepAdvisory) string {
76 } 88 }
77 b.WriteString(table(cells)) 89 b.WriteString(table(cells))
78 } 90 }
79 b.WriteString("\n### Advisories\n\n") 91 if len(r.Open) > 0 {
80 seen := map[string]bool{} 92 b.WriteString("\n### Advisories\n\n")
81 for _, a := range matched { 93 seen := map[string]bool{}
82 if seen[a.ID] { 94 for _, a := range r.Open {
83 continue 95 if seen[a.ID] {
96 continue
97 }
98 seen[a.ID] = true
99 fmt.Fprintf(&b, "- %s: %s https://osv.dev/vulnerability/%s\n", a.ID, a.Summary, a.ID)
100 }
101 }
102 var notListed []string
103 if r.Dismissed > 0 {
104 notListed = append(notListed, fmt.Sprintf("%d dismissed", r.Dismissed))
105 }
106 if len(r.NotImported) > 0 {
107 var ids []string
108 for _, a := range r.NotImported {
109 ids = append(ids, fmt.Sprintf("%s (`%s`)", a.ID, a.Name))
84 } 110 }
85 seen[a.ID] = true 111 notListed = append(notListed, "for Go packages no file here imports: "+strings.Join(ids, ", "))
86 fmt.Fprintf(&b, "- %s: %s https://osv.dev/vulnerability/%s\n", a.ID, a.Summary, a.ID) 112 }
113 if len(notListed) > 0 {
114 fmt.Fprintf(&b, "\nNot listed: %s. Imports through another module are not seen here. `repo deps status %s` shows them.\n",
115 strings.Join(notListed, "; "), r.Repo)
116 }
117 if len(r.Open) > 0 {
118 fmt.Fprintf(&b, "\nTo dismiss one: `repo deps dismiss %s <advisory> --reason not-affected|wont-fix|dev-only`.\n", r.Repo)
87 } 119 }
88 return b.String() 120 return b.String()
89} 121}
90 122
123// MaintainAdvisories brings the advisories issue in line with a matching
124// set: the open ones listed, the dismissed and not imported ones counted,
125// closed when none are open.
126func MaintainAdvisories(st *store.Store, cfg config.Config, repo store.Repo, matched []store.DepAdvisory,
127 changed bool, save func() error) error {
128 check, err := st.DepCheckFor(repo.ID)
129 if err != nil {
130 return err
131 }
132 dismissed, err := st.AdvisoryDismissals(repo.ID)
133 if err != nil {
134 return err
135 }
136 r := AdvisoryReport{Repo: repo.Path(), Branch: repo.DefaultBranch}
137 for _, a := range matched {
138 switch {
139 case a.NotImported:
140 r.NotImported = append(r.NotImported, a)
141 case dismissed[a.ID].ID != "":
142 r.Dismissed++
143 default:
144 r.Open = append(r.Open, a)
145 }
146 }
147 return botissue.Maintain(st, cfg, repo, botissue.Tracked{
148 Title: AdvisoryTitle,
149 Number: check.AdvisoryIssueNumber,
150 Record: func(n int64) error { return st.SetDepAdvisoryIssue(repo.ID, n) },
151 Empty: len(r.Open) == 0,
152 Changed: changed,
153 Save: save,
154 Body: func() string { return AdvisoryBody(r) },
155 })
156}
157
91// table pads every cell to its column, because the body is read twice: as 158// table pads every cell to its column, because the body is read twice: as
92// a rendered table on the web, where the padding is ignored, and as the 159// a rendered table on the web, where the padding is ignored, and as the
93// plain text of the notification mail, where it is the only thing keeping 160// plain text of the notification mail, where it is the only thing keeping
@@ -145,7 +212,8 @@ func sameAdvisories(a, b []store.DepAdvisory) bool {
145 } 212 }
146 for i := range a { 213 for i := range a {
147 if a[i].Ecosystem != b[i].Ecosystem || a[i].Name != b[i].Name || 214 if a[i].Ecosystem != b[i].Ecosystem || a[i].Name != b[i].Name ||
148 a[i].Version != b[i].Version || a[i].ID != b[i].ID || a[i].Fixed != b[i].Fixed { 215 a[i].Version != b[i].Version || a[i].ID != b[i].ID || a[i].Fixed != b[i].Fixed ||
216 a[i].NotImported != b[i].NotImported {
149 return false 217 return false
150 } 218 }
151 } 219 }
internal/deps/report_test.go +21 −2
@@ -43,17 +43,36 @@ func TestBodyAlignsColumns(t *testing.T) {
43} 43}
44 44
45func TestAdvisoryBody(t *testing.T) { 45func TestAdvisoryBody(t *testing.T) {
46 body := AdvisoryBody("main", []store.DepAdvisory{ 46 body := AdvisoryBody(AdvisoryReport{Repo: "krz/x", Branch: "main", Open: []store.DepAdvisory{
47 {Ecosystem: EcoGo, Name: "golang.org/x/net", Version: "v0.1.0", ID: "GO-2", Summary: "HTTP/2 reset", Severity: "", Fixed: "0.7.0"}, 47 {Ecosystem: EcoGo, Name: "golang.org/x/net", Version: "v0.1.0", ID: "GO-2", Summary: "HTTP/2 reset", Severity: "", Fixed: "0.7.0"},
48 {Ecosystem: EcoPyPI, Name: "flask", Version: "2.0.0", ID: "GHSA-aaaa", Summary: "cookie leak", Severity: "high", Fixed: "2.2.5"}, 48 {Ecosystem: EcoPyPI, Name: "flask", Version: "2.0.0", ID: "GHSA-aaaa", Summary: "cookie leak", Severity: "high", Fixed: "2.2.5"},
49 }) 49 }, Dismissed: 2, NotImported: []store.DepAdvisory{{Ecosystem: EcoGo, Name: "golang.org/x/crypto", ID: "GO-3"}}})
50 for _, want := range []string{ 50 for _, want := range []string{
51 "| `golang.org/x/net` | v0.1.0 | GO-2 | | 0.7.0 |", 51 "| `golang.org/x/net` | v0.1.0 | GO-2 | | 0.7.0 |",
52 "- GHSA-aaaa: cookie leak https://osv.dev/vulnerability/GHSA-aaaa", 52 "- GHSA-aaaa: cookie leak https://osv.dev/vulnerability/GHSA-aaaa",
53 "### PyPI", 53 "### PyPI",
54 "Not listed: 2 dismissed; for Go packages no file here imports: GO-3 (`golang.org/x/crypto`).",
55 "repo deps dismiss krz/x <advisory>",
54 } { 56 } {
55 if !strings.Contains(body, want) { 57 if !strings.Contains(body, want) {
56 t.Errorf("body missing %q:\n%s", want, body) 58 t.Errorf("body missing %q:\n%s", want, body)
57 } 59 }
58 } 60 }
59} 61}
62
63// An advisory naming packages is set aside unless one of them is imported;
64// one naming none, or of another ecosystem, is left alone.
65func TestMarkNotImported(t *testing.T) {
66 matched := []store.DepAdvisory{
67 {Ecosystem: EcoGo, ID: "GO-1", Imports: []string{"golang.org/x/crypto/openpgp", "golang.org/x/crypto/openpgp/armor"}},
68 {Ecosystem: EcoGo, ID: "GO-2", Imports: []string{"golang.org/x/crypto/ssh"}},
69 {Ecosystem: EcoGo, ID: "GO-3"},
70 {Ecosystem: EcoNPM, ID: "GHSA-1", Imports: []string{"x"}},
71 }
72 MarkNotImported(matched, map[string]bool{"golang.org/x/crypto/ssh": true})
73 for i, want := range []bool{true, false, false, false} {
74 if matched[i].NotImported != want {
75 t.Errorf("%s: NotImported = %v", matched[i].ID, matched[i].NotImported)
76 }
77 }
78}
internal/deps/worker.go +15 −15
@@ -105,7 +105,7 @@ func (w *Worker) check(ctx context.Context, repo store.Repo) error {
105 } 105 }
106 return errors.Join( 106 return errors.Join(
107 w.checkUpdates(ctx, repo, Scan(read)), 107 w.checkUpdates(ctx, repo, Scan(read)),
108 w.checkAdvisories(ctx, repo, Resolved(read, root)), 108 w.checkAdvisories(ctx, repo, dir, sha, Resolved(read, root)),
109 ) 109 )
110} 110}
111 111
@@ -120,7 +120,10 @@ func (w *Worker) checkUpdates(ctx context.Context, repo store.Repo, found []Dep)
120 return w.reconcile(repo, behind) 120 return w.reconcile(repo, behind)
121} 121}
122 122
123func (w *Worker) checkAdvisories(ctx context.Context, repo store.Repo, resolved []Dep) error { 123// checkAdvisories matches the resolved set against OSV. A Go advisory that
124// names packages counts only if a Go file at sha imports one of them; the
125// files are read only when such an advisory matched.
126func (w *Worker) checkAdvisories(ctx context.Context, repo store.Repo, dir, sha string, resolved []Dep) error {
124 if len(resolved) == 0 { 127 if len(resolved) == 0 {
125 return w.reconcileAdvisories(repo, nil) 128 return w.reconcileAdvisories(repo, nil)
126 } 129 }
@@ -128,6 +131,14 @@ func (w *Worker) checkAdvisories(ctx context.Context, repo store.Repo, resolved
128 if err != nil { 131 if err != nil {
129 return fmt.Errorf("advisories: %w", err) 132 return fmt.Errorf("advisories: %w", err)
130 } 133 }
134 for _, a := range matched {
135 if a.Ecosystem == EcoGo && len(a.Imports) > 0 {
136 if imported, ok := GoImports(ctx, dir, sha); ok {
137 MarkNotImported(matched, imported)
138 }
139 break
140 }
141 }
131 return w.reconcileAdvisories(repo, matched) 142 return w.reconcileAdvisories(repo, matched)
132} 143}
133 144
@@ -203,21 +214,10 @@ func (w *Worker) reconcile(repo store.Repo, behind []store.DepReport) error {
203// reconcileAdvisories brings the advisories issue in line with what 214// reconcileAdvisories brings the advisories issue in line with what
204// matches. 215// matches.
205func (w *Worker) reconcileAdvisories(repo store.Repo, matched []store.DepAdvisory) error { 216func (w *Worker) reconcileAdvisories(repo store.Repo, matched []store.DepAdvisory) error {
206 check, err := w.St.DepCheckFor(repo.ID)
207 if err != nil {
208 return err
209 }
210 previous, err := w.St.ReportedAdvisories(repo.ID) 217 previous, err := w.St.ReportedAdvisories(repo.ID)
211 if err != nil { 218 if err != nil {
212 return err 219 return err
213 } 220 }
214 return botissue.Maintain(w.St, w.Cfg, repo, botissue.Tracked{ 221 return MaintainAdvisories(w.St, w.Cfg, repo, matched, !sameAdvisories(previous, matched),
215 Title: AdvisoryTitle, 222 func() error { return w.St.ReplaceDepAdvisories(repo.ID, matched) })
216 Number: check.AdvisoryIssueNumber,
217 Record: func(n int64) error { return w.St.SetDepAdvisoryIssue(repo.ID, n) },
218 Empty: len(matched) == 0,
219 Changed: !sameAdvisories(previous, matched),
220 Save: func() error { return w.St.ReplaceDepAdvisories(repo.ID, matched) },
221 Body: func() string { return AdvisoryBody(repo.DefaultBranch, matched) },
222 })
223} 223}
internal/deps/worker_test.go +71
@@ -2,6 +2,8 @@ package deps
2 2
3import ( 3import (
4 "context" 4 "context"
5 "os"
6 "os/exec"
5 "path/filepath" 7 "path/filepath"
6 "strings" 8 "strings"
7 "testing" 9 "testing"
@@ -271,3 +273,72 @@ func TestReconcileAdvisoriesKeepsItsOwnIssue(t *testing.T) {
271 t.Errorf("advisories left behind: %v", left) 273 t.Errorf("advisories left behind: %v", left)
272 } 274 }
273} 275}
276
277// A Go advisory for packages nothing imports opens no issue, and one
278// alongside an open advisory is counted rather than listed.
279func TestReconcileAdvisoriesNotImported(t *testing.T) {
280 w, repo := testWorker(t)
281 aside := store.DepAdvisory{Ecosystem: EcoGo, Name: "golang.org/x/crypto", Version: "v0.58.0",
282 ID: "GO-2026-5932", Summary: "openpgp is unmaintained", NotImported: true}
283 if err := w.reconcileAdvisories(repo, []store.DepAdvisory{aside}); err != nil {
284 t.Fatal(err)
285 }
286 if check, _ := w.St.DepCheckFor(repo.ID); check.AdvisoryIssueNumber != 0 {
287 t.Fatalf("opened #%d for an advisory nothing imports", check.AdvisoryIssueNumber)
288 }
289 if kept, _ := w.St.ReportedAdvisories(repo.ID); len(kept) != 1 || !kept[0].NotImported {
290 t.Fatalf("stored %+v", kept)
291 }
292 open := store.DepAdvisory{Ecosystem: EcoGo, Name: "golang.org/x/net", Version: "v0.1.0", ID: "GO-2", Summary: "reset"}
293 if err := w.reconcileAdvisories(repo, []store.DepAdvisory{aside, open}); err != nil {
294 t.Fatal(err)
295 }
296 check, _ := w.St.DepCheckFor(repo.ID)
297 issue, _ := w.St.IssueByNumber(repo.ID, check.AdvisoryIssueNumber)
298 if !strings.Contains(issue.Body, "GO-2:") || strings.Contains(issue.Body, "- GO-2026-5932:") ||
299 !strings.Contains(issue.Body, "no file here imports: GO-2026-5932") {
300 t.Errorf("issue:\n%s", issue.Body)
301 }
302}
303
304// GoImports reads every Go file's imports, tests included, and leaves out
305// vendor and testdata.
306func TestGoImports(t *testing.T) {
307 dir := t.TempDir()
308 run := func(args ...string) string {
309 t.Helper()
310 cmd := exec.Command("git", args...)
311 cmd.Dir = dir
312 cmd.Env = append(os.Environ(), "GIT_CONFIG_NOSYSTEM=1", "GIT_CONFIG_GLOBAL=/dev/null",
313 "GIT_AUTHOR_NAME=t", "GIT_AUTHOR_EMAIL=t@example.test", "GIT_COMMITTER_NAME=t", "GIT_COMMITTER_EMAIL=t@example.test")
314 out, err := cmd.CombinedOutput()
315 if err != nil {
316 t.Fatalf("git %v: %v\n%s", args, err, out)
317 }
318 return strings.TrimSpace(string(out))
319 }
320 files := map[string]string{
321 "main.go": "package main\n\nimport (\n\t\"fmt\"\n\tx \"golang.org/x/crypto/ssh\"\n)\n",
322 "a_test.go": "package main\n\nimport \"golang.org/x/net/html\"\n",
323 "vendor/v/v.go": "package v\n\nimport \"golang.org/x/crypto/openpgp\"\n",
324 "testdata/t.go": "package t\n\nimport \"golang.org/x/crypto/openpgp/armor\"\n",
325 "broken.go": "this is not go",
326 }
327 for name, body := range files {
328 os.MkdirAll(filepath.Join(dir, filepath.Dir(name)), 0o755)
329 os.WriteFile(filepath.Join(dir, name), []byte(body), 0o644)
330 }
331 run("init", "-q", "-b", "main")
332 run("add", ".")
333 run("commit", "-q", "-m", "x")
334 got, ok := GoImports(context.Background(), dir, run("rev-parse", "HEAD"))
335 if !ok {
336 t.Fatal("not ok")
337 }
338 for p, want := range map[string]bool{"fmt": true, "golang.org/x/crypto/ssh": true, "golang.org/x/net/html": true,
339 "golang.org/x/crypto/openpgp": false, "golang.org/x/crypto/openpgp/armor": false} {
340 if got[p] != want {
341 t.Errorf("%s: %v", p, got[p])
342 }
343 }
344}
internal/httpd/depspage_test.go +28
@@ -74,3 +74,31 @@ func TestSettingsPageRendersSecurityTriage(t *testing.T) {
74 } 74 }
75 } 75 }
76} 76}
77
78// The advisories offer dismissal, the dismissed ones reopening, and the
79// ones nothing imports are named.
80func TestSettingsPageRendersAdvisoryTriage(t *testing.T) {
81 var sb strings.Builder
82 err := web.Render(&sb, "settings.html", settingsPage{
83 repoPage: testRepoPage(),
84 DepsEnabled: true,
85 Deps: control.DepsOut{
86 Enabled: true, LastCheck: "2026-11-01T04:02:00Z",
87 Advisories: []control.DepAdvisory{{Ecosystem: "go", Name: "golang.org/x/net", Version: "v0.1.0", ID: "GO-2026-1"}},
88 Dismissed: []control.DepAdvisory{{Ecosystem: "npm", Name: "undici", ID: "GHSA-x", Reason: "dev-only", By: "alice"}},
89 NotImported: []control.DepAdvisory{{Ecosystem: "go", Name: "golang.org/x/crypto", ID: "GO-2026-5932"}},
90 },
91 })
92 if err != nil {
93 t.Fatal(err)
94 }
95 page := sb.String()
96 for _, want := range []string{
97 `value="deps-dismiss"`, `name="advisory" value="GO-2026-1"`, `value="deps-reopen"`, `value="GHSA-x"`,
98 "dev-only", "by alice", "GO-2026-5932</a> (golang.org/x/crypto)",
99 } {
100 if !strings.Contains(page, want) {
101 t.Errorf("settings page does not show %q", want)
102 }
103 }
104}
internal/httpd/settings.go +4
@@ -169,6 +169,10 @@ func (s *Server) settingsSubmit(w http.ResponseWriter, r *http.Request, u store.
169 verb = "enable" 169 verb = "enable"
170 } 170 }
171 argv = []string{"repo", "security", verb, repo} 171 argv = []string{"repo", "security", verb, repo}
172 case "deps-dismiss":
173 argv = []string{"repo", "deps", "dismiss", repo, v("advisory"), "--reason", v("reason")}
174 case "deps-reopen":
175 argv = []string{"repo", "deps", "reopen", repo, v("advisory")}
172 case "security-dismiss": 176 case "security-dismiss":
173 argv = []string{"repo", "security", "dismiss", repo, v("fingerprint"), "--reason", v("reason")} 177 argv = []string{"repo", "security", "dismiss", repo, v("fingerprint"), "--reason", v("reason")}
174 case "security-reopen": 178 case "security-reopen":
internal/store/deps.go +75 −5
@@ -40,6 +40,12 @@ type DepAdvisory struct {
40 Summary string 40 Summary string
41 Severity string 41 Severity string
42 Fixed string // the first release past Version that fixes it, if any 42 Fixed string // the first release past Version that fixes it, if any
43 // NotImported marks a Go advisory whose packages no Go file in the
44 // repository imports; it is kept but not reported.
45 NotImported bool
46 // Imports are the packages the advisory names (Go), for deciding
47 // NotImported. Not stored.
48 Imports []string
43} 49}
44 50
45func (s *Store) EnableDepCheck(repoID int64) error { 51func (s *Store) EnableDepCheck(repoID int64) error {
@@ -166,7 +172,7 @@ func (s *Store) ReplaceDepReports(repoID int64, reports []DepReport) error {
166 172
167func (s *Store) ReportedAdvisories(repoID int64) ([]DepAdvisory, error) { 173func (s *Store) ReportedAdvisories(repoID int64) ([]DepAdvisory, error) {
168 rows, err := s.DB.Query(` 174 rows, err := s.DB.Query(`
169 SELECT ecosystem, name, version, advisory_id, summary, severity, fixed FROM dep_advisories 175 SELECT ecosystem, name, version, advisory_id, summary, severity, fixed, not_imported FROM dep_advisories
170 WHERE repo_id = ? ORDER BY ecosystem, name, version, advisory_id`, repoID) 176 WHERE repo_id = ? ORDER BY ecosystem, name, version, advisory_id`, repoID)
171 if err != nil { 177 if err != nil {
172 return nil, err 178 return nil, err
@@ -175,7 +181,7 @@ func (s *Store) ReportedAdvisories(repoID int64) ([]DepAdvisory, error) {
175 var out []DepAdvisory 181 var out []DepAdvisory
176 for rows.Next() { 182 for rows.Next() {
177 var a DepAdvisory 183 var a DepAdvisory
178 if err := rows.Scan(&a.Ecosystem, &a.Name, &a.Version, &a.ID, &a.Summary, &a.Severity, &a.Fixed); err != nil { 184 if err := rows.Scan(&a.Ecosystem, &a.Name, &a.Version, &a.ID, &a.Summary, &a.Severity, &a.Fixed, &a.NotImported); err != nil {
179 return nil, err 185 return nil, err
180 } 186 }
181 out = append(out, a) 187 out = append(out, a)
@@ -196,11 +202,75 @@ func (s *Store) ReplaceDepAdvisories(repoID int64, advisories []DepAdvisory) err
196 } 202 }
197 for _, a := range advisories { 203 for _, a := range advisories {
198 if _, err := tx.Exec(` 204 if _, err := tx.Exec(`
199 INSERT INTO dep_advisories (repo_id, ecosystem, name, version, advisory_id, summary, severity, fixed) 205 INSERT INTO dep_advisories (repo_id, ecosystem, name, version, advisory_id, summary, severity, fixed, not_imported)
200 VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, 206 VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`,
201 repoID, a.Ecosystem, a.Name, a.Version, a.ID, a.Summary, a.Severity, a.Fixed); err != nil { 207 repoID, a.Ecosystem, a.Name, a.Version, a.ID, a.Summary, a.Severity, a.Fixed, a.NotImported); err != nil {
202 return err 208 return err
203 } 209 }
204 } 210 }
205 return tx.Commit() 211 return tx.Commit()
206} 212}
213
214// AdvisoryDismissal is an advisory a repository dismissed.
215type AdvisoryDismissal struct {
216 ID string
217 Reason string
218 By string // username, '' once the account is gone
219 CreatedAt string
220}
221
222// DismissAdvisories dismisses advisories by id, replacing the reason of
223// any already dismissed.
224func (s *Store) DismissAdvisories(repoID, byID int64, ids []string, reason string) error {
225 tx, err := s.DB.Begin()
226 if err != nil {
227 return err
228 }
229 defer tx.Rollback()
230 for _, id := range ids {
231 if _, err := tx.Exec(`
232 INSERT INTO dep_advisory_dismissals (repo_id, advisory_id, reason, by_id) VALUES (?, ?, ?, ?)
233 ON CONFLICT (repo_id, advisory_id) DO UPDATE SET reason = excluded.reason, by_id = excluded.by_id,
234 created_at = strftime('%Y-%m-%dT%H:%M:%fZ','now')`,
235 repoID, id, reason, byID); err != nil {
236 return err
237 }
238 }
239 return tx.Commit()
240}
241
242// ReopenAdvisories takes dismissals back.
243func (s *Store) ReopenAdvisories(repoID int64, ids []string) error {
244 tx, err := s.DB.Begin()
245 if err != nil {
246 return err
247 }
248 defer tx.Rollback()
249 for _, id := range ids {
250 if _, err := tx.Exec("DELETE FROM dep_advisory_dismissals WHERE repo_id = ? AND advisory_id = ?", repoID, id); err != nil {
251 return err
252 }
253 }
254 return tx.Commit()
255}
256
257// AdvisoryDismissals returns a repo's dismissals by advisory id.
258func (s *Store) AdvisoryDismissals(repoID int64) (map[string]AdvisoryDismissal, error) {
259 rows, err := s.DB.Query(`
260 SELECT d.advisory_id, d.reason, COALESCE(u.username, ''), d.created_at
261 FROM dep_advisory_dismissals d LEFT JOIN users u ON u.id = d.by_id
262 WHERE d.repo_id = ?`, repoID)
263 if err != nil {
264 return nil, err
265 }
266 defer rows.Close()
267 out := map[string]AdvisoryDismissal{}
268 for rows.Next() {
269 var d AdvisoryDismissal
270 if err := rows.Scan(&d.ID, &d.Reason, &d.By, &d.CreatedAt); err != nil {
271 return nil, err
272 }
273 out[d.ID] = d
274 }
275 return out, rows.Err()
276}
internal/store/migrations/0084_dep_advisory_dismissals.down.sql added +2
@@ -0,0 +1,2 @@
1ALTER TABLE dep_advisories DROP COLUMN not_imported;
2DROP TABLE dep_advisory_dismissals;
internal/store/migrations/0084_dep_advisory_dismissals.up.sql added +14
@@ -0,0 +1,14 @@
1-- An advisory a repository dismissed, by id, so it stays dismissed across
2-- checks. Kept while checks are off, as code scanning dismissals are.
3CREATE TABLE dep_advisory_dismissals (
4 repo_id INTEGER NOT NULL REFERENCES repos(id) ON DELETE CASCADE,
5 advisory_id TEXT NOT NULL,
6 reason TEXT NOT NULL,
7 by_id INTEGER REFERENCES users(id) ON DELETE SET NULL,
8 created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')),
9 PRIMARY KEY (repo_id, advisory_id)
10);
11
12-- A Go advisory naming packages none of the repository's Go files import.
13-- Kept so status can say what was set aside, but not reported.
14ALTER TABLE dep_advisories ADD COLUMN not_imported INTEGER NOT NULL DEFAULT 0;
internal/web/templates/settings.html +22 −2
@@ -308,15 +308,35 @@
308{{end}}</table></div> 308{{end}}</table></div>
309{{else}}<p class="none">Nothing behind{{if not .Deps.LastCheck}} — the first check has not run yet{{end}}.</p>{{end}} 309{{else}}<p class="none">Nothing behind{{if not .Deps.LastCheck}} — the first check has not run yet{{end}}.</p>{{end}}
310{{if .Deps.Advisories}}<div class="tablewrap"><table class="keys"> 310{{if .Deps.Advisories}}<div class="tablewrap"><table class="keys">
311<tr class="cols"><th scope="col">dependency</th><th scope="col">version</th><th scope="col">advisory</th><th scope="col">fixed in</th></tr> 311<tr class="cols"><th scope="col">dependency</th><th scope="col">version</th><th scope="col">advisory</th><th scope="col">fixed in</th><th scope="col"><span class="vh">dismiss</span></th></tr>
312{{range .Deps.Advisories}}<tr> 312{{range .Deps.Advisories}}<tr>
313 <td class="mono">{{.Ecosystem}} {{.Name}}</td> 313 <td class="mono">{{.Ecosystem}} {{.Name}}</td>
314 <td class="mono">{{.Version}}</td> 314 <td class="mono">{{.Version}}</td>
315 <td class="mono"><a href="https://osv.dev/vulnerability/{{.ID}}">{{.ID}}</a></td> 315 <td class="mono"><a href="https://osv.dev/vulnerability/{{.ID}}">{{.ID}}</a></td>
316 <td class="mono">{{.Fixed}}</td> 316 <td class="mono">{{.Fixed}}</td>
317 <td><form method="post" action="{{$base}}" class="inline">
318 <input type="hidden" name="field" value="deps-dismiss">
319 <input type="hidden" name="advisory" value="{{.ID}}">
320 <select name="reason" aria-label="Reason"><option value="not-affected">Not affected</option><option value="wont-fix">Won't fix</option><option value="dev-only">Development only</option></select>
321 <button type="submit">Dismiss</button>
322 </form></td>
317</tr> 323</tr>
318{{end}}</table></div> 324{{end}}</table></div>
319{{else if .Deps.LastCheck}}<p class="none">No known advisories.</p>{{end}} 325{{else if .Deps.LastCheck}}<p class="none">No open advisories.</p>{{end}}
326{{if .Deps.NotImported}}<p class="meta">Not imported by any Go file here, so not reported:{{range .Deps.NotImported}} <a href="https://osv.dev/vulnerability/{{.ID}}">{{.ID}}</a> ({{.Name}}){{end}}. Imports through another module are not seen.</p>{{end}}
327{{if .Deps.Dismissed}}<h3>Dismissed advisories</h3><div class="tablewrap"><table class="keys">
328<tr class="cols"><th scope="col">dependency</th><th scope="col">advisory</th><th scope="col">reason</th><th scope="col"><span class="vh">reopen</span></th></tr>
329{{range .Deps.Dismissed}}<tr>
330 <td class="mono">{{.Ecosystem}} {{.Name}}</td>
331 <td class="mono"><a href="https://osv.dev/vulnerability/{{.ID}}">{{.ID}}</a></td>
332 <td>{{.Reason}}{{if .By}} <span class="meta">by {{.By}}</span>{{end}}</td>
333 <td><form method="post" action="{{$base}}" class="inline">
334 <input type="hidden" name="field" value="deps-reopen">
335 <input type="hidden" name="advisory" value="{{.ID}}">
336 <button type="submit">Reopen</button>
337 </form></td>
338</tr>
339{{end}}</table></div>{{end}}
320{{end}} 340{{end}}
321</section> 341</section>
322 342