-
Notifications
You must be signed in to change notification settings - Fork 216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fillup missing vulnerabilities summary #1767
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Tushar Goel <tushar.goel.dav@gmail.com>
9557b88
to
f4140cd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some feedback.
created_by="nvd_importer", summary__isnull=False | ||
).exclude(summary="") | ||
self.log( | ||
f"Found {nvd_importer_advisories.count()} advisories from NVD importer", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f"Found {nvd_importer_advisories.count()} advisories from NVD importer", | |
f"Found {nvd_importer_advisories.count()} advisories with summaries from NVD importer", |
matching_advisories = nvd_importer_advisories.filter(Q(aliases__contains=alias)) | ||
|
||
if matching_advisories.exists(): | ||
# Take the first matching advisory with a summary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# Take the first matching advisory with a summary | |
# Take the first matching advisory with a summary. | |
# NVD advisories only have one alias, always a CVE |
if matching_advisories.exists(): | ||
# Take the first matching advisory with a summary | ||
best_advisory = matching_advisories.first() | ||
vulnerability.summary = best_advisory.summary |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vulnerability.summary = best_advisory.summary | |
# Note: we filtered above to only get non-empty summaries | |
vulnerability.summary = best_advisory.summary |
|
||
if matching_advisories.exists(): | ||
# Take the first matching advisory with a summary | ||
best_advisory = matching_advisories.first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should take the latest NVD advisory with the most up-to-date summary, and not the oldest
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @TG1999, few nits for your consideration.
level=logging.INFO, | ||
) | ||
|
||
for vulnerability in vulnerabilities_qs.paginated(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use LoopProgress here
for vulnerability in vulnerabilities_qs.paginated(): | |
progress = LoopProgress(total_iterations=vulnerabilities_qs.count(), logger=self.log) | |
for vulnerability in progress.iter(vulnerabilities_qs.paginated()): |
for vulnerability in vulnerabilities_qs.paginated(): | ||
aliases = vulnerability.aliases.values_list("alias", flat=True) | ||
# get alias that start with CVE- with filter | ||
alias = aliases.filter(alias__startswith="CVE-").first() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are prefetching aliases with vulnerabilities_qs = Vulnerability.objects.filter(summary="").prefetch_related("aliases")
, but that will be rendered useless since this will trigger fresh database query.
Reference: #859