Skip to content

Commit 9c0f05e

Browse files
committed
Merge sbs2001:kb_statements branch in main
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
2 parents 80a2981 + 41fc465 commit 9c0f05e

4 files changed

Lines changed: 97 additions & 2 deletions

File tree

vulnerabilities/data_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def _ensure_repository(self) -> None:
348348

349349
def _clone_repository(self) -> None:
350350
kwargs = {}
351-
if getattr(self, 'branch', False):
351+
if self.config.branch:
352352
kwargs['checkout_branch'] = self.config.branch
353353

354354
self._repo = pygit2.clone_repository(

vulnerabilities/importer_yielder.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@
184184
},
185185
{
186186
'name': 'msr2019',
187-
'license': '',
187+
'license': 'apache-2.0',
188188
'last_run': None,
189189
'data_source': 'ProjectKBMSRDataSource',
190190
'data_source_cfg': {
@@ -200,6 +200,16 @@
200200
'etags': {}
201201
},
202202
},
203+
{
204+
'name': 'kaybee',
205+
'license': 'apache-2.0',
206+
'last_run': None,
207+
'data_source': 'KaybeeDataSource',
208+
'data_source_cfg': {
209+
'repository_url': 'https://github.com/SAP/project-kb.git',
210+
'branch': 'vulnerability-data'
211+
},
212+
},
203213

204214
]
205215

vulnerabilities/importers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@
4040
from vulnerabilities.importers.nvd import NVDDataSource
4141
from vulnerabilities.importers.project_kb_msr2019 import ProjectKBMSRDataSource
4242
from vulnerabilities.importers.apache_httpd import ApacheHTTPDDataSource
43+
from vulnerabilities.importers.kaybee import KaybeeDataSource
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Copyright (c) nexB Inc. and others. All rights reserved.
2+
# http://nexb.com and https://github.com/nexB/vulnerablecode/
3+
# The VulnerableCode software is licensed under the Apache License version 2.0.
4+
# Data generated with VulnerableCode require an acknowledgment.
5+
#
6+
# You may not use this software except in compliance with the License.
7+
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software distributed
9+
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
10+
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
# specific language governing permissions and limitations under the License.
12+
#
13+
# When you publish or redistribute any data created with VulnerableCode or any VulnerableCode
14+
# derivative work, you must accompany this data with the following acknowledgment:
15+
#
16+
# Generated with VulnerableCode and provided on an "AS IS" BASIS, WITHOUT WARRANTIES
17+
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from
18+
# VulnerableCode should be considered or used as legal advice. Consult an Attorney
19+
# for any legal advice.
20+
# VulnerableCode is a free software tool from nexB Inc. and others.
21+
# Visit https://github.com/nexB/vulnerablecode/ for support and download.
22+
23+
import yaml
24+
25+
from packageurl import PackageURL
26+
27+
from vulnerabilities.data_source import GitDataSource
28+
from vulnerabilities.data_source import Advisory
29+
from vulnerabilities.data_source import Reference
30+
31+
32+
class KaybeeDataSource(GitDataSource):
33+
def __enter__(self):
34+
super(KaybeeDataSource, self).__enter__()
35+
self._added_files, self._updated_files = self.file_changes(
36+
recursive=True,
37+
file_ext="yaml",
38+
)
39+
print(self._added_files.union(self._updated_files))
40+
41+
def updated_advisories(self):
42+
advisories = []
43+
for yaml_file in self._added_files.union(self._updated_files):
44+
print(yaml_file)
45+
advisories.append(yaml_file_to_advisory(yaml_file))
46+
print(advisories[-1])
47+
48+
return self.batch_advisories(advisories)
49+
50+
51+
def yaml_file_to_advisory(yaml_path):
52+
impacted_packages = []
53+
resolved_packages = []
54+
references = []
55+
56+
data = load_yaml(yaml_path)
57+
vuln_id = data["vulnerability_id"]
58+
summary = "\n".join([note["text"] for note in data["notes"]])
59+
60+
for entry in data.get("artifacts", []):
61+
package = PackageURL.from_string(entry["id"])
62+
if entry["affected"]:
63+
impacted_packages.append(package)
64+
65+
else:
66+
resolved_packages.append(package)
67+
68+
for fix in data.get("fixes", []):
69+
for commit in fix["commits"]:
70+
references.append(Reference(url=f"{commit['repository']}/{commit['id']}"))
71+
72+
return Advisory(
73+
cve_id=vuln_id,
74+
summary=summary,
75+
impacted_package_urls=impacted_packages,
76+
resolved_package_urls=resolved_packages,
77+
vuln_references=references,
78+
)
79+
80+
81+
# TODO refactor all such commonly needed helpers into one single module
82+
def load_yaml(path):
83+
with open(path) as f:
84+
return yaml.safe_load(f)

0 commit comments

Comments
 (0)