Skip to content

Commit ffba91c

Browse files
author
Prabhu Subramanian
committed
Include vendor for npm
1 parent 0402a2e commit ffba91c

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="appthreat-vulnerability-db",
8-
version="1.4.3",
8+
version="1.4.4",
99
author="Team AppThreat",
1010
author_email="cloud@appthreat.com",
1111
description="AppThreat's vulnerability database and package search library with a built-in file based storage. CVE, GitHub, npm are the primary sources of vulnerabilities.",

vdb/cli.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ def build_args():
7878
dest="search",
7979
help="Search for package and version in the database. Use colon to separate package and version. Use comma to specify multiple values. Eg: android:8.0",
8080
)
81+
parser.add_argument(
82+
"--search-npm",
83+
dest="search_npm",
84+
help="Search for package and version in the database. Use colon to separate package and version. Use comma to specify multiple values. Eg: android:8.0",
85+
)
8186
parser.add_argument(
8287
"--list",
8388
action="store_true",
@@ -158,6 +163,10 @@ def main():
158163
for s in [GitHubSource()]:
159164
LOG.info("Syncing {}".format(s.__class__.__name__))
160165
s.download_recent()
166+
if args.search_npm:
167+
source = NpmSource()
168+
results = source.bulk_search(config.npm_app_info, [args.search_npm])
169+
print_results(results)
161170
if args.list:
162171
db = dbLib.get()
163172
results = dbLib.list_all_occurrence(db)

vdb/lib/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
npm_audit_url = npm_server + "/-/npm/v1/security/audits"
3232
npm_advisories_url = npm_server + "/-/npm/v1/security/advisories"
3333

34+
npm_app_info = {"name": "appthreat-vdb", "version": "1.0.0"}
35+
3436
CVE_TPL = """
3537
{"cve":{"data_type":"CVE","data_format":"MITRE","data_version":"4.0","CVE_data_meta":{"ID":"%(cve_id)s","ASSIGNER":"%(assigner)s"},"problemtype":{"problemtype_data":[{"description":[{"lang":"en","value":"%(cwe_id)s"}]}]},"references":{"reference_data": %(references)s},"description":{"description_data":[{"lang":"en","value":"%(description)s"}]}},"configurations":{"CVE_data_version":"4.0","nodes":[{"operator":"OR","cpe_match":[{"vulnerable":true,"cpe23Uri":"cpe:2.3:a:%(vendor)s:%(product)s:%(version)s:*:*:*:*:*:*:*","versionStartExcluding":"%(version_start_excluding)s","versionEndExcluding":"%(version_end_excluding)s","versionStartIncluding":"%(version_start_including)s","versionEndIncluding":"%(version_end_including)s"}, {"vulnerable":false,"cpe23Uri":"cpe:2.3:a:%(vendor)s:%(product)s:%(fix_version_start_including)s:*:*:*:*:*:*:*","versionStartExcluding":"%(fix_version_start_excluding)s","versionEndExcluding":"%(fix_version_end_excluding)s","versionStartIncluding":"%(fix_version_start_including)s","versionEndIncluding":"%(fix_version_end_including)s"}]}]},"impact":{"baseMetricV3":{"cvssV3":{"version":"3.1","vectorString":"%(vectorString)s","attackVector":"NETWORK","attackComplexity":"%(attackComplexity)s","privilegesRequired":"NONE","userInteraction":"REQUIRED","scope":"UNCHANGED","confidentialityImpact":"%(severity)s","integrityImpact":"%(severity)s","availabilityImpact":"%(severity)s","baseScore":%(score).1f,"baseSeverity":"%(severity)s"},"exploitabilityScore":%(exploitabilityScore).1f,"impactScore":%(score).1f},"baseMetricV2":{"cvssV2":{"version":"2.0","vectorString":"AV:N/AC:M/Au:N/C:P/I:P/A:P","accessVector":"NETWORK","accessComplexity":"MEDIUM","authentication":"NONE","confidentialityImpact":"PARTIAL","integrityImpact":"PARTIAL","availabilityImpact":"PARTIAL","baseScore":%(score).1f},"severity":"%(severity)s","exploitabilityScore":%(exploitabilityScore).1f,"impactScore":%(score).1f,"acInsufInfo":false,"obtainAllPrivilege":false,"obtainUserPrivilege":false,"obtainOtherPrivilege":false,"userInteractionRequired":false}},"publishedDate":"%(publishedDate)s","lastModifiedDate":"%(lastModifiedDate)s"}
3638
"""

vdb/lib/npm.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,22 @@ def bulk_search(self, app_info, pkg_list):
4040
requires = {}
4141
dependencies = {}
4242
for pkg in pkg_list:
43+
vendor = None
4344
if isinstance(pkg, dict):
45+
vendor = pkg.get("vendor")
4446
name = pkg.get("name")
4547
version = pkg.get("version")
4648
else:
4749
tmpA = pkg.split("|")
4850
version = tmpA[len(tmpA) - 1]
4951
name = tmpA[len(tmpA) - 2]
50-
requires[name] = version
51-
dependencies[name] = {"version": version}
52+
if len(tmpA) == 3:
53+
vendor = tmpA[0]
54+
key = name
55+
if vendor:
56+
key = f"{vendor}/{name}"
57+
requires[key] = version
58+
dependencies[key] = {"version": version}
5259
payload["requires"] = requires
5360
payload["dependencies"] = dependencies
5461
return convert_to_occurrence(serialize_vuln_list(self.fetch(payload)))
@@ -148,10 +155,11 @@ def convert(self, adv_data):
148155
for d in adv_data:
149156
self.to_vuln(d, ret_data)
150157
else:
151-
for k, v in adv_data.get("advisories").items():
152-
if v["deleted"]:
153-
continue
154-
self.to_vuln(v, ret_data)
158+
if adv_data.get("advisories"):
159+
for k, v in adv_data.get("advisories").items():
160+
if v["deleted"]:
161+
continue
162+
self.to_vuln(v, ret_data)
155163
return ret_data
156164

157165
def to_vuln(self, v, ret_data):

0 commit comments

Comments
 (0)