|
15 | 15 |
|
16 | 16 | import bleach |
17 | 17 | import crum |
| 18 | +import cvss |
18 | 19 | import hyperlink |
19 | 20 | import vobject |
20 | 21 | from asteval import Interpreter |
21 | 22 | from auditlog.models import LogEntry |
22 | 23 | from cryptography.hazmat.backends import default_backend |
23 | 24 | from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes |
24 | | -from cvss import CVSS2, CVSS3, CVSS4, CVSSError |
| 25 | +from cvss import CVSS2, CVSS3, CVSS4 |
25 | 26 | from dateutil.parser import parse |
26 | 27 | from dateutil.relativedelta import MO, SU, relativedelta |
27 | 28 | from django.conf import settings |
@@ -2660,49 +2661,11 @@ 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 | | -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) |
2699 | | - |
2700 | | - |
2701 | 2664 | def parse_cvss_data(cvss_vector_string: str) -> dict: |
2702 | 2665 | if not cvss_vector_string: |
2703 | 2666 | return {} |
2704 | 2667 |
|
2705 | | - vectors = parse_cvss_from_text(cvss_vector_string) |
| 2668 | + vectors = cvss.parser.parse_cvss_from_text(cvss_vector_string) |
2706 | 2669 | if len(vectors) > 0: |
2707 | 2670 | vector = vectors[0] |
2708 | 2671 | # For CVSS2, environmental score is at index 2 |
|
0 commit comments