Skip to content

Commit 3d58640

Browse files
committed
cmd/issue: add command issue placeholder
Add a command, `issue placeholder` which can be used to publish a placeholder issue for a CVE. Example usage: `issue placeholder CVE-1234-5678 CVE-0000-1111` would create two issues on the x/vulndb tracker, one for each CVE. The placeholder issue does not reveal anything about the CVE, and the command is intended to be used to create tracking issues for CVEs that have been preannounced but not yet published. Change-Id: I95ace0eaffe83f77ebc58d4ec755f0276e748c02 Reviewed-on: https://go-review.googlesource.com/c/vulndb/+/559601 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Damien Neil <[email protected]>
1 parent 8127c87 commit 3d58640

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

cmd/issue/main.go

+32-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"strings"
2020

2121
"golang.org/x/vulndb/internal"
22+
"golang.org/x/vulndb/internal/cveschema5"
2223
"golang.org/x/vulndb/internal/ghsa"
2324
"golang.org/x/vulndb/internal/gitrepo"
2425
"golang.org/x/vulndb/internal/issues"
@@ -35,9 +36,12 @@ var (
3536
func main() {
3637
ctx := context.Background()
3738
flag.Usage = func() {
38-
fmt.Fprintf(flag.CommandLine.Output(), "usage: issue [cmd] [filename]\n")
39-
fmt.Fprintf(flag.CommandLine.Output(), " triage: [filename]\n")
40-
fmt.Fprintf(flag.CommandLine.Output(), " excluded: [filename]\n")
39+
fmt.Fprintf(flag.CommandLine.Output(), "usage: issue [cmd] [filename | cves]\n")
40+
fmt.Fprintf(flag.CommandLine.Output(), " triage [filename]: create issues to triage on the tracker for the aliases listed in the file\n")
41+
fmt.Fprintf(flag.CommandLine.Output(), " excluded [filename]: create excluded issues on the tracker for the aliases listed in the file\n")
42+
fmt.Fprintf(flag.CommandLine.Output(), " placeholder [cve(s)]: create a placeholder issue on the tracker for the given CVE(s)\n")
43+
fmt.Fprintf(flag.CommandLine.Output(), "\n")
44+
fmt.Fprintf(flag.CommandLine.Output(), "Flags:\n")
4145
flag.PrintDefaults()
4246
}
4347
flag.Parse()
@@ -59,6 +63,8 @@ func main() {
5963
err = createIssueToTriage(ctx, c, ghsaClient, pc, filename)
6064
case "excluded":
6165
err = createExcluded(ctx, c, ghsaClient, pc, filename)
66+
case "placeholder":
67+
err = createPlaceholder(ctx, c, flag.Args()[1:])
6268
default:
6369
err = fmt.Errorf("unsupported command: %q", cmd)
6470
}
@@ -93,6 +99,21 @@ func createExcluded(ctx context.Context, c *issues.Client, ghsaClient *ghsa.Clie
9399
return nil
94100
}
95101

102+
func createPlaceholder(ctx context.Context, c *issues.Client, args []string) error {
103+
for _, arg := range args {
104+
if !cveschema5.IsCVE(arg) {
105+
return fmt.Errorf("%q is not a CVE", arg)
106+
}
107+
aliases := []string{arg}
108+
packages := []string{"<placeholder>"}
109+
bodies := []string{fmt.Sprintf("This is a placeholder issue for %q.", arg)}
110+
if err := publishIssue(ctx, c, packages, aliases, bodies, []string{}); err != nil {
111+
return err
112+
}
113+
}
114+
return nil
115+
}
116+
96117
func constructIssue(ctx context.Context, c *issues.Client, ghsaClient *ghsa.Client, pc *proxy.Client, alias string, labels []string) (err error) {
97118
var ghsas []*ghsa.SecurityAdvisory
98119
if strings.HasPrefix(alias, "GHSA") {
@@ -143,17 +164,22 @@ func constructIssue(ctx context.Context, c *issues.Client, ghsaClient *ghsa.Clie
143164
}
144165
bodies = append(bodies, body)
145166
}
146-
sort.Strings(ids)
167+
return publishIssue(ctx, c, []string{pkgPath}, ids, bodies, labels)
168+
}
169+
170+
func publishIssue(ctx context.Context, c *issues.Client, packages, aliases, bodies, labels []string) error {
171+
sort.Strings(aliases)
147172
iss := &issues.Issue{
148-
Title: fmt.Sprintf("x/vulndb: potential Go vuln in %s: %s", pkgPath, strings.Join(ids, ", ")),
173+
Title: fmt.Sprintf("x/vulndb: potential Go vuln in %s: %s", strings.Join(packages, ", "),
174+
strings.Join(aliases, ", ")),
149175
Body: strings.Join(bodies, "\n\n----------\n\n"),
150176
Labels: labels,
151177
}
152178
issNum, err := c.CreateIssue(ctx, iss)
153179
if err != nil {
154180
return err
155181
}
156-
fmt.Printf("created https://github.com/golang/vulndb/issues/%d (%s)\n", issNum, strings.Join(ids, ", "))
182+
fmt.Printf("published issue https://%s/issues/%d (%s)\n", *issueRepo, issNum, strings.Join(aliases, ", "))
157183
return nil
158184
}
159185

0 commit comments

Comments
 (0)