|
3 | 3 | from json.decoder import JSONDecodeError
|
4 | 4 |
|
5 | 5 | import cvss.parser
|
6 |
| -from cvss import CVSS2, CVSS3 |
| 6 | +from cvss import CVSS2, CVSS3, CVSS4 |
7 | 7 |
|
8 | 8 | from dojo.models import Finding
|
9 | 9 |
|
@@ -96,22 +96,32 @@ def get_findings(self, filename, test):
|
96 | 96 | cvss_vectors = cvss.parser.parse_cvss_from_text(
|
97 | 97 | vulnerability["cvssVector"],
|
98 | 98 | )
|
99 |
| - if len(cvss_vectors) > 0 and isinstance( |
100 |
| - cvss_vectors[0], CVSS3, |
101 |
| - ): |
102 |
| - # Only set finding vector if it's version 3 |
103 |
| - cvss_vector = cvss_vectors[0].clean_vector() |
104 |
| - severity = cvss_vectors[0].severities()[0] |
105 |
| - elif len(cvss_vectors) > 0 and isinstance( |
106 |
| - cvss_vectors[0], CVSS2, |
107 |
| - ): |
108 |
| - # Otherwise add it to description |
109 |
| - description = ( |
110 |
| - description |
111 |
| - + "\nCVSS V2 Vector:" |
112 |
| - + cvss_vectors[0].clean_vector() |
| 99 | + |
| 100 | + if len(cvss_vectors) > 0: |
| 101 | + vector_obj = cvss_vectors[0] |
| 102 | + |
| 103 | + if isinstance(vector_obj, CVSS4): |
| 104 | + severity = vector_obj.severities()[0] |
| 105 | + |
| 106 | + elif isinstance(vector_obj, CVSS3): |
| 107 | + cvss_vector = vector_obj.clean_vector() |
| 108 | + severity = vector_obj.severities()[0] |
| 109 | + |
| 110 | + elif isinstance(vector_obj, CVSS2): |
| 111 | + description += "\nCVSS V2 Vector:" + vector_obj.clean_vector() |
| 112 | + severity = vector_obj.severities()[0] |
| 113 | + |
| 114 | + else: |
| 115 | + raise ValueError( |
| 116 | + f"Unsupported CVSS version detected in parser: {type(vector_obj).__name__}" |
| 117 | + ) |
| 118 | + else: |
| 119 | + # Explicitly raise an error if no CVSS vectors are found, |
| 120 | + # to avoid 'NoneType' errors during severity processing later. |
| 121 | + raise ValueError( |
| 122 | + "No CVSS vectors found. Please check that parse_cvss_from_text() " \ |
| 123 | + "correctly parses the provided cvssVector." |
113 | 124 | )
|
114 |
| - severity = cvss_vectors[0].severities()[0] |
115 | 125 | else:
|
116 | 126 | # If there is no vector, calculate severity based on
|
117 | 127 | # score and CVSS V3 (AuditJS does not always include
|
|
0 commit comments