Skip to content

Commit 5e1547a

Browse files
committed
➕ Add a VulCode importer
Signed-off-by: Shivam Sandbhor <[email protected]>
1 parent 985454c commit 5e1547a

File tree

4 files changed

+78
-2
lines changed

4 files changed

+78
-2
lines changed

vulnerabilities/data_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2017 nexB Inc. and others. All rights reserved.
1+
# Copyright (c) nexB Inc. and others. All rights reserved.
22
# http://nexb.com and https://github.com/nexB/vulnerablecode/
33
# The VulnerableCode software is licensed under the Apache License version 2.0.
44
# Data generated with VulnerableCode require an acknowledgment.

vulnerabilities/importer_yielder.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@
172172
'db_url': 'https://usn.ubuntu.com/usn-db/database-all.json.bz2'
173173
},
174174
},
175-
176175
{
177176
'name': 'github',
178177
'license': '',
@@ -182,6 +181,16 @@
182181
'endpoint': 'https://api.github.com/graphql',
183182
'ecosystems': ['MAVEN', 'NUGET', 'COMPOSER']
184183
}
184+
},
185+
186+
{
187+
'name': 'vulcodes',
188+
'license': '',
189+
'last_run': None,
190+
'data_source': 'VulCodeDataSource',
191+
'data_source_cfg': {
192+
'repository_url': 'https://github.com/sbs2001/vulcodes.git'
193+
}
185194
}
186195

187196
]

vulnerabilities/importers/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@
3838
from vulnerabilities.importers.ubuntu_usn import UbuntuUSNDataSource
3939
from vulnerabilities.importers.github import GitHubAPIDataSource
4040
from vulnerabilities.importers.nvd import NVDDataSource
41+
from vulnerabilities.importers.vulcodes import VulCodeDataSource

vulnerabilities/importers/vulcodes.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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 code scanning tool from nexB Inc. and others.
21+
# Visit https://github.com/nexB/vulnerablecode/ for support and download.
22+
23+
import json
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 VulCodeDataSource(GitDataSource):
33+
def __enter__(self):
34+
super(VulCodeDataSource, self).__enter__()
35+
36+
if not getattr(self, "_added_files", None):
37+
self._added_files, self._updated_files = self.file_changes(
38+
file_ext="json",
39+
)
40+
41+
def updated_advisories(self):
42+
43+
advisories = []
44+
for file in self._added_files.union(self._updated_files):
45+
with open(file) as f:
46+
data = json.load(f)
47+
references = []
48+
49+
for ref in data["references"]:
50+
references.append(Reference(url=ref["url"], reference_id=ref["reference_id"]))
51+
52+
advisories.append(
53+
Advisory(
54+
identifier=data["identifier"],
55+
summary=data["summary"],
56+
impacted_package_urls=[
57+
PackageURL.from_string(purl) for purl in data["vulnerable_packages"]
58+
],
59+
resolved_package_urls=[
60+
PackageURL.from_string(purl) for purl in data["resolved_packages"]
61+
],
62+
vuln_references=references,
63+
)
64+
)
65+
66+
return self.batch_advisories(advisories)

0 commit comments

Comments
 (0)