|
21 | 21 | from auditlog.models import LogEntry |
22 | 22 | from cryptography.hazmat.backends import default_backend |
23 | 23 | 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 |
25 | 26 | from dateutil.parser import parse |
26 | 27 | from dateutil.relativedelta import MO, SU, relativedelta |
27 | 28 | from django.conf import settings |
@@ -2660,42 +2661,9 @@ def generate_file_response_from_file_path( |
2660 | 2661 | return response |
2661 | 2662 |
|
2662 | 2663 |
|
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 |
2664 | 2665 | 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) |
2699 | 2667 |
|
2700 | 2668 |
|
2701 | 2669 | def parse_cvss_data(cvss_vector_string: str) -> dict: |
|
0 commit comments