Skip to content

Commit ee1f0cf

Browse files
committed
Fix pysec importer
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
1 parent f71776b commit ee1f0cf

7 files changed

Lines changed: 464 additions & 554 deletions

File tree

vulnerabilities/importers/pysec.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,18 @@
2323
import logging
2424
from io import BytesIO
2525
from typing import Iterable
26+
from typing import List
2627
from typing import Optional
2728
from zipfile import ZipFile
2829

2930
import dateparser
3031
import requests
3132
from packageurl import PackageURL
32-
from univers.version_range import InvalidVersionRange
3333
from univers.version_range import PypiVersionRange
3434
from univers.versions import InvalidVersion
3535
from univers.versions import PypiVersion
3636
from univers.versions import SemverVersion
37+
from univers.versions import Version
3738

3839
from vulnerabilities.helpers import dedupe
3940
from vulnerabilities.importer import AdvisoryData
@@ -70,17 +71,32 @@ def advisory_data(self) -> Iterable[AdvisoryData]:
7071

7172

7273
def parse_advisory_data(raw_data: dict) -> Optional[AdvisoryData]:
73-
raw_id = raw_data["id"]
74+
raw_id = raw_data.get("id") or ""
7475
summary = raw_data.get("summary") or ""
75-
aliases = get_aliases(raw_data)
76+
details = raw_data.get("details") or ""
77+
summary_and_details = []
78+
if summary:
79+
summary_and_details.append(summary)
80+
if details:
81+
summary_and_details.append(details)
82+
summary = ".".join(summary_and_details)
83+
aliases = raw_data.get("aliases") or []
84+
if raw_id:
85+
aliases.append(raw_id)
7686
date_published = get_published_date(raw_data)
7787
severity = list(get_severities(raw_data))
7888
references = get_references(raw_data, severity)
7989

8090
affected_packages = []
8191
if "affected" not in raw_data:
8292
logger.error(f"affected_packages not found - {raw_id !r}")
83-
return
93+
return AdvisoryData(
94+
aliases=aliases,
95+
summary=summary,
96+
references=references,
97+
affected_packages=[],
98+
date_published=date_published,
99+
)
84100

85101
for affected_pkg in raw_data.get("affected") or []:
86102
purl = get_affected_purl(affected_pkg, raw_id)
@@ -110,7 +126,7 @@ def parse_advisory_data(raw_data: dict) -> Optional[AdvisoryData]:
110126
)
111127

112128

