|
13 | 13 |
|
14 | 14 | import requests
|
15 | 15 | from bs4 import BeautifulSoup
|
16 |
| -from cwe2.database import Database |
17 | 16 | from packageurl import PackageURL
|
18 | 17 | from univers.version_constraint import VersionConstraint
|
19 | 18 | from univers.version_range import ApacheVersionRange
|
|
25 | 24 | from vulnerabilities.importer import Reference
|
26 | 25 | from vulnerabilities.importer import VulnerabilitySeverity
|
27 | 26 | from vulnerabilities.severity_systems import APACHE_HTTPD
|
28 |
| -from vulnerabilities.utils import get_cwe_id |
| 27 | +from vulnerabilities.utils import create_weaknesses_list |
| 28 | +from vulnerabilities.utils import cwe_regex |
29 | 29 | from vulnerabilities.utils import get_item
|
30 | 30 |
|
31 | 31 | logger = logging.getLogger(__name__)
|
@@ -234,33 +234,21 @@ def get_weaknesses(cve_data):
|
234 | 234 | >>> get_weaknesses(mock_cve_data2)
|
235 | 235 | [190, 200]
|
236 | 236 | """
|
237 |
| - |
238 | 237 | alias = get_item(cve_data, "CVE_data_meta", "ID")
|
239 |
| - cwe_id = [] |
240 |
| - db = Database() |
| 238 | + cwe_strings = [] |
241 | 239 | if alias:
|
242 | 240 | problemtype_data = get_item(cve_data, "problemtype", "problemtype_data") or []
|
243 | 241 | for problem in problemtype_data:
|
244 |
| - for desc in problem["description"]: |
| 242 | + for desc in problem.get("description", []): |
245 | 243 | value = desc.get("value", "")
|
246 |
| - cwe_pattern = r"CWE-\d+" |
247 |
| - cwe_id_string_list = re.findall(cwe_pattern, value) |
248 |
| - for cwe_id_string in cwe_id_string_list: |
249 |
| - cwe_id.append(get_cwe_id(cwe_id_string)) |
250 |
| - |
| 244 | + cwe_id_string_list = re.findall(cwe_regex, value) |
| 245 | + cwe_strings.extend(cwe_id_string_list) |
251 | 246 | else:
|
252 | 247 | problemTypes = cve_data.get("containers", {}).get("cna", {}).get("problemTypes", [])
|
253 | 248 | descriptions = problemTypes[0].get("descriptions", []) if len(problemTypes) > 0 else []
|
254 | 249 | for description in descriptions:
|
255 | 250 | cwe_id_string = description.get("cweId", "")
|
256 |
| - cwe_id.append(get_cwe_id(cwe_id_string)) |
257 |
| - |
258 |
| - weaknesses = [] |
259 |
| - for cwe in cwe_id: |
260 |
| - try: |
261 |
| - db.get(cwe) |
262 |
| - weaknesses.append(cwe) |
263 |
| - except Exception: |
264 |
| - logger.error("Invalid CWE id") |
| 251 | + cwe_strings.append(cwe_id_string) |
265 | 252 |
|
| 253 | + weaknesses = create_weaknesses_list(cwe_strings) |
266 | 254 | return weaknesses
|
0 commit comments