From 61e8f9ec49430533edaeac23825f4bbc40ab4848 Mon Sep 17 00:00:00 2001 From: ziadhany Date: Wed, 29 May 2024 22:14:54 +0300 Subject: [PATCH] Change the kev model ( known_ransomware_campaign_use from integer choices to boolean ) Signed-off-by: ziadhany --- .../improvers/vulnerability_kev.py | 6 +- .../migrations/{0058_kev.py => 0057_kev.py} | 9 ++- vulnerabilities/models.py | 22 ++------ .../templates/vulnerability_details.html | 56 +++++++++---------- 4 files changed, 40 insertions(+), 53 deletions(-) rename vulnerabilities/migrations/{0058_kev.py => 0057_kev.py} (84%) diff --git a/vulnerabilities/improvers/vulnerability_kev.py b/vulnerabilities/improvers/vulnerability_kev.py index fff043e86..f29352abb 100644 --- a/vulnerabilities/improvers/vulnerability_kev.py +++ b/vulnerabilities/improvers/vulnerability_kev.py @@ -4,13 +4,11 @@ from django.db.models import QuerySet from sphinx.util import requests -from vulnerabilities.importer import AdvisoryData from vulnerabilities.improver import Improver from vulnerabilities.improver import Inference from vulnerabilities.models import Advisory from vulnerabilities.models import Alias from vulnerabilities.models import Kev -from vulnerabilities.models import KnownRansomwareCampaignUseType logger = logging.getLogger(__name__) @@ -55,9 +53,9 @@ def get_inferences(self, advisory_data) -> Iterable[Inference]: "required_action": kev_vul["requiredAction"], "due_date": kev_vul["dueDate"], "resources_and_notes": kev_vul["notes"], - "known_ransomware_campaign_use": KnownRansomwareCampaignUseType.KNOWN + "known_ransomware_campaign_use": True if kev_vul["knownRansomwareCampaignUse"] == "Known" - else KnownRansomwareCampaignUseType.UNKNOWN, + else False, }, ) return [] diff --git a/vulnerabilities/migrations/0058_kev.py b/vulnerabilities/migrations/0057_kev.py similarity index 84% rename from vulnerabilities/migrations/0058_kev.py rename to vulnerabilities/migrations/0057_kev.py index 105808091..57cb76d80 100644 --- a/vulnerabilities/migrations/0058_kev.py +++ b/vulnerabilities/migrations/0057_kev.py @@ -1,4 +1,4 @@ -# Generated by Django 4.1.13 on 2024-02-27 13:40 +# Generated by Django 4.1.13 on 2024-05-29 19:14 from django.db import migrations, models import django.db.models.deletion @@ -7,7 +7,7 @@ class Migration(migrations.Migration): dependencies = [ - ("vulnerabilities", "0057_alter_packagechangelog_software_version_and_more"), + ("vulnerabilities", "0056_alter_packagechangelog_software_version_and_more"), ] operations = [ @@ -54,7 +54,10 @@ class Migration(migrations.Migration): ), ( "known_ransomware_campaign_use", - models.IntegerField(choices=[(1, "Known"), (2, "Unknown")]), + models.BooleanField( + default=False, + help_text="Known if this vulnerability is known to have been leveraged as part of a ransomware campaign; \n or 'Unknown' if CISA lacks confirmation that the vulnerability has been utilized for ransomware.", + ), ), ( "vulnerability", diff --git a/vulnerabilities/models.py b/vulnerabilities/models.py index 2336a0712..95f45fdd2 100644 --- a/vulnerabilities/models.py +++ b/vulnerabilities/models.py @@ -1309,16 +1309,6 @@ def log_fixing(cls, package, importer, source_url, related_vulnerability): ) -class KnownRansomwareCampaignUseType(models.IntegerChoices): - """ - Known if this vulnerability is known to have been leveraged as part of a ransomware campaign; - or 'Unknown' if CISA lacks confirmation that the vulnerability has been utilized for ransomware. - """ - - KNOWN = 1, "Known" - UNKNOWN = 2, "Unknown" - - class Kev(models.Model): """ Known Exploited Vulnerabilities @@ -1358,14 +1348,12 @@ class Kev(models.Model): " often a URL to vendor instructions." ) - known_ransomware_campaign_use = models.IntegerField( - choices=KnownRansomwareCampaignUseType.choices + known_ransomware_campaign_use = models.BooleanField( + default=False, + help_text="""Known if this vulnerability is known to have been leveraged as part of a ransomware campaign; + or 'Unknown' if CISA lacks confirmation that the vulnerability has been utilized for ransomware.""", ) @property def get_known_ransomware_campaign_use_type(self): - label_by_status = { - choice_code: choice_label - for choice_code, choice_label in KnownRansomwareCampaignUseType.choices - } - return label_by_status.get(self.known_ransomware_campaign_use) + return "Known" if self.known_ransomware_campaign_use else "Unknown" diff --git a/vulnerabilities/templates/vulnerability_details.html b/vulnerabilities/templates/vulnerability_details.html index 69df938c9..2cfaacbd9 100644 --- a/vulnerabilities/templates/vulnerability_details.html +++ b/vulnerabilities/templates/vulnerability_details.html @@ -388,19 +388,16 @@ - {% if vulnerability.kev.date_added %} - - - - - {% endif %} - + + + + + {% if vulnerability.kev.description %} {% endif %} - - {% if vulnerability.kev.due_date %} + + {% if vulnerability.kev.resources_and_notes %} - + {% endif %} - - {% if vulnerability.kev.resources_and_notes %} + + {% if vulnerability.kev.due_date %} - + {% endif %} - - {% if vulnerability.kev.known_ransomware_campaign_use %} + {% if vulnerability.kev.date_added %} - + {% endif %} +
- - Date Added: - - {{ vulnerability.kev.date_added }}
+ + Known Ransomware Campaign Use: + + {{ vulnerability.kev.get_known_ransomware_campaign_use_type }}
@@ -424,42 +421,43 @@ {{ vulnerability.kev.required_action }}
- Due Date: + data-tooltip="Any additional notes about the vulnerability"> + Notes: {{ vulnerability.kev.due_date }}{{ vulnerability.kev.resources_and_notes }}
- Notes: + data-tooltip="The date the required action is due in the format YYYY-MM-DD"> + Due Date: {{ vulnerability.kev.resources_and_notes }}{{ vulnerability.kev.due_date }}
- - Known Ransomware Campaign Use: + + Date Added: {{ vulnerability.kev.get_known_ransomware_campaign_use_type }}{{ vulnerability.kev.date_added }}
{% endif %}