Skip to content

Commit 1ddd585

Browse files
committed
wip
Signed-off-by: Keshav Priyadarshi <git@keshav.space>
1 parent 4ab8b2f commit 1ddd585

File tree

15 files changed

+73
-13
lines changed

15 files changed

+73
-13
lines changed

vulnerabilities/importers/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
from vulnerabilities.importers import ubuntu_usn
3333
from vulnerabilities.importers import vulnrichment
3434
from vulnerabilities.importers import xen
35+
from vulnerabilities.pipelines import VulnerableCodeBaseImporterPipelineV2
3536
from vulnerabilities.pipelines import alpine_linux_importer
3637
from vulnerabilities.pipelines import github_importer
3738
from vulnerabilities.pipelines import gitlab_importer
@@ -189,3 +190,9 @@
189190
collect_fix_commits_v2.CollectGitlabFixCommitsPipeline,
190191
]
191192
)
193+
194+
TODO_EXCLUDED_PIPELINES = [
195+
key
196+
for key, value in IMPORTERS_REGISTRY.items()
197+
if issubclass(value, VulnerableCodeBaseImporterPipelineV2) and value.exclude_from_package_todo
198+
]

vulnerabilities/models.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,9 +1139,9 @@ def get_affecting_vulnerabilities(self):
11391139
next_fixed_package_vulns = list(fixed_by_pkg.affected_by)
11401140

11411141
fixed_by_package_details["fixed_by_purl"] = fixed_by_purl
1142-
fixed_by_package_details["fixed_by_purl_vulnerabilities"] = (
1143-
next_fixed_package_vulns
1144-
)
1142+
fixed_by_package_details[
1143+
"fixed_by_purl_vulnerabilities"
1144+
] = next_fixed_package_vulns
11451145
fixed_by_pkgs.append(fixed_by_package_details)
11461146

11471147
vuln_details["fixed_by_package_details"] = fixed_by_pkgs
@@ -2865,11 +2865,7 @@ def latest_for_avid(self, avid: str):
28652865
)
28662866

28672867
def latest_per_avid(self):
2868-
return self.order_by(
2869-
"avid",
2870-
F("date_collected").desc(nulls_last=True),
2871-
"-id",
2872-
).distinct("avid")
2868+
return self.filter(is_latest=True)
28732869

28742870
def latest_for_avids(self, avids):
28752871
return self.filter(avid__in=avids).latest_per_avid()
@@ -2941,6 +2937,12 @@ def latest_advisories_for_purl(self, purl):
29412937
qs = self.filter(id__in=Subquery(adv_ids))
29422938
return qs.latest_per_avid()
29432939

2940+
def todo_excluded(self):
2941+
"""Exclude advisory ineligible for ToDo computation."""
2942+
from vulnerabilities.importers import TODO_EXCLUDED_PIPELINES
2943+
2944+
return self.exclude(datasource_id__in=TODO_EXCLUDED_PIPELINES)
2945+
29442946

29452947
class AdvisorySet(models.Model):
29462948

@@ -2986,6 +2988,7 @@ class AdvisoryV2(models.Model):
29862988
max_length=200,
29872989
blank=False,
29882990
null=False,
2991+
db_index=True,
29892992
help_text="Unique ID for the datasource used for this advisory ." "e.g.: nginx_importer_v2",
29902993
)
29912994

@@ -3069,6 +3072,14 @@ class AdvisoryV2(models.Model):
30693072
help_text="UTC Date on which the advisory was collected",
30703073
)
30713074

