-
-
Notifications
You must be signed in to change notification settings - Fork 234
Migrate Xen, Curl, Istio and OSS-Fuzz importer #1946
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0922e44
Migrate Xen importer
TG1999 e954b60
Add tests for Xen importer
TG1999 0b5f4ab
Migrate CURL importer
TG1999 655c583
Fix tests
TG1999 729c86a
Add OSS Fuzz importer
TG1999 a08bde0
Add OSS Fuzz importer
TG1999 b63464e
Migrate Istio importer
TG1999 da0bf37
Add tests for OSS-FUZZ
TG1999 2e10f7e
Fix tests
TG1999 3e09dc9
Add postgresql importer
TG1999 edbbc67
Add mozilla importer
TG1999 4c20709
Fix tests
TG1999 3479b49
Fix linting errors
TG1999 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
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
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
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
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
22 changes: 22 additions & 0 deletions
22
vulnerabilities/migrations/0099_advisoryv2_original_advisory_text.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,22 @@ | ||
# Generated by Django 4.2.22 on 2025-07-16 08:39 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("vulnerabilities", "0098_alter_advisory_options_alter_advisoryalias_options_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="advisoryv2", | ||
name="original_advisory_text", | ||
field=models.TextField( | ||
blank=True, | ||
help_text="Raw advisory data as collected from the upstream datasource.", | ||
null=True, | ||
), | ||
), | ||
] |
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
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
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
156 changes: 156 additions & 0 deletions
156
vulnerabilities/pipelines/v2_importers/curl_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,156 @@ | ||
# | ||
# Copyright (c) nexB Inc. and others. All rights reserved. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
|
||
import json | ||
import logging | ||
from datetime import datetime | ||
from datetime import timezone | ||
from typing import Iterable | ||
|
||
from cwe2.database import Database | ||
from packageurl import PackageURL | ||
from univers.version_range import GenericVersionRange | ||
from univers.versions import SemverVersion | ||
|
||
from vulnerabilities.importer import AdvisoryData | ||
from vulnerabilities.importer import AffectedPackage | ||
from vulnerabilities.importer import ReferenceV2 | ||
from vulnerabilities.importer import VulnerabilitySeverity | ||
from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipelineV2 | ||
from vulnerabilities.severity_systems import SCORING_SYSTEMS | ||
from vulnerabilities.utils import fetch_response | ||
from vulnerabilities.utils import get_cwe_id | ||
from vulnerabilities.utils import get_item | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class CurlImporterPipeline(VulnerableCodeBaseImporterPipelineV2): | ||
""" | ||
Pipeline-based importer for curl advisories from curl.se. | ||
""" | ||
|
||
pipeline_id = "curl_importer_v2" | ||
spdx_license_expression = "curl" | ||
license_url = "https://curl.se/docs/copyright.html" | ||
repo_url = "https://github.com/curl/curl-www/" | ||
url = "https://curl.se/docs/vuln.json" | ||
unfurl_version_ranges = True | ||
|
||
@classmethod | ||
def steps(cls): | ||
return (cls.collect_and_store_advisories,) | ||
|
||
def fetch_data(self): | ||
return fetch_response(self.url).json() | ||
|
||
def advisories_count(self) -> int: | ||
return len(self.fetch_data()) | ||
|
||
def collect_advisories(self) -> Iterable[AdvisoryData]: | ||
for entry in self.fetch_data(): | ||
cve_id = entry.get("aliases") or [] | ||
cve_id = cve_id[0] if cve_id else None | ||
if not cve_id or not cve_id.startswith("CVE"): | ||
package = get_item(entry, "database_specific", "package") | ||
logger.error(f"Invalid CVE ID: {cve_id} in package {package}") | ||
continue | ||
yield parse_curl_advisory(entry) | ||
|
||
|
||
def parse_curl_advisory(raw_data) -> AdvisoryData: | ||
""" | ||
Parse advisory data from raw JSON data and return an AdvisoryData object. | ||
|
||
Args: | ||
raw_data (dict): Raw JSON data containing advisory information. | ||
|
||
Returns: | ||
AdvisoryData: Parsed advisory data as an AdvisoryData object. | ||
""" | ||
affected = get_item(raw_data, "affected")[0] if len(get_item(raw_data, "affected")) > 0 else [] | ||
|
||
ranges = get_item(affected, "ranges")[0] if len(get_item(affected, "ranges")) > 0 else [] | ||
events = get_item(ranges, "events")[1] if len(get_item(ranges, "events")) > 1 else {} | ||
version_type = get_item(ranges, "type") if get_item(ranges, "type") else "" | ||
fixed_version = events.get("fixed") | ||
if version_type == "SEMVER" and fixed_version: | ||
fixed_version = SemverVersion(fixed_version) | ||
|
||
purl = PackageURL(type="generic", namespace="curl.se", name="curl") | ||
versions = affected.get("versions") or [] | ||
affected_version_range = GenericVersionRange.from_versions(versions) | ||
|
||
affected_package = AffectedPackage( | ||
package=purl, | ||
affected_version_range=affected_version_range, | ||
fixed_version=fixed_version, | ||
) | ||
|
||
database_specific = raw_data.get("database_specific") or {} | ||
|
||
references = [] | ||
www_url = database_specific.get("www") | ||
issue_url = database_specific.get("issue") | ||
json_url = database_specific.get("URL") | ||
|
||
if www_url: | ||
references.append(ReferenceV2(url=www_url)) | ||
if issue_url: | ||
references.append(ReferenceV2(url=issue_url)) | ||
severity = VulnerabilitySeverity( | ||
system=SCORING_SYSTEMS["cvssv3.1"], value=database_specific.get("severity", ""), url=www_url | ||
) | ||
|
||
published = raw_data.get("published", "") | ||
date_published = ( | ||
datetime.strptime(published, "%Y-%m-%dT%H:%M:%S.%fZ").replace(tzinfo=timezone.utc) | ||
if published | ||
else None | ||
) | ||
|
||
weaknesses = get_cwe_from_curl_advisory(raw_data) | ||
|
||
aliases = raw_data.get("aliases", []) | ||
advisory_id = raw_data.get("id") or "" | ||
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. Instead of returning an advisory data with no |
||
|
||
if advisory_id in aliases: | ||
aliases.remove(advisory_id) | ||
|
||
return AdvisoryData( | ||
advisory_id=advisory_id, | ||
aliases=aliases, | ||
summary=raw_data.get("summary") or "", | ||
affected_packages=[affected_package], | ||
references_v2=references, | ||
date_published=date_published, | ||
weaknesses=weaknesses, | ||
url=json_url, | ||
severities=[severity], | ||
original_advisory_text=json.dumps(raw_data, indent=2, ensure_ascii=False), | ||
) | ||
|
||
|
||
def get_cwe_from_curl_advisory(raw_data): | ||
""" | ||
Extracts CWE IDs from the given raw_data and returns a list of CWE IDs. | ||
|
||
>>> get_cwe_from_curl_advisory({"database_specific": {"CWE": {"id": "CWE-333"}}}) | ||
[333] | ||
>>> get_cwe_from_curl_advisory({"database_specific": {"CWE": {"id": ""}}}) | ||
[] | ||
""" | ||
weaknesses = [] | ||
db = Database() | ||
cwe_string = get_item(raw_data, "database_specific", "CWE", "id") or "" | ||
|
||
if cwe_string: | ||
try: | ||
cwe_id = get_cwe_id(cwe_string) | ||
db.get(cwe_id) # validate CWE exists | ||
weaknesses.append(cwe_id) | ||
except Exception: | ||
logger.error(f"Invalid CWE id: {cwe_string}") | ||
return weaknesses |
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.
I don't think we need indent.