-
-
Notifications
You must be signed in to change notification settings - Fork 261
Migrate Suse Scores importer to advisory V2 #2101
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
Open
ziadhany
wants to merge
2
commits into
aboutcode-org:main
Choose a base branch
from
ziadhany:suse-migrate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+213
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
vulnerabilities/pipelines/v2_importers/suse_score_importer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # | ||
| # Copyright (c) nexB Inc. and others. All rights reserved. | ||
| # VulnerableCode is a trademark of nexB Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # See http://www.apache.org/licenses/LICENSE-2.0 for the license text. | ||
| # See https://github.com/aboutcode-org/vulnerablecode for support or download. | ||
| # See https://aboutcode.org for more information about nexB OSS projects. | ||
| # | ||
|
|
||
| from typing import Iterable | ||
|
|
||
| from vulnerabilities import severity_systems | ||
| from vulnerabilities.importer import AdvisoryData | ||
| from vulnerabilities.importer import ReferenceV2 | ||
| from vulnerabilities.importer import VulnerabilitySeverity | ||
| from vulnerabilities.management.commands.commit_export import logger | ||
| from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipelineV2 | ||
| from vulnerabilities.utils import fetch_yaml | ||
|
|
||
|
|
||
| class SUSESeverityScoreImporterPipeline(VulnerableCodeBaseImporterPipelineV2): | ||
| spdx_license_expression = "CC-BY-4.0" | ||
| license_url = "https://ftp.suse.com/pub/projects/security/yaml/LICENSE" | ||
| pipeline_id = "suse_importer_v2" | ||
| url = "https://ftp.suse.com/pub/projects/security/yaml/suse-cvss-scores.yaml" | ||
|
|
||
| @classmethod | ||
| def steps(cls): | ||
| return ( | ||
| cls.fetch_advisories, | ||
| cls.collect_and_store_advisories, | ||
| ) | ||
|
|
||
| def fetch_advisories(self): | ||
| self.score_data = fetch_yaml(self.url) | ||
|
|
||
| def advisories_count(self): | ||
| return sum(1 for _ in self.score_data) | ||
|
|
||
| def collect_advisories(self) -> Iterable[AdvisoryData]: | ||
| systems_by_version = { | ||
| "2.0": severity_systems.CVSSV2, | ||
| "3": severity_systems.CVSSV3, | ||
| "3.1": severity_systems.CVSSV31, | ||
| "4": severity_systems.CVSSV4, | ||
| } | ||
|
|
||
| for cve_id in self.score_data or []: | ||
| severities = [] | ||
| for cvss_score in self.score_data[cve_id].get("cvss") or []: | ||
| cvss_version = cvss_score.get("version") or "" | ||
| scoring_system = systems_by_version.get(cvss_version) | ||
| if not scoring_system: | ||
| logger.error(f"Unsupported CVSS version: {cvss_version}") | ||
| continue | ||
| base_score = str(cvss_score.get("score") or "") | ||
| vector = str(cvss_score.get("vector") or "") | ||
| score = VulnerabilitySeverity( | ||
| system=scoring_system, | ||
| value=base_score, | ||
| scoring_elements=vector, | ||
| ) | ||
| severities.append(score) | ||
|
|
||
| yield AdvisoryData( | ||
| advisory_id=cve_id, | ||
| aliases=[], | ||
| summary="", | ||
| severities=severities, | ||
| references_v2=[ReferenceV2(reference_id=cve_id, url=self.url)], | ||
| url=self.url, | ||
| ) | ||
33 changes: 33 additions & 0 deletions
33
vulnerabilities/tests/pipelines/v2_importers/test_suse_score_importer_v2.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # | ||
| # Copyright (c) nexB Inc. and others. All rights reserved. | ||
| # VulnerableCode is a trademark of nexB Inc. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # See http://www.apache.org/licenses/LICENSE-2.0 for the license text. | ||
| # See https://github.com/aboutcode-org/vulnerablecode for support or download. | ||
| # See https://aboutcode.org for more information about nexB OSS projects. | ||
| # | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import saneyaml | ||
|
|
||
| from vulnerabilities.pipelines.v2_importers.suse_score_importer import ( | ||
| SUSESeverityScoreImporterPipeline, | ||
| ) | ||
| from vulnerabilities.tests import util_tests | ||
|
|
||
| TEST_DATA = Path(__file__).parent.parent.parent / "test_data" / "suse_scores_v2" | ||
|
|
||
| TEST_YAML_DB = TEST_DATA / "suse-cvss-scores.yaml" | ||
|
|
||
|
|
||
| def test_suse_score_advisories(): | ||
| pipeline = SUSESeverityScoreImporterPipeline() | ||
|
|
||
| with open(TEST_YAML_DB) as f: | ||
| pipeline.score_data = saneyaml.load(f) | ||
|
|
||
| result = [adv.to_dict() for adv in pipeline.collect_advisories()] | ||
|
|
||
| expected_file = TEST_DATA / "suse-cvss-scores-expected.json" | ||
| util_tests.check_results_against_json(result, expected_file) |
84 changes: 84 additions & 0 deletions
84
vulnerabilities/tests/test_data/suse_scores_v2/suse-cvss-scores-expected.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| [ | ||
| { | ||
| "advisory_id": "CVE-2004-0230", | ||
| "aliases": [], | ||
| "summary": "", | ||
| "affected_packages": [], | ||
| "references_v2": [ | ||
| { | ||
| "reference_id": "CVE-2004-0230", | ||
| "reference_type": "", | ||
| "url": "https://ftp.suse.com/pub/projects/security/yaml/suse-cvss-scores.yaml" | ||
| } | ||
| ], | ||
| "patches": [], | ||
| "severities": [ | ||
| { | ||
| "system": "cvssv2", | ||
| "value": "4.3", | ||
| "scoring_elements": "AV:N/AC:M/Au:N/C:N/I:N/A:P" | ||
| }, | ||
| { | ||
| "system": "cvssv3.1", | ||
| "value": "3.7", | ||
| "scoring_elements": "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L" | ||
| } | ||
| ], | ||
| "date_published": null, | ||
| "weaknesses": [], | ||
| "url": "https://ftp.suse.com/pub/projects/security/yaml/suse-cvss-scores.yaml" | ||
| }, | ||
| { | ||
| "advisory_id": "CVE-2003-1605", | ||
| "aliases": [], | ||
| "summary": "", | ||
| "affected_packages": [], | ||
| "references_v2": [ | ||
| { | ||
| "reference_id": "CVE-2003-1605", | ||
| "reference_type": "", | ||
| "url": "https://ftp.suse.com/pub/projects/security/yaml/suse-cvss-scores.yaml" | ||
| } | ||
| ], | ||
| "patches": [], | ||
| "severities": [ | ||
| { | ||
| "system": "cvssv3", | ||
| "value": "8.6", | ||
| "scoring_elements": "CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:N/A:N" | ||
| } | ||
| ], | ||
| "date_published": null, | ||
| "weaknesses": [], | ||
| "url": "https://ftp.suse.com/pub/projects/security/yaml/suse-cvss-scores.yaml" | ||
| }, | ||
| { | ||
| "advisory_id": "CVE-2010-20103", | ||
| "aliases": [], | ||
| "summary": "", | ||
| "affected_packages": [], | ||
| "references_v2": [ | ||
| { | ||
| "reference_id": "CVE-2010-20103", | ||
| "reference_type": "", | ||
| "url": "https://ftp.suse.com/pub/projects/security/yaml/suse-cvss-scores.yaml" | ||
| } | ||
| ], | ||
| "patches": [], | ||
| "severities": [ | ||
| { | ||
| "system": "cvssv3.1", | ||
| "value": "9.8", | ||
| "scoring_elements": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H" | ||
| }, | ||
| { | ||
| "system": "cvssv4", | ||
| "value": "9.3", | ||
| "scoring_elements": "CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N" | ||
| } | ||
| ], | ||
| "date_published": null, | ||
| "weaknesses": [], | ||
| "url": "https://ftp.suse.com/pub/projects/security/yaml/suse-cvss-scores.yaml" | ||
| } | ||
| ] |
22 changes: 22 additions & 0 deletions
22
vulnerabilities/tests/test_data/suse_scores_v2/suse-cvss-scores.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| --- | ||
| CVE-2004-0230: | ||
| cvss: | ||
| - version: 2.0 | ||
| score: 4.3 | ||
| vector: AV:N/AC:M/Au:N/C:N/I:N/A:P | ||
| - version: 3.1 | ||
| score: 3.7 | ||
| vector: CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:L | ||
| CVE-2003-1605: | ||
| cvss: | ||
| - version: 3 | ||
| score: 8.6 | ||
| vector: CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:N/A:N | ||
| CVE-2010-20103: | ||
| cvss: | ||
| - version: 3.1 | ||
| score: 9.8 | ||
| vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H | ||
| - version: 4 | ||
| score: 9.3 | ||
| vector: CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@TG1999 We can’t create an advisory without a summary, affected_packages, or references, so we should at least include a reference.
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.
@ziadhany we should change this logic then, severities are also a good data point to capture, so if an advisory have a severity we should be able to create it.
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.
Okay, I will create an issue for that.