Skip to content

Commit 043cea8

Browse files
committed
import data from oss_fuzz using osv format
Signed-off-by: ziad <ziadhany2016@gmail.com>
1 parent 9269de9 commit 043cea8

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

vulnerabilities/importers/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from vulnerabilities.importers import nginx
1515
from vulnerabilities.importers import nvd
1616
from vulnerabilities.importers import openssl
17+
from vulnerabilities.importers import oss_fuzz
1718
from vulnerabilities.importers import pypa
1819
from vulnerabilities.importers import pysec
1920
from vulnerabilities.importers import redhat
@@ -27,8 +28,9 @@
2728
redhat.RedhatImporter,
2829
pysec.PyPIImporter,
2930
debian.DebianImporter,
30-
gitlab.GitLabAPIImporter,
31+
gitlab.GitLabGitImporter,
3132
pypa.PyPaImporter,
33+
oss_fuzz.OSS_FuzzImporter,
3234
]
3335

3436
IMPORTERS_REGISTRY = {x.qualified_name: x for x in IMPORTERS_REGISTRY}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/nexB/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#
9+
import logging
10+
import os
11+
from typing import Iterable
12+
13+
import saneyaml
14+
from fetchcode.vcs.git import fetch_via_git
15+
16+
from vulnerabilities.importer import AdvisoryData
17+
from vulnerabilities.importer import Importer
18+
from vulnerabilities.importers.osv import parse_advisory_data
19+
20+
logger = logging.getLogger(__name__)
21+
22+
23+
class OSS_FuzzImporter(Importer):
24+
license_url = "https://github.com/google/oss-fuzz-vulns/blob/main/LICENSE"
25+
spdx_license_expression = "CC-BY-4.0"
26+
url = "git+https://github.com/google/oss-fuzz-vulns"
27+
28+
def advisory_data(self) -> Iterable[AdvisoryData]:
29+
for file in fork_and_get_files(self.url):
30+
yield parse_advisory_data(file, supported_ecosystem="oss-fuzz")
31+
32+
33+
class ForkError(Exception):
34+
pass
35+
36+
37+
def fork_and_get_files(url) -> dict:
38+
"""
39+
Fetch the github repository and go to vulns directory ,
40+
then open directories one by one and return a file .
41+
"""
42+
try:
43+
fork_directory = fetch_via_git(url=url)
44+
except Exception as e:
45+
logger.error(f"Can't clone url {url}")
46+
raise ForkError(url) from e
47+
48+
advisory_dirs = os.path.join(fork_directory.dest_dir, "vulns")
49+
for root, _, files in os.walk(advisory_dirs):
50+
for file in files:
51+
if not file.endswith(".yaml"):
52+
logger.warning(f"unsupported file {file}")
53+
else:
54+
with open(os.path.join(root, file), "r") as f:
55+
yield saneyaml.load(f.read())

vulnerabilities/importers/osv.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ def get_fixed_version(fixed_range, raw_id) -> List[Version]:
192192
fixed_version.append(SemverVersion(i))
193193
except InvalidVersion:
194194
logger.error(f"Invalid Version - SemverVersion - {raw_id !r} - {i !r}")
195+
195196
# if fixed_range_type == "GIT":
196197
# TODO add GitHubVersion univers fix_version
197198
# logger.error(f"NotImplementedError GIT Version - {raw_id !r} - {i !r}")

vulnerablecode/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
ALLOWED_HOSTS = env.list("ALLOWED_HOSTS", default=[".localhost", "127.0.0.1", "[::1]"])
3131

3232
# SECURITY WARNING: don't run with debug turned on in production
33-
DEBUG = env.bool("VULNERABLECODE_DEBUG", default=False)
33+
DEBUG = env.bool("VULNERABLECODE_DEBUG", default=True)
3434

3535
# Application definition
3636

0 commit comments

Comments
 (0)