Skip to content
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

Added NVD CPE details #114

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ type VulnerabilityDetail struct {
Description string `json:",omitempty"`
PublishedDate *time.Time `json:",omitempty"`
LastModifiedDate *time.Time `json:",omitempty"`
CPEDetails string `json:",omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should have a struct for CPEDetails, not string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

noted, I thought we want to optimize the storage here, so I tried storing as JSON string

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In any cases, we marshal VulnerabilityDetail to JSON in BoltDB, so the disk size would be almost the same. If we store CPEDetails as string, we need to unmarshal twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, pushing the change

}

type AdvisoryDetail struct {
Expand Down
8 changes: 6 additions & 2 deletions pkg/vulnsrc/nvd/nvd.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ func (vs VulnSrc) commit(tx *bolt.Tx, items []Item) error {

publishedDate, _ := time.Parse("2006-01-02T15:04Z", item.PublishedDate)
lastModifiedDate, _ := time.Parse("2006-01-02T15:04Z", item.LastModifiedDate)

vuln := types.VulnerabilityDetail{
CvssScore: item.Impact.BaseMetricV2.CvssV2.BaseScore,
CvssVector: item.Impact.BaseMetricV2.CvssV2.VectorString,
Expand All @@ -107,7 +106,12 @@ func (vs VulnSrc) commit(tx *bolt.Tx, items []Item) error {
PublishedDate: &publishedDate,
LastModifiedDate: &lastModifiedDate,
}

if item.Configurations != nil {
configurationString, err := json.Marshal(item.Configurations)
if err == nil {
vuln.CPEDetails = string(configurationString)
}
}
if err := vs.dbc.PutVulnerabilityDetail(tx, cveID, vulnerability.Nvd, vuln); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/vulnsrc/nvd/nvd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestVulnSrc_Update(t *testing.T) {
References: []string{"https://source.android.com/security/bulletin/2020-01-01"},
LastModifiedDate: utils.MustTimeParse("2020-01-01T01:01:00Z"),
PublishedDate: utils.MustTimeParse("2001-01-01T01:01:00Z"),
CPEDetails: `{"CVE_data_version":"4.0","nodes":[{"cpe_match":[{"cpe23Uri":"cpe:2.3:o:google:android:8.0:*:*:*:*:*:*:*","vulnerable":true},{"cpe23Uri":"cpe:2.3:o:google:android:8.1:*:*:*:*:*:*:*","vulnerable":true},{"cpe23Uri":"cpe:2.3:o:google:android:9.0:*:*:*:*:*:*:*","vulnerable":true},{"cpe23Uri":"cpe:2.3:o:google:android:10.0:*:*:*:*:*:*:*","vulnerable":true}],"operator":"OR"}]}`,
},
},
{
Expand Down
1 change: 1 addition & 0 deletions pkg/vulnsrc/nvd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type NVD struct {
}

type Item struct {
Configurations interface{}
Cve Cve
Impact Impact
LastModifiedDate string `json:"lastModifiedDate"`
Expand Down