-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enrich observations with exploit information from cvss-bt (#2672)
* feat: enrich cvss with cvss-bt * chore: remove enriched_cvss fields * chore: fix import linter * chore: documentation (start) * chore: renaming * chore: documentation (finish) * chore: unittest for exploit enrichment * chore: more work on unittests * chore: code quality * chore: unittests shall not run settings signals task
- Loading branch information
Showing
58 changed files
with
1,083 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...pplication/commons/migrations/0015_settings_exploit_information_max_age_years_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Generated by Django 5.1.6 on 2025-03-06 04:40 | ||
|
||
import django.core.validators | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("commons", "0014_settings_feature_automatic_osv_scanning"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="settings", | ||
name="exploit_information_max_age_years", | ||
field=models.IntegerField( | ||
default=10, | ||
help_text="Maximum age of CVEs for enrichment in years", | ||
validators=[ | ||
django.core.validators.MinValueValidator(0), | ||
django.core.validators.MaxValueValidator(999999), | ||
], | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="settings", | ||
name="feature_exploit_information", | ||
field=models.BooleanField(default=True, help_text="Enable CVSS enrichment"), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,39 @@ | ||
from typing import Any | ||
|
||
import environ | ||
from django.db.models.signals import post_save | ||
from django.dispatch import receiver | ||
from huey.contrib.djhuey import db_task, lock_task | ||
|
||
from application.commons.models import Settings | ||
from application.core.models import Product | ||
from application.core.services.security_gate import check_security_gate | ||
from application.epss.models import Exploit_Information | ||
from application.epss.services.cvss_bt import ( | ||
apply_exploit_information_observations, | ||
import_cvss_bt, | ||
) | ||
|
||
|
||
@receiver(post_save, sender=Settings) | ||
def settings_post_save( # pylint: disable=unused-argument | ||
sender: Any, instance: Settings, created: bool, **kwargs: Any | ||
) -> None: | ||
# parameters are needed according to Django documentation | ||
env = environ.Env() | ||
if not env.bool("SO_UNITTESTS", False): | ||
settings_post_save_task(instance, created) | ||
|
||
|
||
@db_task() | ||
@lock_task("settings_post_save_task_lock") | ||
def settings_post_save_task(settings: Settings, created: bool) -> None: | ||
for product in Product.objects.filter(is_product_group=False): | ||
check_security_gate(product) | ||
|
||
if not created: | ||
if settings.feature_exploit_information and not Exploit_Information.objects.exists(): | ||
import_cvss_bt() | ||
if not settings.feature_exploit_information and Exploit_Information.objects.exists(): | ||
Exploit_Information.objects.all().delete() | ||
apply_exploit_information_observations(settings) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
backend/application/core/migrations/0061_observation_cve_found_in_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.1.6 on 2025-03-04 05:07 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("core", "0060_product_automatic_osv_scanning_enabled"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="observation", | ||
name="cve_found_in", | ||
field=models.CharField(blank=True, max_length=255), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.