Skip to content

Commit 9395cef

Browse files
cvss4: remove no longer needed custom parsing
1 parent 81be250 commit 9395cef

1 file changed

Lines changed: 4 additions & 36 deletions

File tree

dojo/utils.py

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
from auditlog.models import LogEntry
2222
from cryptography.hazmat.backends import default_backend
2323
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
24-
from cvss import CVSS2, CVSS3, CVSS4, CVSSError
24+
from cvss import CVSS2, CVSS3, CVSS4
25+
from cvss import parse_cvss_from_text as cvss_parse_cvss_from_text
2526
from dateutil.parser import parse
2627
from dateutil.relativedelta import MO, SU, relativedelta
2728
from django.conf import settings
@@ -2660,42 +2661,9 @@ def generate_file_response_from_file_path(
26602661
return response
26612662

26622663

2663-
# TEMPORARY: Local implementation until the upstream PR is merged & released: https://github.com/RedHatProductSecurity/cvss/pull/75
2664+
# used to add some custom logic, but that's now present in cvss 3.6. might be good to retain our own wrapper just in case/for now
26642665
def parse_cvss_from_text(text):
2665-
"""
2666-
Parses CVSS2, CVSS3, and CVSS4 vectors from arbitrary text and returns a list of CVSS objects.
2667-
2668-
Parses text for substrings that look similar to CVSS vector
2669-
and feeds these matches to CVSS constructor.
2670-
2671-
Args:
2672-
text (str): arbitrary text
2673-
2674-
Returns:
2675-
A list of CVSS objects.
2676-
2677-
"""
2678-
# Looks for substrings that resemble CVSS2, CVSS3, or CVSS4 vectors.
2679-
# CVSS3 and CVSS4 vectors start with a 'CVSS:x.x/' prefix and are matched by the optional non-capturing group.
2680-
# CVSS2 vectors do not include a prefix and are matched by raw vector pattern only.
2681-
# Minimum total match length is 26 characters to reduce false positives.
2682-
matches = re.compile(r"(?:CVSS:[3-4]\.\d/)?[A-Za-z:/]{26,}").findall(text)
2683-
2684-
cvsss = set()
2685-
for match in matches:
2686-
try:
2687-
if match.startswith("CVSS:4."):
2688-
cvss = CVSS4(match)
2689-
elif match.startswith("CVSS:3."):
2690-
cvss = CVSS3(match)
2691-
else:
2692-
cvss = CVSS2(match)
2693-
2694-
cvsss.add(cvss)
2695-
except (CVSSError, KeyError):
2696-
pass
2697-
2698-
return list(cvsss)
2666+
return cvss_parse_cvss_from_text(text)
26992667

27002668

27012669
def parse_cvss_data(cvss_vector_string: str) -> dict:

0 commit comments

Comments
 (0)