-
-
Notifications
You must be signed in to change notification settings - Fork 269
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
Changes from all commits
4fc018f
38b456a
221bc12
52724a5
98e4082
9fc7ec8
b0ae6a8
5d22856
190440b
ee7e509
9ca5558
0887e83
86f2e4f
e8e6166
c9df2f9
0312cfb
641b457
be24df0
5428b37
d78cd0f
8d19463
bea7f16
File filter
Filter by extension
Conversations
Jump to
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.
Large diffs are not rendered by default.
| 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.
Show resolved
Hide resolved
|
||
| 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.