Skip to content

Commit 594038c

Browse files
committed
fix: add CVSSv4 support to auditjs parser and improve error handling
1 parent 8e7cc01 commit 594038c

File tree

1 file changed

+26
-16
lines changed

1 file changed

+26
-16
lines changed

dojo/tools/auditjs/parser.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from json.decoder import JSONDecodeError
44

55
import cvss.parser
6-
from cvss import CVSS2, CVSS3
6+
from cvss import CVSS2, CVSS3, CVSS4
77

88
from dojo.models import Finding
99

@@ -96,22 +96,32 @@ def get_findings(self, filename, test):
9696
cvss_vectors = cvss.parser.parse_cvss_from_text(
9797
vulnerability["cvssVector"],
9898
)
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."
113124
)
114-
severity = cvss_vectors[0].severities()[0]
115125
else:
116126
# If there is no vector, calculate severity based on
117127
# score and CVSS V3 (AuditJS does not always include

0 commit comments

Comments
 (0)