Skip to content

Commit

Permalink
add tags field to event data on new vulnerability notifications
Browse files Browse the repository at this point in the history
when building message notification, use get() to avoid exception when
looking up event_data["tags"]

use get() to avoid throwing error if key is not found
  • Loading branch information
Marcusk19 committed Mar 4, 2024
1 parent 827ca13 commit 600b605
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
34 changes: 20 additions & 14 deletions data/secscan_model/secscan_v4_model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import itertools
import logging
import urllib
Expand Down Expand Up @@ -57,6 +58,7 @@


DEFAULT_SECURITY_SCANNER_V4_REINDEX_THRESHOLD = 86400 # 1 day
TAG_LIMIT = 100

IndexReportState = namedtuple("IndexReportState", ["Index_Finished", "Index_Error"])( # type: ignore[call-arg]
"IndexFinished", "IndexError"
Expand Down Expand Up @@ -454,23 +456,27 @@ def should_skip_indexing(manifest_candidate):
import notifications

keys = list(found_vulnerabilities)
tag_names = list(registry_model.tag_names_for_manifest(manifest, None))
for key in keys:
vuln = found_vulnerabilities[key]

event_data = {
"vulnerable_index_report_created": "true",
"vulnerability": {
"id": vuln["id"],
"description": vuln["description"],
"link": vuln["links"],
"priority": vuln["severity"],
"has_fix": bool(vuln["fixed_in_version"]),
},
}

notifications.spawn_notification(
manifest.repository, "vulnerability_found", event_data
)
for i in range(0, len(tag_names), TAG_LIMIT):

event_data = {
"tags": list(tag_names[i : i + TAG_LIMIT]),
"vulnerable_index_report_created": "true",
"vulnerability": {
"id": vuln["id"],
"description": vuln["description"],
"link": vuln["links"],
"priority": vuln["severity"],
"has_fix": bool(vuln["fixed_in_version"]),
},
}

notifications.spawn_notification(
manifest.repository, "vulnerability_found", event_data
)

elif report["state"] == IndexReportState.Index_Error:
index_status = IndexStatus.FAILED
Expand Down
2 changes: 1 addition & 1 deletion notifications/notificationevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def get_summary(self, event_data, notification_data):
return msg % (
event_data[vuln_key][priority_key],
event_data["repository"],
len(event_data["tags"]),
len(event_data.get("tags")),
)


Expand Down

0 comments on commit 600b605

Please sign in to comment.