3075+
is_latest = models.BooleanField(
3076+
default=False,
3077+
blank=False,
3078+
null=False,
3079+
db_index=True,
3080+
help_text="Indicates whether this is the latest version of the advisory identified by its AVID.",
3081+
)
3082+
30723083
original_advisory_text = models.TextField(
30733084
blank=True,
30743085
null=True,
@@ -3121,6 +3132,11 @@ class AdvisoryV2(models.Model):
31213132
class Meta:
31223133
unique_together = ["datasource_id", "advisory_id", "unique_content_id"]
31233134
ordering = ["datasource_id", "advisory_id", "date_published", "unique_content_id"]
3135+
constraints = [
3136+
models.UniqueConstraint(
3137+
fields=["avid"], condition=Q(is_latest=True), name="unique_latest_per_avid"
3138+
)
3139+
]
31243140
indexes = [
31253141
models.Index(
31263142
fields=["avid", "-date_collected", "-id"],

vulnerabilities/pipelines/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ class VulnerableCodeBaseImporterPipelineV2(VulnerableCodePipeline):
271271
ignorable_versions = []
272272
precedence = 0
273273

274+
# Set this to True if computing fixed/affected package ToDo is not fruitful for this source.
275+
# An example of such advisory would be pipeline dedicated to collecting issues,
276+
# pull requests, commit messages, EPSS, exploits, etc.
277+
exclude_from_package_todo = False
278+
274279
# Control how often progress log is shown (range: 1–100, higher value = less frequent log)
275280
progress_step = 10
276281

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#
2+
# Copyright (c) nexB Inc. and others. All rights reserved.
3+
# VulnerableCode is a trademark of nexB Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# See http://www.apache.org/licenses/LICENSE-2.0 for the license text.
6+
# See https://github.com/aboutcode-org/vulnerablecode for support or download.
7+
# See https://aboutcode.org for more information about nexB OSS projects.
8+
#

vulnerabilities/pipelines/v2_importers/aosp_importer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class AospImporterPipeline(VulnerableCodeBaseImporterPipelineV2):
3232
license_url = "https://github.com/quarkslab/aosp_dataset/blob/master/LICENSE"
3333

3434
precedence = 200
35+
exclude_from_package_todo = True
3536

3637
@classmethod
3738
def steps(cls):

vulnerabilities/pipelines/v2_importers/epss_importer_v2.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class EPSSImporterPipeline(VulnerableCodeBaseImporterPipelineV2):
3030
spdx_license_expression = "unknown"
3131
importer_name = "EPSS Importer"
3232

33+
exclude_from_package_todo = True
34+
3335
precedence = 200
3436

3537
def advisories_count(self):

vulnerabilities/pipelines/v2_importers/nvd_importer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class NVDImporterPipeline(VulnerableCodeBaseImporterPipelineV2):
7171
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
7272
"""
7373

74+
exclude_from_package_todo = True
75+
7476
precedence = 100
7577

7678
@classmethod

vulnerabilities/pipelines/v2_importers/project_kb_msr2019_importer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ class ProjectKBMSR2019Pipeline(VulnerableCodeBaseImporterPipelineV2):
3030
license_url = "https://github.com/SAP/project-kb/blob/main/LICENSE.txt"
3131
repo_url = "git+https://github.com/SAP/project-kb"
3232

33+
exclude_from_package_todo = True
34+
3335
precedence = 200
3436

3537
@classmethod

vulnerabilities/pipelines/v2_importers/project_kb_statements_importer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class ProjectKBStatementsPipeline(VulnerableCodeBaseImporterPipelineV2):
3737
license_url = "https://github.com/SAP/project-kb/blob/main/LICENSE.txt"
3838
repo_url = "git+https://github.com/SAP/project-kb@vulnerability-data"
3939

40+
exclude_from_package_todo = True
41+
4042
precedence = 200
4143

4244
@classmethod

vulnerabilities/pipelines/v2_importers/suse_score_importer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class SUSESeverityScoreImporterPipeline(VulnerableCodeBaseImporterPipelineV2):
2323
pipeline_id = "suse_importer_v2"
2424
url = "https://ftp.suse.com/pub/projects/security/yaml/suse-cvss-scores.yaml"
2525

26+
exclude_from_package_todo = True
27+
2628
@classmethod
2729
def steps(cls):
2830
return (

0 commit comments

Comments
 (0)