Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 323
Store severity scores #290
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
4fc018f38b456a221bc1252724a598e40829fc7ec8b0ae6a85d22856190440bee7e5099ca55580887e8386f2e4fe8e6166c9df2f90312cfb641b457be24df05428b37d78cd0f8d19463bea7f16File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -122,3 +122,6 @@ Pipfile | ||
| # pytest | ||
| .pytest_cache | ||
| # VSCode | ||
| .vscode | ||
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
Large diffs are not rendered by default.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -32,7 +32,9 @@ | ||
| from vulnerabilities.data_source import DataSource | ||
| from vulnerabilities.data_source import DataSourceConfiguration | ||
| from vulnerabilities.data_source import Reference | ||
| from vulnerabilities.data_source import VulnerabilitySeverity | ||
| from vulnerabilities.helpers import create_etag | ||
| from vulnerabilities.severity_systems import scoring_systems | ||
| @dataclasses.dataclass | ||
| @@ -77,6 +79,14 @@ def to_advisories(self, nvd_data): | ||
| cve_id = cve_item["cve"]["CVE_data_meta"]["ID"] | ||
| ref_urls = self.extract_reference_urls(cve_item) | ||
| references = [Reference(url=url) for url in ref_urls] | ||
| severity_scores = self.extract_severity_scores(cve_item) | ||
| references.append( | ||
| Reference( | ||
| url=f"https://nvd.nist.gov/vuln/detail/{cve_id}", | ||
| reference_id=cve_id, | ||
| severities=severity_scores, | ||
| ) | ||
| ) | ||
| summary = self.extract_summary(cve_item) | ||
| yield Advisory( | ||
| cve_id=cve_id, summary=summary, vuln_references=references, impacted_package_urls=[] | ||
| @@ -90,6 +100,40 @@ def extract_summary(cve_item): | ||
| summaries = [desc["value"] for desc in cve_item["cve"]["description"]["description_data"]] | ||
| return max(summaries, key=len) | ||
| @staticmethod | ||
| def extract_severity_scores(cve_item): | ||
| severity_scores = [] | ||
| if cve_item["impact"].get("baseMetricV3"): | ||
sbs2001 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| severity_scores.append( | ||
sbs2001 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| VulnerabilitySeverity( | ||
| system=scoring_systems["cvssv3"], | ||
| value=str(cve_item["impact"]["baseMetricV3"]["cvssV3"]["baseScore"]), | ||
| ) | ||
| ) | ||
| severity_scores.append( | ||
| VulnerabilitySeverity( | ||
| system=scoring_systems["cvssv3_vector"], | ||
| value=str(cve_item["impact"]["baseMetricV3"]["cvssV3"]["vectorString"]), | ||
| ) | ||
| ) | ||
| if cve_item["impact"].get("baseMetricV2"): | ||
| severity_scores.append( | ||
| VulnerabilitySeverity( | ||
| system=scoring_systems["cvssv2"], | ||
| value=str(cve_item["impact"]["baseMetricV2"]["cvssV2"]["baseScore"]), | ||
| ) | ||
| ) | ||
| severity_scores.append( | ||
| VulnerabilitySeverity( | ||
| system=scoring_systems["cvssv2_vector"], | ||
| value=str(cve_item["impact"]["baseMetricV2"]["cvssV2"]["vectorString"]), | ||
| ) | ||
| ) | ||
| return severity_scores | ||
| def extract_reference_urls(self, cve_item): | ||
| urls = set() | ||
| for reference in cve_item["cve"]["references"]["reference_data"]: | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # Copyright (c) 2017 nexB Inc. and others. All rights reserved. | ||
| # Copyright (c) nexB Inc. and others. All rights reserved. | ||
| # http://nexb.com and https://github.com/nexB/vulnerablecode/ | ||
| # The VulnerableCode software is licensed under the Apache License version 2.0. | ||
| # Data generated with VulnerableCode require an acknowledgment. | ||
| @@ -17,24 +17,27 @@ | ||
| # OR CONDITIONS OF ANY KIND, either express or implied. No content created from | ||
| # VulnerableCode should be considered or used as legal advice. Consult an Attorney | ||
| # for any legal advice. | ||
| # VulnerableCode is a free software code scanning tool from nexB Inc. and others. | ||
| # VulnerableCode is a free software code from nexB Inc. and others. | ||
| # Visit https://github.com/nexB/vulnerablecode/ for support and download. | ||
| import requests | ||
| import json | ||
| from packageurl import PackageURL | ||
| import requests | ||
| from vulnerabilities.data_source import Advisory | ||
| from vulnerabilities.data_source import DataSource | ||
| from vulnerabilities.data_source import DataSourceConfiguration | ||
| from vulnerabilities.data_source import Reference | ||
| from vulnerabilities.data_source import VulnerabilitySeverity | ||
| from vulnerabilities.severity_systems import scoring_systems | ||
| class RedhatDataSource(DataSource): | ||
| CONFIG_CLASS = DataSourceConfiguration | ||
| def __enter__(self): | ||
| self.redhat_response = fetch() | ||
| def updated_advisories(self): | ||
| @@ -52,7 +55,6 @@ def fetch(): | ||
| url = "https://access.redhat.com/hydra/rest/securitydata/cve.json?page={}" | ||
| while True: | ||
| resp_json = requests.get(url.format(page_no)).json() | ||
| page_no += 1 | ||
| if not resp_json: | ||
| @@ -65,31 +67,74 @@ def fetch(): | ||
| def to_advisory(advisory_data): | ||
| affected_purls = [] | ||
| if advisory_data.get("affected_packages"): | ||
| for rpm in advisory_data["affected_packages"]: | ||
| if rpm_to_purl(rpm): | ||
| affected_purls.append(rpm_to_purl(rpm)) | ||
| references = [] | ||
| if advisory_data.get("bugzilla"): | ||
| bugzilla = advisory_data.get("bugzilla") | ||
| bugzilla = advisory_data.get("bugzilla") | ||
| if bugzilla: | ||
| url = "https://bugzilla.redhat.com/show_bug.cgi?id={}".format(bugzilla) | ||
sbs2001 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| bugzilla_data = requests.get(f"https://bugzilla.redhat.com/rest/bug/{bugzilla}").json() | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just as a side note, this is the kind of JSON we would likely need to store forever as back auditable evidence when we will do this later ... which likely calls for a central place where we fetch things from | ||
| bugzilla_severity_val = bugzilla_data["bugs"][0]["severity"] | ||
| bugzilla_severity = VulnerabilitySeverity( | ||
| system=scoring_systems["rhbs"], | ||
| value=bugzilla_severity_val, | ||
| ) | ||
| references.append( | ||
| Reference( | ||
| url="https://bugzilla.redhat.com/show_bug.cgi?id={}".format(bugzilla), | ||
| severities=[bugzilla_severity], | ||
| url=url, | ||
| reference_id=bugzilla, | ||
| ) | ||
| ) | ||
| for rhsa in advisory_data["advisories"]: | ||
| references.append( | ||
| Reference( | ||
| url="https://access.redhat.com/errata/{}".format(rhsa), reference_id=rhsa, | ||
| for rh_adv in advisory_data["advisories"]: | ||
| # RH provides 3 types of advisories RHSA, RHBA, RHEA. Only RHSA's contain severity score. | ||
| # See https://access.redhat.com/articles/2130961 for more details. | ||
| if "RHSA" in rh_adv.upper(): | ||
| rhsa_data = requests.get(f"https://access.redhat.com/hydra/rest/securitydata/cvrf/{rh_adv}.json").json() # nopep8 | ||
| value = rhsa_data["cvrfdoc"]["aggregate_severity"] | ||
| rhsa_aggregate_severity = VulnerabilitySeverity( | ||
| system=scoring_systems["rhas"], | ||
| value=value, | ||
| ) | ||
| references.append( | ||
| Reference( | ||
| severities=[rhsa_aggregate_severity], | ||
| url="https://access.redhat.com/errata/{}".format(rh_adv), | ||
| reference_id=rh_adv, | ||
| ) | ||
| ) | ||
| else: | ||
| references.append(Reference(severities=[], url=url, reference_id=rh_adv)) | ||
| redhat_scores = [] | ||
| cvssv3_score = advisory_data.get("cvss3_score") | ||
| if cvssv3_score: | ||
| redhat_scores.append( | ||
| VulnerabilitySeverity( | ||
| system=scoring_systems["cvssv3"], | ||
| value=cvssv3_score, | ||
| ) | ||
| ) | ||
| cvssv3_vector = advisory_data.get("cvss3_scoring_vector") | ||
| if cvssv3_vector: | ||
| redhat_scores.append( | ||
| VulnerabilitySeverity( | ||
| system=scoring_systems["cvssv3_vector"], | ||
| value=cvssv3_vector, | ||
| ) | ||
| ) | ||
| references.append(Reference(url=advisory_data["resource_url"])) | ||
| references.append(Reference(severities=redhat_scores, url=advisory_data["resource_url"])) | ||
| return Advisory( | ||
| summary=advisory_data["bugzilla_description"], | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.