Skip to content

Add CVSS v4.0 support, fix CVSS v2.0 invalid calculator link #3474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@ require (
github.com/blang/semver/v4 v4.0.0
github.com/cheggaaa/pb/v3 v3.1.7
github.com/go-git/go-git/v5 v5.16.2
github.com/goark/go-cvss v1.6.7
github.com/golang/protobuf v1.5.4
github.com/google/go-containerregistry v0.20.6
github.com/google/go-github/v72 v72.0.0
@@ -22,6 +21,7 @@ require (
github.com/mitchellh/mapstructure v1.5.1-0.20231216201459-8508981c8b6c
github.com/nozzle/throttler v0.0.0-20180817012639-2ea982251481
github.com/olekukonko/tablewriter v0.0.5
github.com/pandatix/go-cvss v0.6.2
github.com/psampaz/go-mod-outdated v0.9.0
github.com/saschagrunert/go-modiff v1.3.5
github.com/sendgrid/rest v2.6.9+incompatible
@@ -168,7 +168,6 @@ require (
github.com/go-openapi/validate v0.24.0 // indirect
github.com/go-piv/piv-go/v2 v2.3.0 // indirect
github.com/go-viper/mapstructure/v2 v2.3.0 // indirect
github.com/goark/errs v1.3.2 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -421,10 +421,6 @@ github.com/go-test/deep v1.1.1 h1:0r/53hagsehfO4bzD2Pgr/+RgHqhmf+k1Bpse2cTu1U=
github.com/go-test/deep v1.1.1/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
github.com/go-viper/mapstructure/v2 v2.3.0 h1:27XbWsHIqhbdR5TIC911OfYvgSaW93HM+dX7970Q7jk=
github.com/go-viper/mapstructure/v2 v2.3.0/go.mod h1:oJDH3BJKyqBA2TXFhDsKDGDTlndYOZ6rGS0BRZIxGhM=
github.com/goark/errs v1.3.2 h1:ifccNe1aK7Xezt4XVYwHUqalmnfhuphnEvh3FshCReQ=
github.com/goark/errs v1.3.2/go.mod h1:ZsQucxaDFVfSB8I99j4bxkDRfNOrlKINwg72QMuRWKw=
github.com/goark/go-cvss v1.6.7 h1:9R/cx8+lv17uFS1RKYNmEfYqEJwWgF26F4g7hK38jEw=
github.com/goark/go-cvss v1.6.7/go.mod h1:qsmYCGTQnQqW/Lq1Z3lRCEarKD++nx7C+KgsG05MhDA=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk=
@@ -711,6 +707,8 @@ github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/package-url/packageurl-go v0.1.2 h1:0H2DQt6DHd/NeRlVwW4EZ4oEI6Bn40XlNPRqegcxuo4=
github.com/package-url/packageurl-go v0.1.2/go.mod h1:uQd4a7Rh3ZsVg5j0lNyAfyxIeGde9yrlhjF78GzeW0c=
github.com/pandatix/go-cvss v0.6.2 h1:TFiHlzUkT67s6UkelHmK6s1INKVUG7nlKYiWWDTITGI=
github.com/pandatix/go-cvss v0.6.2/go.mod h1:jDXYlQBZrc8nvrMUVVvTG8PhmuShOnKrxP53nOFkt8Q=
github.com/pborman/uuid v1.2.1 h1:+ZZIw58t/ozdjRaXh/3awHfmWRbzYxJoAdNJxe/3pvw=
github.com/pborman/uuid v1.2.1/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M=
52 changes: 38 additions & 14 deletions pkg/cve/cve.go
Original file line number Diff line number Diff line change
@@ -20,8 +20,12 @@ import (
"errors"
"fmt"
"regexp"
"strings"

cvss "github.com/goark/go-cvss/v3/metric"
gocvss20 "github.com/pandatix/go-cvss/20"
gocvss30 "github.com/pandatix/go-cvss/30"
gocvss31 "github.com/pandatix/go-cvss/31"
gocvss40 "github.com/pandatix/go-cvss/40"
)

// CVE Information of a linked CVE vulnerability.
@@ -100,22 +104,42 @@ func (cve *CVE) Validate() (err error) {
return errors.New("string CVSS vector missing from CVE data")
}

var bm cvss.Metrics
// Parse the vector string to make sure it is well formed
if len(cve.CVSSVector) == 44 {
bm, err = cvss.NewBase().Decode(cve.CVSSVector)
} else {
bm, err = cvss.NewTemporal().Decode(cve.CVSSVector)
}
switch {
default: // CVSS v2.0 has no prefix
_, err := gocvss20.ParseVector(cve.CVSSVector)
if err != nil {
return fmt.Errorf("parsing CVSS vector string: %w", err)
}
// FIRST ORG has no calculator for CVSS v2.0

if err != nil {
return fmt.Errorf("parsing CVSS vector string: %w", err)
case strings.HasPrefix(cve.CVSSVector, "CVSS:3.0"):
_, err := gocvss30.ParseVector(cve.CVSSVector)
if err != nil {
return fmt.Errorf("parsing CVSS vector string: %w", err)
}
cve.CalcLink = fmt.Sprintf(
"https://www.first.org/cvss/calculator/3.0#%s", cve.CVSSVector,
)

case strings.HasPrefix(cve.CVSSVector, "CVSS:3.1"):
_, err := gocvss31.ParseVector(cve.CVSSVector)
if err != nil {
return fmt.Errorf("parsing CVSS vector string: %w", err)
}
cve.CalcLink = fmt.Sprintf(
"https://www.first.org/cvss/calculator/3.1#%s", cve.CVSSVector,
)

case strings.HasPrefix(cve.CVSSVector, "CVSS:4.0"):
_, err := gocvss40.ParseVector(cve.CVSSVector)
if err != nil {
return fmt.Errorf("parsing CVSS vector string: %w", err)
}
cve.CalcLink = fmt.Sprintf(
"https://www.first.org/cvss/calculator/4.0#%s", cve.CVSSVector,
)
}

cve.CalcLink = fmt.Sprintf(
"https://www.first.org/cvss/calculator/%s#%s", bm.BaseMetrics().Ver.String(), cve.CVSSVector,
)

if cve.CVSSScore == 0 {
return errors.New("missing CVSS score from CVE data")
}