Skip to content

Commit

Permalink
Add link to CVE calculator on release notes CVE data
Browse files Browse the repository at this point in the history
Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
  • Loading branch information
puerco committed Feb 23, 2021
1 parent 15d64a3 commit 2163900
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/notes/document/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ This release contains changes that address the following vulnerabilities:
{{.Description}}
**CVSS Rating:** {{.CVSSRating}} ({{.CVSSScore}}) {{.CVSSVector}}<br>
**CVSS Rating:** {{.CVSSRating}} ({{.CVSSScore}}) [{{.CVSSVector}}]({{.CalcLink}})<br>
**Tracking Issue:** {{.TrackingIssue}}
{{ end }}
Expand Down
14 changes: 12 additions & 2 deletions pkg/notes/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ type CVEData struct {
CVSSVector string `json:"vector"` // Full CVSS vector string, CVSS:3.1/AV:N/AC:H/PR:H/UI:R/S:U/C:H/I:H/A:H
CVSSScore float32 `json:"score"` // Numeric CVSS score (eg 6.2)
CVSSRating string `json:"rating"` // Severity bucket (eg Medium)
LinkedPRs []int `json:"linkedPRs"` // List of linked PRs (to remove them from the release notes doc)
CalcLink string // Link to the CVE calculator (automatic)
LinkedPRs []int `json:"linkedPRs"` // List of linked PRs (to remove them from the release notes doc)
}

const (
Expand Down Expand Up @@ -1099,7 +1100,7 @@ func (cve *CVEData) Validate() error {
cve.CVSSRating != "Medium" &&
cve.CVSSRating != "High" &&
cve.CVSSRating != "Critical" {
return errors.New("Invalida CVSS rating")
return errors.New("Invalid CVSS rating")
}

if cve.CVSSVector == "" {
Expand All @@ -1122,5 +1123,14 @@ func (cve *CVEData) Validate() error {
return errors.New("CVE description missing from CVE data")
}

// Since we're checking the vector string with a regex, use the effort to
// add a link to the CVE calculator
re := regexp.MustCompile(`^CVSS:(\d+\.\d+)/`)
cvssVer := re.FindStringSubmatch(cve.CVSSVector)
if len(cvssVer) == 0 {
return errors.New("CVSS vector in not properly formed: version missing")
}
cve.CalcLink = fmt.Sprintf("https://www.first.org/cvss/calculator/%s#%s", cvssVer[1], cve.CVSSVector)

return nil
}

0 comments on commit 2163900

Please sign in to comment.