Skip to content

Commit

Permalink
feat(cve/nvd): support CVSS v4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
MaineK00n committed Jun 29, 2024
1 parent d8173cd commit 684a44a
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
30 changes: 20 additions & 10 deletions models/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,29 @@ func ConvertNvdToModel(cveID string, nvds []cvedict.Nvd) ([]CveContent, []Exploi
c.Cvss3Severity = cvss3.BaseSeverity
m[cvss3.Source] = c
}
for _, cvss40 := range nvd.Cvss40 {

Check failure on line 122 in models/utils.go

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

nvd.Cvss40 undefined (type "github.com/vulsio/go-cve-dictionary/models".Nvd has no field or method Cvss40)

Check failure on line 122 in models/utils.go

View workflow job for this annotation

GitHub Actions / lint

nvd.Cvss40 undefined (type "github.com/vulsio/go-cve-dictionary/models".Nvd has no field or method Cvss40)) (typecheck)

Check failure on line 122 in models/utils.go

View workflow job for this annotation

GitHub Actions / lint

nvd.Cvss40 undefined (type "github.com/vulsio/go-cve-dictionary/models".Nvd has no field or method Cvss40)) (typecheck)

Check failure on line 122 in models/utils.go

View workflow job for this annotation

GitHub Actions / lint

nvd.Cvss40 undefined (type "github.com/vulsio/go-cve-dictionary/models".Nvd has no field or method Cvss40)) (typecheck)

Check failure on line 122 in models/utils.go

View workflow job for this annotation

GitHub Actions / Analyze (go)

nvd.Cvss40 undefined (type "github.com/vulsio/go-cve-dictionary/models".Nvd has no field or method Cvss40)

Check failure on line 122 in models/utils.go

View workflow job for this annotation

GitHub Actions / build (windows-latest)

nvd.Cvss40 undefined (type "github.com/vulsio/go-cve-dictionary/models".Nvd has no field or method Cvss40)

Check failure on line 122 in models/utils.go

View workflow job for this annotation

GitHub Actions / build (macos-latest)

nvd.Cvss40 undefined (type "github.com/vulsio/go-cve-dictionary/models".Nvd has no field or method Cvss40)
c := m[cvss40.Source]
c.Cvss40Score = cvss40.BaseScore
c.Cvss40Vector = cvss40.VectorString
c.Cvss40Severity = cvss40.BaseSeverity
m[cvss40.Source] = c
}

for source, cont := range m {
cves = append(cves, CveContent{
Type: Nvd,
CveID: cveID,
Summary: strings.Join(desc, "\n"),
Cvss2Score: cont.Cvss2Score,
Cvss2Vector: cont.Cvss2Vector,
Cvss2Severity: cont.Cvss2Severity,
Cvss3Score: cont.Cvss3Score,
Cvss3Vector: cont.Cvss3Vector,
Cvss3Severity: cont.Cvss3Severity,
SourceLink: fmt.Sprintf("https://nvd.nist.gov/vuln/detail/%s", cveID),
Type: Nvd,
CveID: cveID,
Summary: strings.Join(desc, "\n"),
Cvss2Score: cont.Cvss2Score,
Cvss2Vector: cont.Cvss2Vector,
Cvss2Severity: cont.Cvss2Severity,
Cvss3Score: cont.Cvss3Score,
Cvss3Vector: cont.Cvss3Vector,
Cvss3Severity: cont.Cvss3Severity,
Cvss40Score: cont.Cvss40Score,
Cvss40Vector: cont.Cvss40Vector,
Cvss40Severity: cont.Cvss40Severity,
SourceLink: fmt.Sprintf("https://nvd.nist.gov/vuln/detail/%s", cveID),
// Cpes: cpes,
CweIDs: cont.CweIDs,
References: refs,
Expand Down
2 changes: 1 addition & 1 deletion models/vulninfos.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ func (v VulnInfo) Cvss3Scores() (values []CveContentCvss) {

// Cvss40Scores returns CVSS V4 Score
func (v VulnInfo) Cvss40Scores() (values []CveContentCvss) {
for _, ctype := range []CveContentType{Mitre} {
for _, ctype := range []CveContentType{Mitre, Nvd} {
if conts, found := v.CveContents[ctype]; found {
for _, cont := range conts {
if cont.Cvss40Score == 0 && cont.Cvss40Severity == "" {
Expand Down
18 changes: 18 additions & 0 deletions models/vulninfos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,15 @@ func TestVulnInfo_Cvss40Scores(t *testing.T) {
Optional: map[string]string{"source": "CNA"},
},
},
Nvd: []CveContent{
{
Type: Nvd,
Cvss40Score: 6.9,
Cvss40Vector: "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:L/VI:L/VA:L/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X",
Cvss40Severity: "MEDIUM",
Optional: map[string]string{"source": "[email protected]"},
},
},
},
},
want: []CveContentCvss{
Expand All @@ -1943,6 +1952,15 @@ func TestVulnInfo_Cvss40Scores(t *testing.T) {
Vector: "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:L/VI:L/VA:L/SC:N/SI:N/SA:N",
},
},
{
Type: Nvd,
Value: Cvss{
Type: CVSS40,
Score: 6.9,
Severity: "MEDIUM",
Vector: "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:L/VI:L/VA:L/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X",
},
},
},
},
}
Expand Down

0 comments on commit 684a44a

Please sign in to comment.