-
Notifications
You must be signed in to change notification settings - Fork 143
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
refactor(nvd): migrate to API 2.0 #374
Conversation
pkg/vulnsrc/nvd/nvd.go
Outdated
func getCvssV3(metricsV31, metricsV30 []CvssMetricV3) (score float64, vector string, severity types.Severity) { | ||
// order: v3.1 metrics => v3.0 metrics | ||
// save the first `primary` metric | ||
// if the `Primary` metric does not exist => save the first `Secondary` metric (v3.1 => v3.0) | ||
for _, metricV3 := range append(metricsV31, metricsV30...) { | ||
// save first metric or the `Primary` metric if `Secondary` metric was saved previously | ||
if score == 0 || metricV3.Type == primaryType { | ||
score = metricV3.CvssData.BaseScore | ||
vector = metricV3.CvssData.VectorString | ||
severity, _ = types.NewSeverity(metricV3.CvssData.BaseSeverity) | ||
if metricV3.Type == primaryType { | ||
return | ||
} | ||
} | ||
} | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this case.
what to choose: “Secondary metric V31” or “Primary metric v30”.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I commented above, we should take metrics only from NVD here. So, the answer is:
- cvssMetricV31 with
source: [email protected]
- cvssMetricV30 with
source: [email protected]
- cvssMetricV31 from other vendors (ignore)
- cvssMetricV30 from other vendors (ignore)
We may want to use metrics from other vendors in the future, but it should be done in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your help!
Changed in 96b8f7d
Hi @DmitriyLewen , @knqyf263 , Hope you are doing great. Just came across this PR.
Thank you |
Hello @namandf
We are trying to finish these changes before the 15th.
right. This fix only for trivy-db. You will need only doewnload new DB.
We only receive advisory information from nvd (severity, descriptions, etc.). |
Thank you for the update @DmitriyLewen .
Out of curiosity, do we rely on MITRE/cve.org for the CVE list? or are you suggesting that other databases bridge that gap? |
No, we don't use MITRE/cve.org. We use the following databases to get CVE list: |
Got it. Thank you. You might already be aware but looks like there is again a change in deadline. |
yes, thanks! FYI - We have aquasecurity/trivy#5658 |
pkg/vulnsrc/nvd/nvd.go
Outdated
func getCvssV2(metricsV2 []CvssMetricV2) (score float64, vector string, severity types.Severity) { | ||
for _, metricV2 := range metricsV2 { | ||
// save first metric or the `Primary` metric if `Secondary` metric was saved previously | ||
if score == 0 || metricV2.Type == primaryType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, the type doesn't matter. We need metrics from NVD, so I think we should take metrics with source: [email protected]
.
source identifies the organization that provided the metrics information and type identifies whether the organization is a primary or secondary source. Primary sources include the NVD and CNA who have reached the provider level in CVMAP. 10% of provider level submissions are audited by the NVD. If a submission has been audited the NVD will appear as the primary source and the provider level CNA will appear as the secondary source.
"cvssMetricV30": [
{
"source": "[email protected]",
"type": "Secondary",
"cvssData": {
"version": "3.0",
"vectorString": "CVSS:3.0/AV:P/AC:H/PR:N/UI:N/S:U/C:N/I:L/A:H",
"attackVector": "PHYSICAL",
"attackComplexity": "HIGH",
"privilegesRequired": "NONE",
"userInteraction": "NONE",
"scope": "UNCHANGED",
"confidentialityImpact": "NONE",
"integrityImpact": "LOW",
"availabilityImpact": "HIGH",
"baseScore": 4.8,
"baseSeverity": "MEDIUM"
},
"exploitabilityScore": 0.5,
"impactScore": 4.2
}
],
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! fixed in 96b8f7d
pkg/vulnsrc/nvd/nvd.go
Outdated
func getCvssV3(metricsV31, metricsV30 []CvssMetricV3) (score float64, vector string, severity types.Severity) { | ||
// order: v3.1 metrics => v3.0 metrics | ||
// save the first `primary` metric | ||
// if the `Primary` metric does not exist => save the first `Secondary` metric (v3.1 => v3.0) | ||
for _, metricV3 := range append(metricsV31, metricsV30...) { | ||
// save first metric or the `Primary` metric if `Secondary` metric was saved previously | ||
if score == 0 || metricV3.Type == primaryType { | ||
score = metricV3.CvssData.BaseScore | ||
vector = metricV3.CvssData.VectorString | ||
severity, _ = types.NewSeverity(metricV3.CvssData.BaseSeverity) | ||
if metricV3.Type == primaryType { | ||
return | ||
} | ||
} | ||
} | ||
return | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I commented above, we should take metrics only from NVD here. So, the answer is:
- cvssMetricV31 with
source: [email protected]
- cvssMetricV30 with
source: [email protected]
- cvssMetricV31 from other vendors (ignore)
- cvssMetricV30 from other vendors (ignore)
We may want to use metrics from other vendors in the future, but it should be done in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I left a small comment.
pkg/vulnsrc/nvd/types.go
Outdated
ID string `json:"id"` | ||
SourceIdentifier string `json:"sourceIdentifier,omitempty"` | ||
Published string `json:"published"` | ||
LastModified string `json:"lastModified"` | ||
VulnStatus string `json:"vulnStatus,omitempty"` | ||
EvaluatorComment string `json:"evaluatorComment,omitempty"` | ||
EvaluatorSolution string `json:"evaluatorSolution,omitempty"` | ||
EvaluatorImpact string `json:"evaluatorImpact,omitempty"` | ||
CisaExploitAdd string `json:"cisaExploitAdd,omitempty"` | ||
CisaActionDue string `json:"cisaActionDue,omitempty"` | ||
Descriptions []LangString `json:"descriptions"` | ||
Metrics Metrics `json:"metrics,omitempty"` | ||
Weaknesses []Weakness `json:"weaknesses,omitempty"` | ||
Configurations []Configuration `json:"configurations,omitempty"` | ||
References []Reference `json:"references"` | ||
VendorComments []VendorComment `json:"vendorComments,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove unneeded fields? It helps us understand what fields we are using. Other structs as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed. Please let me know if I did something wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point!
I checked your changes and don't see problem with that.
Signed-off-by: knqyf263 <[email protected]>
Description
Migrate to NVD API 2.0
Related Issues
Related PRs