Skip to content

Commit c1b3547

Browse files
authored
Merge pull request #563 from enzbang/fix-cve-test
Fix CVE test by using a simpler cache
2 parents f0274f0 + 9b57994 commit c1b3547

File tree

7 files changed

+5681
-4
lines changed

7 files changed

+5681
-4
lines changed

src/e3/cve.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,27 @@ class NVD:
3737
"""Provide access to the NVD API."""
3838

3939
def __init__(
40-
self, cache_db_path: str | None = None, nvd_api_key: str | None = None
40+
self,
41+
cache_db_path: str | None = None,
42+
cache_backend: str | None = None,
43+
nvd_api_key: str | None = None,
4144
) -> None:
4245
"""Initialize a NVD instance.
4346
4447
:param cache_db_path: path to the cache database [strongly recommended]
4548
if the path is valid but the file does not exist, the database will
4649
be created when searching for CVE. Note that this requires requests-cache
4750
package.
51+
:param cache_backend: which requests_cache backend to use, default is
52+
sqlite
4853
:param nvd_api_key: the API key to use to avoid drastic rate limits
4954
"""
5055
self.cache_db_path = cache_db_path
5156
if self.cache_db_path is None:
5257
logger.warning(
5358
"the use of a cache for NVD requests is strongly recommended"
5459
)
60+
self.cache_backend = cache_backend
5561
self.nvd_api_key = nvd_api_key
5662
if self.nvd_api_key is None:
5763
logger.warning(
@@ -116,14 +122,17 @@ def session(self) -> Session:
116122

117123
session = CachedSession(
118124
self.cache_db_path,
125+
backend=self.cache_backend,
119126
# Use Cache-Control headers for expiration, if available
120127
cache_control=True,
121128
# Otherwise renew the cache every day
122129
expire_after=timedelta(days=1),
123130
# Use cache data in case of errors
124131
stale_if_error=True,
132+
# Ignore headers
133+
match_header=False,
125134
)
126-
logger.debug(f"using requests cache from {session.cache.db_path}")
135+
logger.debug(f"using requests cache from {self.cache_db_path}")
127136
return session
128137
else:
129138
return Session()

tests/tests_e3/cve/cache.db

-156 KB
Binary file not shown.
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
{
2+
"created_at": "2023-03-08T11:37:29.224743",
3+
"elapsed": 1.971946,
4+
"encoding": "utf-8",
5+
"headers": {
6+
"content-type": "application/json",
7+
"content-encoding": "gzip",
8+
"vary": "Accept-Encoding",
9+
"x-frame-options": "SAMEORIGIN",
10+
"access-control-allow-origin": "*",
11+
"access-control-allow-headers": "accept, apiKey, content-type, origin, x-requested-with",
12+
"access-control-allow-methods": "GET, HEAD, OPTIONS",
13+
"access-control-allow-credentials": "false",
14+
"date": "Wed, 08 Mar 2023 11:37:29 GMT",
15+
"Content-Length": "3224",
16+
"apikey": "No",
17+
"strict-transport-security": "max-age=31536000"
18+
},
19+
"reason": "OK",
20+
"request": {
21+
"body": "",
22+
"headers": {
23+
"Accept": "*/*",
24+
"Accept-Encoding": "deflate, gzip",
25+
"Connection": "keep-alive",
26+
"User-Agent": "python-requests/2.28.2"
27+
},
28+
"method": "GET",
29+
"url": "https://services.nvd.nist.gov/rest/json/cves/2.0?cpeName=cpe:2.3:a:libpng:libpng:1.6.0:-:*:*:*:*:*:*&isVulnerable&noRejected&resultsPerPage=5&startIndex=10"
30+
},
31+
"status_code": 200,
32+
"url": "https://services.nvd.nist.gov/rest/json/cves/2.0?cpeName=cpe:2.3:a:libpng:libpng:1.6.0:-:*:*:*:*:*:*&isVulnerable&noRejected&resultsPerPage=5&startIndex=10",
33+
"_decoded_content": {
34+
"resultsPerPage": 1,
35+
"startIndex": 10,
36+
"totalResults": 11,
37+
"format": "NVD_CVE",
38+
"version": "2.0",
39+
"timestamp": "2023-03-08T11:37:29.247",
40+
"vulnerabilities": [
41+
{
42+
"cve": {
43+
"id": "CVE-2021-4214",
44+
"sourceIdentifier": "secalert@redhat.com",
45+
"published": "2022-08-24T16:15:10.037",
46+
"lastModified": "2022-11-08T02:32:10.533",
47+
"vulnStatus": "Analyzed",
48+
"descriptions": [
49+
{
50+
"lang": "en",
51+
"value": "A heap overflow flaw was found in libpngs' pngimage.c program. This flaw allows an attacker with local network access to pass a specially crafted PNG file to the pngimage utility, causing an application to crash, leading to a denial of service."
52+
},
53+
{
54+
"lang": "es",
55+
"value": "Se ha encontrado un fallo de desbordamiento de la pila en el programa pngimage.c de libpngs. Este fallo permite a un atacante con acceso a la red local pasar un archivo PNG especialmente dise\u00f1ado a la utilidad pngimage, causando un fallo en la aplicaci\u00f3n, conllevando a una denegaci\u00f3n de servicio."
56+
}
57+
],
58+
"metrics": {
59+
"cvssMetricV31": [
60+
{
61+
"source": "nvd@nist.gov",
62+
"type": "Primary",
63+
"cvssData": {
64+
"version": "3.1",
65+
"vectorString": "CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H",
66+
"attackVector": "LOCAL",
67+
"attackComplexity": "LOW",
68+
"privilegesRequired": "NONE",
69+
"userInteraction": "REQUIRED",
70+
"scope": "UNCHANGED",
71+
"confidentialityImpact": "NONE",
72+
"integrityImpact": "NONE",
73+
"availabilityImpact": "HIGH",
74+
"baseScore": 5.5,
75+
"baseSeverity": "MEDIUM"
76+
},
77+
"exploitabilityScore": 1.8,
78+
"impactScore": 3.6
79+
}
80+
]
81+
},
82+
"weaknesses": [
83+
{
84+
"source": "secalert@redhat.com",
85+
"type": "Primary",
86+
"description": [
87+
{
88+
"lang": "en",
89+
"value": "CWE-120"
90+
}
91+
]
92+
},
93+
{
94+
"source": "nvd@nist.gov",
95+
"type": "Secondary",
96+
"description": [
97+
{
98+
"lang": "en",
99+
"value": "CWE-787"
100+
}
101+
]
102+
}
103+
],
104+
"configurations": [
105+
{
106+
"nodes": [
107+
{
108+
"operator": "OR",
109+
"negate": false,
110+
"cpeMatch": [
111+
{
112+
"vulnerable": true,
113+
"criteria": "cpe:2.3:a:libpng:libpng:1.6.0:-:*:*:*:*:*:*",
114+
"matchCriteriaId": "42882881-6827-4123-B217-FC9B4C36702A"
115+
}
116+
]
117+
}
118+
]
119+
},
120+
{
121+
"nodes": [
122+
{
123+
"operator": "OR",
124+
"negate": false,
125+
"cpeMatch": [
126+
{
127+
"vulnerable": true,
128+
"criteria": "cpe:2.3:o:debian:debian_linux:10.0:*:*:*:*:*:*:*",
129+
"matchCriteriaId": "07B237A9-69A3-4A9C-9DA0-4E06BD37AE73"
130+
},
131+
{
132+
"vulnerable": true,
133+
"criteria": "cpe:2.3:o:debian:debian_linux:11.0:*:*:*:*:*:*:*",
134+
"matchCriteriaId": "FA6FEEC2-9F11-4643-8827-749718254FED"
135+
}
136+
]
137+
}
138+
]
139+
},
140+
{
141+
"nodes": [
142+
{
143+
"operator": "OR",
144+
"negate": false,
145+
"cpeMatch": [
146+
{
147+
"vulnerable": true,
148+
"criteria": "cpe:2.3:a:netapp:ontap_select_deploy_administration_utility:-:*:*:*:*:*:*:*",
149+
"matchCriteriaId": "E7CF3019-975D-40BB-A8A4-894E62BD3797"
150+
}
151+
]
152+
}
153+
]
154+
}
155+
],
156+
"references": [
157+
{
158+
"url": "https://access.redhat.com/security/cve/CVE-2021-4214",
159+
"source": "secalert@redhat.com",
160+
"tags": [
161+
"Third Party Advisory"
162+
]
163+
},
164+
{
165+
"url": "https://bugzilla.redhat.com/show_bug.cgi?id=2043393",
166+
"source": "secalert@redhat.com",
167+
"tags": [
168+
"Exploit",
169+
"Issue Tracking",
170+
"Third Party Advisory"
171+
]
172+
},
173+
{
174+
"url": "https://github.com/glennrp/libpng/issues/302",
175+
"source": "secalert@redhat.com",
176+
"tags": [
177+
"Exploit",
178+
"Third Party Advisory"
179+
]
180+
},
181+
{
182+
"url": "https://security-tracker.debian.org/tracker/CVE-2021-4214",
183+
"source": "secalert@redhat.com",
184+
"tags": [
185+
"Third Party Advisory"
186+
]
187+
},
188+
{
189+
"url": "https://security.netapp.com/advisory/ntap-20221020-0001/",
190+
"source": "secalert@redhat.com",
191+
"tags": [
192+
"Third Party Advisory"
193+
]
194+
}
195+
]
196+
}
197+
}
198+
]
199+
}
200+
}

0 commit comments

Comments
 (0)