Skip to content

Commit dcd5d70

Browse files
committed
Use advisory related aliases to compare conflicting advisories
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 322c966 commit dcd5d70

File tree

3 files changed

+37
-15
lines changed

3 files changed

+37
-15
lines changed

vulnerabilities/migrations/0093_advisorytodo.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 4.2.20 on 2025-06-03 17:36
1+
# Generated by Django 4.2.20 on 2025-06-03 18:13
22

33
from django.db import migrations, models
44

@@ -59,7 +59,10 @@ class Migration(migrations.Migration):
5959
max_length=50,
6060
),
6161
),
62-
("issue_detail", models.TextField(help_text="Additional details about the issue.")),
62+
(
63+
"issue_detail",
64+
models.TextField(blank=True, help_text="Additional details about the issue."),
65+
),
6366
(
6467
"created_at",
6568
models.DateTimeField(
@@ -76,12 +79,16 @@ class Migration(migrations.Migration):
7679
(
7780
"resolved_at",
7881
models.DateTimeField(
79-
help_text="Timestamp indicating when this TODO was resolved."
82+
blank=True,
83+
help_text="Timestamp indicating when this TODO was resolved.",
84+
null=True,
8085
),
8186
),
8287
(
8388
"resolution_detail",
84-
models.TextField(help_text="Additional detail on how this TODO was resolved."),
89+
models.TextField(
90+
blank=True, help_text="Additional detail on how this TODO was resolved."
91+
),
8592
),
8693
(
8794
"advisories",

vulnerabilities/models.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,6 +2301,7 @@ class AdvisoryToDo(models.Model):
23012301
)
23022302

23032303
issue_detail = models.TextField(
2304+
blank=True,
23042305
help_text="Additional details about the issue.",
23052306
)
23062307

@@ -2322,12 +2323,19 @@ class AdvisoryToDo(models.Model):
23222323
)
23232324

23242325
resolved_at = models.DateTimeField(
2326+
null=True,
2327+
blank=True,
23252328
help_text="Timestamp indicating when this TODO was resolved.",
23262329
)
23272330

23282331
resolution_detail = models.TextField(
2332+
blank=True,
23292333
help_text="Additional detail on how this TODO was resolved.",
23302334
)
23312335

23322336
class Meta:
23332337
unique_together = ("related_advisories_id", "issue_type")
2338+
2339+
def save(self, *args, **kwargs):
2340+
self.full_clean()
2341+
return super().save(*args, **kwargs)

vulnerabilities/pipelines/compute_advisory_todo.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def steps(cls):
3131
)
3232

3333
def compute_individual_advisory_todo(self):
34-
advisories = Advisory.objects.all().paginated()
34+
advisories = Advisory.objects.all().iterator(chunk_size=2000)
3535
advisories_count = Advisory.objects.all().count()
3636

3737
self.log(
@@ -62,10 +62,14 @@ def detect_conflicting_advisories(self):
6262

6363
self.log(f"Cross validating advisory affected and fixed package for {aliases_count} CVEs")
6464

65-
progress = LoopProgress(total_iterations=aliases_count, logger=self.log)
66-
for alias in progress.iter(aliases.paginated()):
65+
progress = LoopProgress(
66+
total_iterations=aliases_count,
67+
logger=self.log,
68+
progress_step=1,
69+
)
70+
for alias in progress.iter(aliases.iterator(chunk_size=2000)):
6771
advisories = (
68-
Advisory.objects.filter(aliases__contains=alias.alias)
72+
Advisory.objects.filter(aliases__in=aliases)
6973
.exclude(advisory_todos__issue_type="MISSING_AFFECTED_AND_FIXED_BY_PACKAGES")
7074
.distinct()
7175
)
@@ -87,9 +91,8 @@ def detect_conflicting_advisories(self):
8791
def check_missing_summary(advisory, todo_id, logger=None):
8892
if not advisory.summary:
8993
todo, created = AdvisoryToDo.objects.get_or_create(
90-
unique_todo_id=todo_id,
94+
related_advisories_id=todo_id,
9195
issue_type="MISSING_SUMMARY",
92-
issue_detail="",
9396
)
9497
if created:
9598
todo.advisories.add(advisory)
@@ -107,6 +110,9 @@ def check_missing_affected_and_fixed_by_packages(advisory, todo_id, logger=None)
107110
has_affected_package = False
108111
has_fixed_package = False
109112
for affected in advisory.to_advisory_data().affected_packages or []:
113+
if not affected:
114+
continue
115+
110116
if has_affected_package and has_fixed_package:
111117
break
112118
if not has_affected_package and affected.affected_version_range:
@@ -121,12 +127,11 @@ def check_missing_affected_and_fixed_by_packages(advisory, todo_id, logger=None)
121127
issue_type = "MISSING_AFFECTED_AND_FIXED_BY_PACKAGES"
122128
elif not has_affected_package:
123129
issue_type = "MISSING_AFFECTED_PACKAGE"
124-
elif has_fixed_package:
130+
elif not has_fixed_package:
125131
issue_type = "MISSING_FIXED_BY_PACKAGE"
126132
todo, created = AdvisoryToDo.objects.get_or_create(
127-
unique_todo_id=todo_id,
133+
related_advisories_id=todo_id,
128134
issue_type=issue_type,
129-
issue_detail="",
130135
)
131136
if created:
132137
todo.advisories.add(advisory)
@@ -246,9 +251,11 @@ def check_conflicting_affected_and_fixed_by_packages(
246251

247252
todo_id = advisories_checksum(advisories)
248253
todo, created = AdvisoryToDo.objects.get_or_create(
249-
unique_todo_id=todo_id,
254+
related_advisories_id=todo_id,
250255
issue_type=issue_type,
251-
issue_detail="\n".join(messages),
256+
defaults={
257+
"issue_details": "\n".join(messages),
258+
},
252259
)
253260
if created:
254261
todo.advisories.add(*advisories)

0 commit comments

Comments
 (0)