113-
def fixed_filter(fixed_range) -> []:
129+
def fixed_filter(fixed_range) -> Iterable[str]:
114130
"""
115131
Return a list of fixed version strings given a ``fixed_range`` mapping of OSV data.
116132
>>> list(fixed_filter({"type": "SEMVER", "events": [{"introduced": "0"}, {"fixed": "1.6.0"}]}))
@@ -124,30 +140,12 @@ def fixed_filter(fixed_range) -> []:
124140
yield fixed
125141

126142

127-
def get_aliases(raw_data) -> []:
128-
"""
129-
aliases field is optional , id is required and these are all aliases from our perspective
130-
converting list of two fields to a dict then , convert it to a list to make sure a list is unique
131-
>>> get_aliases({"id": "GHSA-j3f7-7rmc-6wqj"})
132-
['GHSA-j3f7-7rmc-6wqj']
133-
>>> get_aliases({"aliases": ["CVE-2021-40831"]})
134-
['CVE-2021-40831']
135-
>>> get_aliases({"aliases": ["CVE-2022-22817", "GHSA-8vj2-vxx3-667w"], "id": "GHSA-j3f7-7rmc-6wqj"})
136-
['CVE-2022-22817', 'GHSA-8vj2-vxx3-667w', 'GHSA-j3f7-7rmc-6wqj']
137-
"""
138-
vulnerability_id = raw_data.get("id")
139-
vulnerability_aliases = raw_data.get("aliases") or []
140-
if vulnerability_id:
141-
vulnerability_aliases.append(vulnerability_id)
142-
return vulnerability_aliases
143-
144-
145143
def get_published_date(raw_data):
146144
published = raw_data.get("published")
147145
return published and dateparser.parse(published)
148146

149147

150-
def get_severities(raw_data) -> []:
148+
def get_severities(raw_data) -> Iterable[VulnerabilitySeverity]:
151149
for sever_list in raw_data.get("severity") or []:
152150
if sever_list.get("type") == "CVSS_V3":
153151
yield VulnerabilitySeverity(
@@ -173,7 +171,7 @@ def get_severities(raw_data) -> []:
173171
)
174172

175173

176-
def get_references(raw_data, severities) -> []:
174+
def get_references(raw_data, severities) -> List[Reference]:
177175
references = raw_data.get("references") or []
178176
return [Reference(url=ref["url"], severities=severities) for ref in references if ref]
179177

@@ -199,14 +197,16 @@ def get_affected_version_range(affected_pkg, raw_id):
199197
affected_versions = affected_pkg.get("versions")
200198
if affected_versions:
201199
try:
202-
return PypiVersionRange(affected_versions)
203-
except InvalidVersionRange:
204-
logger.error(f"InvalidVersionRange affected_pkg_version_range Error - {raw_id !r} ")
200+
return PypiVersionRange.from_versions(affected_versions)
201+
except Exception as e:
202+
logger.error(
203+
f"InvalidVersionRange affected_pkg_version_range Error - {raw_id !r} {e!r}"
204+
)
205205
else:
206206
logger.error(f"affected_pkg_version_range not found - {raw_id !r} ")
207207

208208

209-
def get_fixed_version(fixed_range, raw_id) -> []:
209+
def get_fixed_version(fixed_range, raw_id) -> List[Version]:
210210
"""
211211
Return a list of fixed versions, using fixed_filter we get the list of fixed version strings,
212212
then we pass every element to their univers.versions , then we dedupe the result
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"aliases": [
3+
"CVE-2022-22817",
4+
"GHSA-8vj2-vxx3-667w",
5+
"PYSEC-2022-10"
6+
],
7+
"summary": "PIL.ImageMath.eval in Pillow before 9.0.0 allows evaluation of arbitrary expressions, such as ones that use the Python exec method.",
8+
"affected_packages": [
9+
{
10+
"package": {
11+
"type": "pypi",
12+
"namespace": null,
13+
"name": "pillow",
14+
"version": null,
15+
"qualifiers": null,
16+
"subpath": null
17+
},
18+
"affected_version_range": "vers:pypi/1.0|1.1|1.2|1.3|1.4|1.5|1.6|1.7.0|1.7.1|1.7.2|1.7.3|1.7.4|1.7.5|1.7.6|1.7.7|1.7.8|2.0.0|2.1.0|2.2.0|2.2.1|2.2.2|2.3.0|2.3.1|2.3.2|2.4.0|2.5.0|2.5.1|2.5.2|2.5.3|2.6.0|2.6.1|2.6.2|2.7.0|2.8.0|2.8.1|2.8.2|2.9.0|3.0.0|3.1.0rc1|3.1.0rc1|3.1.0|3.1.1|3.1.2|3.2.0|3.3.0|3.3.1|3.3.2|3.3.3|3.4.0|3.4.1|3.4.2|4.0.0|4.1.0|4.1.1|4.2.0|4.2.1|4.3.0|5.0.0|5.1.0|5.2.0|5.3.0|5.4.0.dev0|5.4.0|5.4.1|6.0.0|6.1.0|6.2.0|6.2.1|6.2.2|7.0.0|7.1.0|7.1.1|7.1.2|7.2.0|8.0.0|8.0.1|8.1.0|8.1.1|8.1.2|8.2.0|8.3.0|8.3.1|8.3.2|8.4.0",
19+
"fixed_version": "9.0.0"
20+
}
21+
],
22+
"references": [
23+
{
24+
"reference_id": "",
25+
"url": "https://pillow.readthedocs.io/en/stable/releasenotes/9.0.0.html#restrict-builtins-available-to-imagemath-eval",
26+
"severities": [
27+
{
28+
"system": "generic_textual",
29+
"value": "HIGH"
30+
}
31+
]
32+
},
33+
{
34+
"reference_id": "",
35+
"url": "https://lists.debian.org/debian-lts-announce/2022/01/msg00018.html",
36+
"severities": [
37+
{
38+
"system": "generic_textual",
39+
"value": "HIGH"
40+
}
41+
]
42+
},
43+
{
44+
"reference_id": "",
45+
"url": "https://github.com/advisories/GHSA-8vj2-vxx3-667w",
46+
"severities": [
47+
{
48+
"system": "generic_textual",
49+
"value": "HIGH"
50+
}
51+
]
52+
}
53+
],
54+
"date_published": "2022-01-10T14:12:00.853348+00:00"
55+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"aliases": [
3+
"CVE-2021-40831",
4+
"GHSA-j3f7-7rmc-6wqj"
5+
],
6+
"summary": "Improper certificate management in AWS IoT Device SDK v2.The AWS IoT Device SDK v2 for Java, Python, C++ and Node.js appends a user supplied Certificate Authority (CA) to the root CAs instead of overriding it on macOS systems. Additionally, SNI validation is also not enabled when the CA has been \u201coverridden\u201d. TLS handshakes will thus succeed if the peer can be verified either from the user-supplied CA or the system\u2019s default trust-store. Attackers with access to a host\u2019s trust stores or are able to compromise a certificate authority already in the host's trust store (note: the attacker must also be able to spoof DNS in this case) may be able to use this issue to bypass CA pinning. An attacker could then spoof the MQTT broker, and either drop traffic and/or respond with the attacker's data, but they would not be able to forward this data on to the MQTT broker because the attacker would still need the user's private keys to authenticate against the MQTT broker. The 'aws_tls_ctx_options_override_default_trust_store_*' function within the aws-c-io submodule has been updated to address this behavior. This issue affects: Amazon Web Services AWS IoT Device SDK v2 for Java versions prior to 1.5.0 on macOS. Amazon Web Services AWS IoT Device SDK v2 for Python versions prior to 1.7.0 on macOS. Amazon Web Services AWS IoT Device SDK v2 for C++ versions prior to 1.14.0 on macOS. Amazon Web Services AWS IoT Device SDK v2 for Node.js versions prior to 1.6.0 on macOS. Amazon Web Services AWS-C-IO 0.10.7 on macOS.",
7+
"affected_packages": [
8+
{
9+
"package": {
10+
"type": "pypi",
11+
"namespace": null,
12+
"name": "awsiotsdk",
13+
"version": null,
14+
"qualifiers": null,
15+
"subpath": null
16+
},
17+
"affected_version_range": "vers:pypi/0.2.4|0.2.9|0.3.0|1.0.2|1.0.3|1.0.5|1.0.6|1.1.0|1.2.0|1.2.1|1.3.0|1.3.1|1.3.2|1.4.0|1.5.0|1.5.1|1.5.2|1.5.3|1.5.4|1.5.5|1.5.6|1.5.7|1.5.8|1.5.10|1.5.11|1.5.12|1.5.13|1.5.14|1.5.15|1.5.16|1.5.17|1.5.18|1.6.0|1.6.1|1.6.2",
18+
"fixed_version": "1.7.0"
19+
}
20+
],
21+
"references": [
22+
{
23+
"reference_id": "",
24+
"url": "https://nvd.nist.gov/vuln/detail/CVE-2021-40831",
25+
"severities": [
26+
{
27+
"system": "cvssv3.1_vector",
28+
"value": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N"
29+
}
30+
]
31+
},
32+
{
33+
"reference_id": "",
34+
"url": "https://github.com/aws/aws-iot-device-sdk-cpp-v2",
35+
"severities": [
36+
{
37+
"system": "cvssv3.1_vector",
38+
"value": "CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:N"
39+
}
40+
]
41+
}
42+
],
43+
"date_published": "2021-11-24T20:35:03+00:00"
44+
}

0 commit comments

Comments
 (0)