Skip to content

Commit 20fd784

Browse files
committed
Refactor rockylinux importer
- Modified the severity score collection. - Refined docstrings Signed-off-by: ambuj <[email protected]>
1 parent 445b29c commit 20fd784

File tree

3 files changed

+711
-742
lines changed

3 files changed

+711
-742
lines changed

vulnerabilities/importers/rockylinux.py

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,40 +81,55 @@ def to_advisory(advisory_data):
8181
8282
Example:
8383
>>> advisory_data = {
84-
... "name": "CVE-2023-1234",
85-
... "publishedAt": "2023-08-20T12:34:56Z",
86-
... "description": "A vulnerability in the system.",
87-
... "affectedProducts": ["product1"],
84+
... "name": "RLSA-2021:4364",
85+
... "publishedAt": "2021-11-09T09:11:20Z",
86+
... "description": "The binutils packages provide a collection of binary utilities for the manipulation",
87+
... "affectedProducts": ["Rocky Linux 8"],
8888
... "rpms": {
89-
... "product1": {
89+
... "Rocky Linux 8": {
9090
... "nvras": [
91-
... "package-1.0-1.el8.x86_64.rpm",
92-
... "package-2.0-1.el8.noarch.rpm"
91+
... "gfs2-utils-0:3.2.0-11.el8.aarch64.rpm",
92+
... "gfs2-utils-0:3.2.0-11.el8.src.rpm",
93+
... "gfs2-utils-0:3.2.0-11.el8.x86_64.rpm",
94+
... "gfs2-utils-debuginfo-0:3.2.0-11.el8.aarch64.rpm",
95+
... "gfs2-utils-debuginfo-0:3.2.0-11.el8.x86_64.rpm",
96+
... "gfs2-utils-debugsource-0:3.2.0-11.el8.aarch64.rpm",
97+
... "gfs2-utils-debugsource-0:3.2.0-11.el8.x86_64.rpm"
9398
... ]
9499
... }
95100
... },
96101
... "fixes": [
97-
... {"sourceLink": "http://example.com/fix", "ticket": "12345"}
102+
... {
103+
... "ticket": "1942434",
104+
... "sourceBy": "Red Hat",
105+
... "sourceLink": "https://bugzilla.redhat.com/show_bug.cgi?id=1942434",
106+
... "description": ""
107+
... }
98108
... ],
99109
... "cves": [
100110
... {
101-
... "name": "CVE-2023-1234",
102-
... "cvss3BaseScore": "7.5",
103-
... "cvss3ScoringVector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H",
104-
... "sourceLink": "http://example.com/cve"
111+
... "name": "CVE-2021-3487",
112+
... "sourceBy": "MITRE",
113+
... "sourceLink": "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2021-3487",
114+
... "cvss3ScoringVector": "CVSS:3.1/AV:N/AC:L/PR:L/UI:N/S:U/C:N/I:N/A:H",
115+
... "cvss3BaseScore": "6.5",
116+
... "cwe": "CWE-20->CWE-400"
105117
... }
106118
... ]
107119
... }
108120
>>> advisory = to_advisory(advisory_data)
109121
>>> advisory.aliases
110-
'CVE-2023-1234'
122+
'RLSA-2021:4364'
111123
>>> advisory.date_published.year
112-
2023
124+
2021
113125
>>> len(advisory.affected_packages)
114-
2
126+
7
115127
>>> len(advisory.references)
116128
2
129+
>>> advisory.weaknesses
130+
[400, 20]
117131
"""
132+
118133
aliases = advisory_data.get("name") or ""
119134
date_published = dateparser.parse(advisory_data.get("publishedAt", ""))
120135

@@ -162,20 +177,15 @@ def to_advisory(advisory_data):
162177
continue
163178

164179
if "CVE" in name.upper():
165-
severity_vector_pattern = r"CVSS:3\.1/([A-Z:/]+)"
166180
severities = VulnerabilitySeverity(
167181
system=severity_systems.CVSSV31,
168182
value=ref.get("cvss3BaseScore", ""),
169-
scoring_elements=re.findall(
170-
severity_vector_pattern, ref.get("cvss3ScoringVector", "")
171-
),
183+
scoring_elements=ref.get("cvss3ScoringVector", "")
184+
if ref.get("cvss3ScoringVector", "") != "UNKNOWN"
185+
else "",
172186
)
173187
references.append(
174-
Reference(
175-
severities=[severities],
176-
url=ref.get("sourceLink", ""),
177-
reference_id=name,
178-
)
188+
Reference(severities=[severities], url=ref.get("sourceLink", ""), reference_id=name)
179189
)
180190

181191
return AdvisoryData(
@@ -223,11 +233,11 @@ def get_cwes_from_rockylinux_advisory(advisory_data) -> [int]:
223233
... "sourceLink": "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-43548",
224234
... "cvss3ScoringVector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:N",
225235
... "cvss3BaseScore": "7.5",
226-
... "cwe": "CWE-350"
236+
... "cwe": "CWE-20 -> CWE-400"
227237
... }
228238
... ]}
229239
>>> get_cwes_from_rockylinux_advisory(advisory_data)
230-
[1321, 400, 350]
240+
[400, 1321, 20]
231241
>>> get_cwes_from_rockylinux_advisory({"cves": [{"name": "CVE-1234-1234","cwe": "None"}]})
232242
[]
233243
"""
@@ -247,4 +257,5 @@ def get_cwes_from_rockylinux_advisory(advisory_data) -> [int]:
247257
weaknesses.append(cwe_id)
248258
except ValueError:
249259
logger.error("Invalid CWE id")
250-
return weaknesses
260+
unique_set = set(weaknesses)
261+
return list(unique_set)

0 commit comments

Comments
 (0)