|
19 | 19 | from rich.tree import Tree
|
20 | 20 | from vdb.lib import CPE_FULL_REGEX
|
21 | 21 | from vdb.lib.config import placeholder_exclude_version, placeholder_fix_version
|
22 |
| -from vdb.lib.utils import parse_cpe, parse_purl |
| 22 | +from vdb.lib.utils import get_cvss3_from_vector, get_cvss4_from_vector, parse_cpe, parse_purl |
23 | 23 |
|
24 | 24 | from depscan.lib import config
|
25 | 25 | from depscan.lib.logger import LOG, console
|
@@ -336,6 +336,11 @@ def prepare_vdr(options: PrepareVdrOptions):
|
336 | 336 | justify = "right"
|
337 | 337 | table.add_column(header=h, justify=justify, vertical="top")
|
338 | 338 | for vuln_occ_dict in options.results:
|
| 339 | + # If CVSS v4 data is available, override the severity and cvss_score |
| 340 | + if vuln_occ_dict.get("cvss4_vector_string"): |
| 341 | + cvss4_obj = get_cvss4_from_vector(vuln_occ_dict.get("cvss4_vector_string")) |
| 342 | + vuln_occ_dict["cvss_score"] = cvss4_obj.get("baseScore") |
| 343 | + vuln_occ_dict["severity"] = cvss4_obj.get("baseSeverity").upper() |
339 | 344 | vid = vuln_occ_dict.get("id")
|
340 | 345 | problem_type = vuln_occ_dict.get("problem_type")
|
341 | 346 | cwes = []
|
@@ -1026,34 +1031,33 @@ def cvss_to_vdr_rating(vuln_occ_dict):
|
1026 | 1031 |
|
1027 | 1032 | :return: A list containing a dictionary with CVSS score information.
|
1028 | 1033 | """
|
1029 |
| - cvss_score = vuln_occ_dict.get("cvss_score", 2.0) |
1030 |
| - with contextlib.suppress(ValueError, TypeError): |
1031 |
| - cvss_score = float(cvss_score) |
1032 |
| - if (pkg_severity := vuln_occ_dict.get("severity", "").lower()) not in ( |
1033 |
| - "critical", |
1034 |
| - "high", |
1035 |
| - "medium", |
1036 |
| - "low", |
1037 |
| - "info", |
1038 |
| - "none", |
1039 |
| - ): |
1040 |
| - pkg_severity = "unknown" |
1041 |
| - ratings = [ |
1042 |
| - { |
1043 |
| - "score": cvss_score, |
1044 |
| - "severity": pkg_severity, |
1045 |
| - } |
1046 |
| - ] |
1047 |
| - method = "31" |
| 1034 | + ratings = [] |
| 1035 | + # Support for cvss v4 |
| 1036 | + if vuln_occ_dict.get("cvss4_vector_string") and (vector_string := vuln_occ_dict.get("cvss4_vector_string")): |
| 1037 | + cvss4_obj = get_cvss4_from_vector(vector_string) |
| 1038 | + ratings.append( |
| 1039 | + { |
| 1040 | + "method": "CVSSv4", |
| 1041 | + "score": cvss4_obj.get("baseScore"), |
| 1042 | + "severity": cvss4_obj.get("baseSeverity").lower(), |
| 1043 | + "vector": vector_string |
| 1044 | + } |
| 1045 | + ) |
1048 | 1046 | if vuln_occ_dict.get("cvss_v3") and (
|
1049 | 1047 | vector_string := vuln_occ_dict["cvss_v3"].get("vector_string")
|
1050 | 1048 | ):
|
1051 |
| - ratings[0]["vector"] = vector_string |
1052 | 1049 | with contextlib.suppress(CVSSError):
|
1053 |
| - method = cvss.CVSS3(vector_string).as_json().get("version") |
| 1050 | + cvss3_obj = get_cvss3_from_vector(vector_string) |
| 1051 | + method = cvss3_obj.get("version") |
1054 | 1052 | method = method.replace(".", "").replace("0", "")
|
1055 |
| - ratings[0]["method"] = f"CVSSv{method}" |
1056 |
| - |
| 1053 | + ratings.append( |
| 1054 | + { |
| 1055 | + "method": f"CVSSv{method}", |
| 1056 | + "score": cvss3_obj.get("baseScore"), |
| 1057 | + "severity": cvss3_obj.get("baseSeverity").lower(), |
| 1058 | + "vector": vector_string |
| 1059 | + } |
| 1060 | + ) |
1057 | 1061 | return ratings
|
1058 | 1062 |
|
1059 | 1063 |
|
|
0 commit comments