Skip to content

Commit 71b687f

Browse files
committed
Document and test advisory identity boundaries
1 parent 766e50b commit 71b687f

2 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎socketsecurity/core/classes.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,12 @@ def __init__(self, **kwargs):
360360
self.ignore = False
361361

362362
def advisory_id(self) -> str:
363-
"""The GHSA or CVE identifier in the alert's props, upper-cased, or ""."""
363+
"""The preferred GHSA or CVE identifier, upper-cased, or "".
364+
365+
This priority is not alias resolution. GHSA-only and CVE-only records
366+
remain distinct without an upstream alias mapping; guessing from their
367+
package and alert type could suppress a different vulnerability.
368+
"""
364369
props = getattr(self, "props", None) or {}
365370
for prop_name in ADVISORY_ID_PROPS:
366371
value = props.get(prop_name)

‎tests/core/test_alert_consolidation.py‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,33 @@ def test_consolidation_key_includes_ecosystem_and_ignores_advisory_case():
9090
assert npm.consolidation_key()[3] == pypi.consolidation_key()[3]
9191

9292

93+
def test_adding_a_cve_to_a_ghsa_record_keeps_the_same_finding_identity():
94+
ghsa_only = _cve("GHSA-aaaa-aaaa-aaaa", error=True)
95+
both = _cve("GHSA-aaaa-aaaa-aaaa", error=True)
96+
both.props["cveId"] = "CVE-2026-0001"
97+
98+
assert ghsa_only.consolidation_key() == both.consolidation_key()
99+
assert Messages.generate_uuid_from_alert_gitlab(ghsa_only) == Messages.generate_uuid_from_alert_gitlab(both)
100+
assert len(Core.get_new_alerts({ghsa_only.key: [ghsa_only, both]}, {})) == 1
101+
102+
103+
@pytest.mark.parametrize("ghsa_field", ["ghsaId", "ghsa_id"])
104+
@pytest.mark.parametrize("cve_field", ["cveId", "cve_id", "cve"])
105+
def test_disjoint_advisory_ids_are_not_assumed_to_be_aliases(ghsa_field, cve_field):
106+
# Neither input establishes whether these identifiers name the same advisory.
107+
# Retaining both protects a blocker from being hidden behind another finding.
108+
ghsa_only = _cve("GHSA-aaaa-aaaa-aaaa", warn=True, props_field=ghsa_field)
109+
cve_only = _cve("CVE-2026-0001", error=True, props_field=cve_field)
110+
111+
alerts = Core.get_new_alerts({ghsa_only.key: [ghsa_only], cve_only.key: [cve_only]}, {})
112+
113+
assert alerts == [ghsa_only, cve_only]
114+
report = Messages.create_security_comment_gitlab(Diff(new_alerts=alerts))
115+
assert len({finding["id"] for finding in report["vulnerabilities"]}) == 2
116+
config = Mock(spec=CliConfig, disable_blocking=False, strict_blocking=False)
117+
assert OutputHandler(config, Mock()).return_exit_code(Diff(new_alerts=alerts)) == 1
118+
119+
93120
def test_non_advisory_alerts_still_collapse_per_package_and_type():
94121
"""Alerts with no advisory ID keep the per-package, per-type collapse."""
95122
first = Issue(pkg_type="npm", purl="a@1.0.0", type="envVars", props={}, warn=True, key="k1")

0 commit comments

Comments
 (0)