|
10 | 10 | from pathlib import Path |
11 | 11 | from uuid import uuid4 |
12 | 12 |
|
| 13 | +import cvss.parser |
13 | 14 | import dateutil |
14 | 15 | import hyperlink |
15 | 16 | import tagulous.admin |
16 | 17 | from auditlog.registry import auditlog |
17 | | -from cvss import CVSS3 |
18 | 18 | from dateutil.relativedelta import relativedelta |
19 | 19 | from django import forms |
20 | 20 | from django.conf import settings |
@@ -2333,8 +2333,6 @@ class Finding(models.Model): |
2333 | 2333 | verbose_name=_("EPSS percentile"), |
2334 | 2334 | help_text=_("EPSS percentile for the CVE. Describes how many CVEs are scored at or below this one."), |
2335 | 2335 | validators=[MinValueValidator(0.0), MaxValueValidator(1.0)]) |
2336 | | - # cvssv3_regex = RegexValidator(regex=r"^AV:[NALP]|AC:[LH]|PR:[UNLH]|UI:[NR]|S:[UC]|[CIA]:[NLH]", message="CVSS must be entered in format: 'AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H'") |
2337 | | - # cvssv3 = models.TextField(validators=[cvssv3_regex], |
2338 | 2336 | cvssv3 = models.TextField(validators=[cvss3_validator], |
2339 | 2337 | max_length=117, |
2340 | 2338 | null=True, |
@@ -2702,11 +2700,12 @@ def save(self, dedupe_option=True, rules_option=True, product_grading_option=Tru |
2702 | 2700 | # Synchronize cvssv3 score using cvssv3 vector |
2703 | 2701 | if self.cvssv3: |
2704 | 2702 | try: |
2705 | | - cvss_object = CVSS3(self.cvssv3) |
| 2703 | + cvss_vector = cvss.parser.parse_cvss_from_text(self.cvssv3) |
2706 | 2704 | # use the environmental score, which is the most refined score |
2707 | | - self.cvssv3_score = cvss_object.scores()[2] |
| 2705 | + self.cvssv3_score = cvss_vector.scores()[2] |
2708 | 2706 | except Exception as ex: |
2709 | | - logger.error("Can't compute cvssv3 score for finding id %i. Invalid cvssv3 vector found: '%s'. Exception: %s", self.id, self.cvssv3, ex) |
| 2707 | + logger.warning("Can't compute cvssv3 score for finding id %i. Invalid cvssv3 vector found: '%s'. Exception: %s.", self.id, self.cvssv3, ex) |
| 2708 | + # should we set self.cvssv3 to None here to avoid storing invalid vectors? it would also remove invalid vectors on existing findings... |
2710 | 2709 |
|
2711 | 2710 | self.set_hash_code(dedupe_option) |
2712 | 2711 |
|
@@ -3519,8 +3518,6 @@ class Finding_Template(models.Model): |
3519 | 3518 | blank=False, |
3520 | 3519 | verbose_name="Vulnerability Id", |
3521 | 3520 | help_text="An id of a vulnerability in a security advisory associated with this finding. Can be a Common Vulnerabilities and Exposures (CVE) or from other sources.") |
3522 | | - # cvssv3_regex = RegexValidator(regex=r"^AV:[NALP]|AC:[LH]|PR:[UNLH]|UI:[NR]|S:[UC]|[CIA]:[NLH]", message="CVSS must be entered in format: 'AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H'") |
3523 | | - # cvssv3 = models.TextField(validators=[cvssv3_regex], max_length=117, null=True) |
3524 | 3521 | cvssv3 = models.TextField(help_text=_("Common Vulnerability Scoring System version 3 (CVSSv3) score associated with this finding."), validators=[cvss3_validator], max_length=117, null=True, verbose_name=_("CVSS v3 vector")) |
3525 | 3522 |
|
3526 | 3523 | severity = models.CharField(max_length=200, null=True, blank=True) |
|
0 commit comments