Skip to content

Commit 574d06e

Browse files
authored
Merge pull request #1151 from keshav-space/advisory_compare
Support Advisory Comparison in VulnTotal
2 parents 97fcbcf + 243f849 commit 574d06e

File tree

10 files changed

+528
-60
lines changed

10 files changed

+528
-60
lines changed

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ toml==0.10.2
106106
tomli==2.0.1
107107
traitlets==5.1.1
108108
typing_extensions==4.1.1
109-
univers==30.11.0
109+
univers==30.12.0
110110
urllib3==1.26.19
111111
wcwidth==0.2.5
112112
websocket-client==0.59.0

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ install_requires =
7171

7272
#essentials
7373
packageurl-python>=0.10.5rc1
74-
univers>=30.11.0
74+
univers>=30.12.0
7575
license-expression>=21.6.14
7676

7777
# file and data formats

vulnerabilities/tests/test_data/apache_kafka/apache-kafka-improver-expected.json

Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,206 @@
11
[
2+
{
3+
"vulnerability_id": null,
4+
"aliases": [
5+
"CVE-2021-38153"
6+
],
7+
"confidence": 100,
8+
"summary": "Some components in Apache Kafka use Arrays.equals to validate a password or key, which is vulnerable to timing attacks that make brute force attacks for such credentials more likely to be successful. Users should upgrade to 2.8.1 or higher, or 3.0.0 or higher where this vulnerability has been fixed.",
9+
"affected_purls": [
10+
{
11+
"type": "apache",
12+
"namespace": "",
13+
"name": "kafka",
14+
"version": "1.1.0",
15+
"qualifiers": "",
16+
"subpath": ""
17+
},
18+
{
19+
"type": "apache",
20+
"namespace": "",
21+
"name": "kafka",
22+
"version": "1.1.1",
23+
"qualifiers": "",
24+
"subpath": ""
25+
},
26+
{
27+
"type": "apache",
28+
"namespace": "",
29+
"name": "kafka",
30+
"version": "1.1.2",
31+
"qualifiers": "",
32+
"subpath": ""
33+
},
34+
{
35+
"type": "apache",
36+
"namespace": "",
37+
"name": "kafka",
38+
"version": "1.1.3",
39+
"qualifiers": "",
40+
"subpath": ""
41+
},
42+
{
43+
"type": "apache",
44+
"namespace": "",
45+
"name": "kafka",
46+
"version": "1.1.4",
47+
"qualifiers": "",
48+
"subpath": ""
49+
},
50+
{
51+
"type": "apache",
52+
"namespace": "",
53+
"name": "kafka",
54+
"version": "1.1.5",
55+
"qualifiers": "",
56+
"subpath": ""
57+
},
58+
{
59+
"type": "apache",
60+
"namespace": "",
61+
"name": "kafka",
62+
"version": "1.1.6",
63+
"qualifiers": "",
64+
"subpath": ""
65+
},
66+
{
67+
"type": "apache",
68+
"namespace": "",
69+
"name": "kafka",
70+
"version": "1.1.7",
71+
"qualifiers": "",
72+
"subpath": ""
73+
},
74+
{
75+
"type": "apache",
76+
"namespace": "",
77+
"name": "kafka",
78+
"version": "1.1.8",
79+
"qualifiers": "",
80+
"subpath": ""
81+
}
82+
],
83+
"fixed_purl": null,
84+
"references": [
85+
{
86+
"reference_id": "CVE-2021-38153",
87+
"url": "https://kafka.apache.org/cve-list",
88+
"severities": []
89+
},
90+
{
91+
"reference_id": "CVE-2021-38153",
92+
"url": "https://kafka.apache.org/cve-list#CVE-2021-38153",
93+
"severities": []
94+
},
95+
{
96+
"reference_id": "CVE-2021-38153",
97+
"url": "https://nvd.nist.gov/vuln/detail/CVE-2021-38153",
98+
"severities": []
99+
}
100+
],
101+
"weaknesses": []
102+
},
103+
{
104+
"vulnerability_id": null,
105+
"aliases": [
106+
"CVE-2019-12399"
107+
],
108+
"confidence": 100,
109+
"summary": "When Connect workers in Apache Kafka 2.0.0, 2.0.1, 2.1.0, 2.1.1, 2.2.0, 2.2.1, or 2.3.0 are configured with one or more config providers, and a connector is created/updated on that Connect cluster to use an externalized secret variable in a substring of a connector configuration property value (the externalized secret variable is not the whole configuration property value), then any client can issue a request to the same Connect cluster to obtain the connector's task configurations and the response will contain the plaintext secret rather than the externalized secrets variable. Users should upgrade to 2.2.2 or higher, or 2.3.1 or higher where this vulnerability has been fixed.",
110+
"affected_purls": [
111+
{
112+
"type": "apache",
113+
"namespace": "",
114+
"name": "kafka",
115+
"version": "1.1.0",
116+
"qualifiers": "",
117+
"subpath": ""
118+
},
119+
{
120+
"type": "apache",
121+
"namespace": "",
122+
"name": "kafka",
123+
"version": "1.1.1",
124+
"qualifiers": "",
125+
"subpath": ""
126+
},
127+
{
128+
"type": "apache",
129+
"namespace": "",
130+
"name": "kafka",
131+
"version": "1.1.2",
132+
"qualifiers": "",
133+
"subpath": ""
134+
},
135+
{
136+
"type": "apache",
137+
"namespace": "",
138+
"name": "kafka",
139+
"version": "1.1.3",
140+
"qualifiers": "",
141+
"subpath": ""
142+
},
143+
{
144+
"type": "apache",
145+
"namespace": "",
146+
"name": "kafka",
147+
"version": "1.1.4",
148+
"qualifiers": "",
149+
"subpath": ""
150+
},
151+
{
152+
"type": "apache",
153+
"namespace": "",
154+
"name": "kafka",
155+
"version": "1.1.5",
156+
"qualifiers": "",
157+
"subpath": ""
158+
},
159+
{
160+
"type": "apache",
161+
"namespace": "",
162+
"name": "kafka",
163+
"version": "1.1.6",
164+
"qualifiers": "",
165+
"subpath": ""
166+
},
167+
{
168+
"type": "apache",
169+
"namespace": "",
170+
"name": "kafka",
171+
"version": "1.1.7",
172+
"qualifiers": "",
173+
"subpath": ""
174+
},
175+
{
176+
"type": "apache",
177+
"namespace": "",
178+
"name": "kafka",
179+
"version": "1.1.8",
180+
"qualifiers": "",
181+
"subpath": ""
182+
}
183+
],
184+
"fixed_purl": null,
185+
"references": [
186+
{
187+
"reference_id": "CVE-2019-12399",
188+
"url": "https://kafka.apache.org/cve-list",
189+
"severities": []
190+
},
191+
{
192+
"reference_id": "CVE-2019-12399",
193+
"url": "https://kafka.apache.org/cve-list#CVE-2019-12399",
194+
"severities": []
195+
},
196+
{
197+
"reference_id": "CVE-2019-12399",
198+
"url": "https://nvd.nist.gov/vuln/detail/CVE-2019-12399",
199+
"severities": []
200+
}
201+
],
202+
"weaknesses": []
203+
},
2204
{
3205
"vulnerability_id": null,
4206
"aliases": [

vulntotal/datasources/deps.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ def datasource_advisory(self, purl) -> Iterable[VendorData]:
4242
A list of VendorData objects containing the advisory information.
4343
"""
4444
payload = generate_meta_payload(purl)
45+
if not payload:
46+
return
4547
response = self.fetch_json_response(payload)
4648
if response:
4749
advisories = parse_advisories_from_meta(response)

vulntotal/datasources/github.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def parse_advisory(interesting_edges, purl) -> Iterable[VendorData]:
101101
"""
102102
for edge in interesting_edges:
103103
node = edge["node"]
104-
aliases = [alias["value"] for alias in get_item(node, "advisory", "identifiers")]
105-
affected_versions = node["vulnerableVersionRange"].strip().replace(" ", "").split(",")
104+
aliases = [aliase["value"] for aliase in get_item(node, "advisory", "identifiers")]
105+
affected_versions = [node["vulnerableVersionRange"].strip()]
106106
parsed_fixed_versions = get_item(node, "firstPatchedVersion", "identifier")
107107
fixed_versions = [parsed_fixed_versions] if parsed_fixed_versions else []
108108
yield VendorData(

vulntotal/datasources/gitlab.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def get_casesensitive_slug(path, package_slug):
180180

181181
# If the namespace/subfolder contains multiple packages, then progressive transverse through folders tree
182182
if package_slug.lower().startswith(slug_flatpath.lower()):
183-
return get_gitlab_style_slug(slug_flatpath, package_slug)
183+
return get_casesensitive_slug(slug_flatpath, package_slug)
184184

185185
payload[0]["variables"]["nextPageCursor"] = paginated_tree["pageInfo"]["endCursor"]
186186
has_next = paginated_tree["pageInfo"]["hasNextPage"]

vulntotal/datasources/snyk.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#
99

1010
import logging
11+
import re
1112
from typing import Iterable
1213
from urllib.parse import quote
1314
from urllib.parse import unquote_plus
@@ -23,6 +24,8 @@
2324

2425
logger = logging.getLogger(__name__)
2526

27+
fixed_version_pattern = re.compile(r"\b\d[\w.-]*\b")
28+
2629

2730
class SnykDataSource(DataSource):
2831
spdx_license_expression = "TODO"
@@ -107,6 +110,7 @@ def datasource_advisory_from_cve(self, cve: str) -> Iterable[VendorData]:
107110
@classmethod
108111
def supported_ecosystem(cls):
109112
return {
113+
"cargo": "cargo",
110114
"cocoapods": "cocoapods",
111115
"composer": "composer",
112116
"golang": "golang",
@@ -115,6 +119,7 @@ def supported_ecosystem(cls):
115119
"maven": "maven",
116120
"npm": "npm",
117121
"nuget": "nuget",
122+
"pub": "pub",
118123
"pypi": "pip",
119124
"gem": "rubygems",
120125
# any purl.type not in supported_ecosystem shall implicitly be treated as unmanaged type
@@ -272,18 +277,16 @@ def parse_html_advisory(advisory_html, snyk_id, affected, purl) -> VendorData:
272277
advisory_soup = BeautifulSoup(advisory_html, "html.parser")
273278
cve_span = advisory_soup.find("span", class_="cve")
274279
if cve_span:
275-
cve_anchor = cve_span.find("a", class_="vue--anchor")
276-
aliases.append(cve_anchor["id"])
280+
if cve_anchor := cve_span.find("a", class_="vue--anchor"):
281+
aliases.append(cve_anchor.get("id"))
277282

278283
how_to_fix = advisory_soup.find(
279284
"div", class_="vue--block vuln-page__instruction-block vue--block--instruction"
280285
)
281-
if how_to_fix:
282-
fixed = how_to_fix.find("p").text.split(" ")
283-
if "Upgrade" in fixed:
284-
lower = fixed.index("version") if "version" in fixed else fixed.index("versions")
285-
upper = fixed.index("or")
286-
fixed_versions = "".join(fixed[lower + 1 : upper]).split(",")
286+
287+
if how_to_fix and (fixed := how_to_fix.find("p").text):
288+
fixed_versions = fixed_version_pattern.findall(fixed)
289+
287290
aliases.append(snyk_id)
288291
return VendorData(
289292
purl=PackageURL(purl.type, purl.namespace, purl.name),

vulntotal/tests/test_data/github/parse_advisory-expected.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
"purl": "pkg:generic/namespace/test",
44
"affected_versions": [
5-
"<2.7.2"
5+
"< 2.7.2"
66
],
77
"fixed_versions": [
88
"2.7.2"
@@ -15,7 +15,7 @@
1515
{
1616
"purl": "pkg:generic/namespace/test",
1717
"affected_versions": [
18-
"<2.11.3"
18+
"< 2.11.3"
1919
],
2020
"fixed_versions": [
2121
"2.11.3"
@@ -28,7 +28,7 @@
2828
{
2929
"purl": "pkg:generic/namespace/test",
3030
"affected_versions": [
31-
"<2.8.1"
31+
"< 2.8.1"
3232
],
3333
"fixed_versions": [
3434
"2.8.1"
@@ -41,7 +41,7 @@
4141
{
4242
"purl": "pkg:generic/namespace/test",
4343
"affected_versions": [
44-
"<2.10.1"
44+
"< 2.10.1"
4545
],
4646
"fixed_versions": [
4747
"2.10.1"

0 commit comments

Comments
 (0)