Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pkg/process/v6/transformers/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func NewEntries(models ...any) []data.Entry {
case grypeDB.VulnerabilityHandle:
entry.VulnerabilityHandle = &m
case grypeDB.AffectedPackageHandle, grypeDB.UnaffectedPackageHandle, grypeDB.AffectedCPEHandle,
grypeDB.UnaffectedCPEHandle, grypeDB.KnownExploitedVulnerabilityHandle, grypeDB.EpssHandle:
grypeDB.UnaffectedCPEHandle, grypeDB.KnownExploitedVulnerabilityHandle, grypeDB.EpssHandle, grypeDB.CWEHandle:
entry.Related = append(entry.Related, m)
case grypeDB.Provider:
entry.Provider = &m
Expand Down
33 changes: 33 additions & 0 deletions pkg/process/v6/transformers/nvd/transform.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nvd

import (
"regexp"
"strings"

"github.com/scylladb/go-set/strset"
Expand Down Expand Up @@ -68,6 +69,10 @@ func transform(cfg Config, vulnerability unmarshal.NVDVulnerability, state provi
in = append(in, a)
}

for _, cwe := range getCWEs(vulnerability) {
in = append(in, cwe)
}

return transformers.NewEntries(in...), nil
}

Expand Down Expand Up @@ -157,6 +162,34 @@ func getAffected(cfg Config, vulnerability unmarshal.NVDVulnerability) []grypeDB
return affs
}

func getCWEs(vulnerability unmarshal.NVDVulnerability) []grypeDB.CWEHandle {
var cwes []grypeDB.CWEHandle
for _, w := range vulnerability.Weaknesses {
for _, d := range w.Description {
if isValidCWE(d.Value) {
cwes = append(cwes, grypeDB.CWEHandle{
Cve: vulnerability.ID,
CWE: d.Value,
Source: w.Source,
Type: w.Type,
})
}
}
}
return cwes
}

func isValidCWE(s string) bool {
if s == "NVD-CWE-Other" {
return true
}
matched, err := regexp.MatchString(`^CWE-\d+$`, s)
if err != nil {
return false
}
return matched
}

func encodeCPEs(cpes []cpe.Attributes) []string {
var results []string
for _, c := range cpes {
Expand Down
Loading