Skip to content

Commit 8cc2594

Browse files
committed
Tighten dedupe comments
1 parent 6b7d330 commit 8cc2594

2 files changed

Lines changed: 9 additions & 13 deletions

File tree

‎socketdev/core/dedupe.py‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,15 @@
66
# one severity on a package shares an alert type (``criticalCVE``, ``cve`` and
77
# so on), so these are what tell two of them apart.
88
#
9-
# Socket's CVE alerts carry ``ghsaId`` and ``cveId``. The other names are not
10-
# in any current alert schema; they are checked so this lookup matches
11-
# ``ADVISORY_ID_PROPS`` / ``Issue.advisory_id()`` in socket-python-cli
9+
# Socket's CVE alerts carry ``ghsaId`` and ``cveId``. The other names are in no
10+
# current alert schema; they mirror ``Issue.advisory_id()`` in socket-python-cli
1211
# (socketsecurity/core/classes.py), which reads alerts from this SDK. Keep the
1312
# two lists in step.
1413
ADVISORY_ID_PROPS = ("ghsaId", "ghsa_id", "cveId", "cve_id", "cve")
1514

1615
# Policy actions from least to most severe. An unknown or missing action ranks
17-
# below "ignore": it yields to any known action, "ignore" included, and never
18-
# replaces one. So an unexpected value can't downgrade a known "error", and
19-
# the result doesn't depend on which release is listed first.
16+
# below "ignore", so it never replaces a known action and the merged result
17+
# doesn't depend on which release is listed first.
2018
ACTION_RANK = {"ignore": 0, "monitor": 1, "warn": 2, "error": 3}
2119

2220

@@ -95,12 +93,10 @@ def consolidate_and_merge_alerts(package_group: List[Dict[str, Any]]) -> Dict[st
9593
merged = alert_map[identity]
9694
if release not in merged["releases"]:
9795
merged["releases"].append(release)
98-
# Keep the most severe action seen for this alert, so a
99-
# release that blocks is never hidden behind one that doesn't.
100-
# Only the action moves: key, props and the rest stay as the
101-
# first sighting had them, so in a purl.post() result the
102-
# merged key can belong to a release whose own action was
103-
# less severe than the one shown.
96+
# Keep the most severe action seen, so a release that blocks
97+
# is never hidden behind one that doesn't. Only the action
98+
# moves: key and props stay with the first sighting, so the
99+
# key can belong to a release with a less severe action.
104100
if Dedupe.action_rank(alert.get("action")) > Dedupe.action_rank(merged.get("action")):
105101
merged["action"] = alert.get("action")
106102

‎tests/unit/test_dedupe.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def test_advisory_id_falls_back_to_cve_and_ignores_case(self):
342342
self.assertEqual(sorted(a["props"]["cveId"] for a in alerts), ["CVE-2021-0001", "CVE-2021-0002"])
343343

344344
def test_alerts_without_advisory_still_merge_across_releases(self):
345-
"""Non-advisory alerts keep the existing identity, including normalized file paths"""
345+
"""Alerts without an advisory ID merge on type, severity and location, with file paths normalized"""
346346
def file_alert(path, action):
347347
return {
348348
"key": f"key-{path}", "type": "networkAccess", "severity": "middle",

0 commit comments

Comments
 (0)