Skip to content

Commit 6872a41

Browse files
committed
List every existing advisory under --strict-blocking
Existing alerts for --strict-blocking are read from the new full scan through socketdev's fullscans.stream(). socketdev 3.6.2 merged alerts that share a type and severity on a package, so only the first CVE of each severity reached the CLI. The Existing alerts table and the EXISTING blocking issues count undercounted (3 instead of 8 in the repro), and when the first CVE of a group was resolved or triaged to monitor or ignore, the Block CVEs behind it were dropped and the run passed. socketdev 3.6.3 keys merged alerts on the advisory ID and keeps the most severe action. Pin it. The CLI's own consolidation already keeps the advisory ID (Issue.consolidation_key) and filters on error/warn before it dedupes, so no CLI logic changes. The new tests run the real FullScans.stream() over a canned response, so they fail if the pinned SDK collapses advisories again. Bumps the version to 2.13.1. uv.lock needs `uv lock` once socketdev 3.6.3 is published.
1 parent ef5a7fb commit 6872a41

4 files changed

Lines changed: 96 additions & 3 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## 2.13.1
4+
5+
### Fixed
6+
7+
- `--strict-blocking` lists and counts every advisory on an unchanged package.
8+
Existing alerts are read through the SDK, which kept one alert per alert type
9+
and severity, so a package with six Critical CVEs showed one, and the
10+
"EXISTING blocking issues" count was too low. Requires `socketdev` 3.6.3.
11+
- A Block-action CVE on an unchanged package now fails the run even when
12+
another CVE of the same severity on that package is triaged to monitor or
13+
ignore. Before, the triaged CVE could stand in for both and the run passed.
14+
315
## 2.13.0
416

517
### Upgrade notes

‎pyproject.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ build-backend = "hatchling.build"
66

77
[project]
88
name = "socketsecurity"
9-
version = "2.13.0"
9+
version = "2.13.1"
1010
requires-python = ">= 3.11"
1111
license = {"file" = "LICENSE"}
1212
dependencies = [
@@ -16,7 +16,7 @@ dependencies = [
1616
"gitpython==3.2.1",
1717
"packaging==26.3",
1818
"python-dotenv==1.2.4",
19-
"socketdev==3.6.2",
19+
"socketdev==3.6.3",
2020
"beautifulsoup4==4.15.0",
2121
"markdown==3.11.3",
2222
"brotli==1.2.1; platform_python_implementation == 'CPython'",

‎socketsecurity/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
__author__ = 'socket.dev'
2-
__version__ = '2.13.0'
2+
__version__ = '2.13.1'
33
USER_AGENT_NAME = 'socket-python-cli'
44
USER_AGENT = f'{USER_AGENT_NAME}/{__version__}'

‎tests/core/test_existing_alerts.py‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from socketdev.exceptions import APIFailure
1717
from socketdev.fullscans import (
1818
FullScanParams,
19+
FullScans,
1920
FullScanStreamResponse,
2021
StreamDiffResponse,
2122
)
@@ -245,6 +246,86 @@ def test_matched_package_without_alerts_is_a_clean_result(core):
245246
core.sdk.fullscans.stream.assert_called_once()
246247

247248

249+
# --- Existing advisories read through the SDK's full-scan stream ------------------------
250+
#
251+
# The tests above stub ``fullscans.stream``. These run the real SDK method over a canned
252+
# HTTP response, so they also cover the SDK's merging of duplicate alerts: socketdev
253+
# 3.6.2 kept one alert per type and severity, which dropped every other CVE of that
254+
# severity on a package, along with any Block action it carried.
255+
256+
HANDLEBARS_CRITICAL_ADVISORIES = [
257+
("GHSA-8r5x-fm3f-whwj", ""),
258+
("GHSA-p8wg-vrv2-v86f", ""),
259+
("GHSA-2w6w-674q-4c4q", ""),
260+
("GHSA-w457-6q6x-cgp9", "CVE-2019-19919"),
261+
("GHSA-765h-qjxv-5f44", "CVE-2021-23383"),
262+
("GHSA-f2jv-r9rf-7988", "CVE-2021-23369"),
263+
]
264+
265+
266+
def _cve_alert(ghsa_id, cve_id, action="error"):
267+
return {
268+
"key": f"key-{ghsa_id}",
269+
"type": "criticalCVE",
270+
"severity": "critical",
271+
"category": "vulnerability",
272+
"props": {"ghsaId": ghsa_id, "cveId": cve_id, "title": f"Advisory {ghsa_id}"},
273+
"action": action,
274+
}
275+
276+
277+
def _stream_through_sdk(core, *artifacts):
278+
"""Serve ``artifacts`` as the full-scan NDJSON body and parse it with the real SDK."""
279+
response = Mock(status_code=200, text="\n".join(json.dumps(a) for a in artifacts))
280+
api = Mock(request_timeout=30)
281+
api.do_request.return_value = response
282+
core.sdk.fullscans.stream.side_effect = FullScans(api).stream
283+
284+
285+
def _existing_only_diff(core, *scan_artifacts):
286+
core.cli_config = CliConfig.from_args(["--api-token", "test", "--strict-blocking"])
287+
core.sdk.fullscans.stream_diff.return_value = _diff_response(unchanged=[
288+
_diff_artifact("unchanged", artifact["id"], artifact["name"]) for artifact in scan_artifacts
289+
])
290+
_stream_through_sdk(core, *scan_artifacts)
291+
params = FullScanParams(repo="repo", branch="feature")
292+
params.include_license_details = True
293+
return core.create_new_diff(["/repo"], params, explicit_files=["/repo/package.json"])
294+
295+
296+
def test_every_same_severity_advisory_on_an_unchanged_package_is_kept(core, caplog):
297+
alerts = [_cve_alert(ghsa, cve) for ghsa, cve in HANDLEBARS_CRITICAL_ADVISORIES]
298+
299+
with caplog.at_level("INFO"):
300+
diff = _existing_only_diff(core, _scan_artifact("u1", "handlebars", alerts))
301+
302+
assert sorted(a.advisory_id() for a in diff.unchanged_alerts) == sorted(
303+
ghsa.upper() for ghsa, _ in HANDLEBARS_CRITICAL_ADVISORIES
304+
)
305+
assert all(a.error for a in diff.unchanged_alerts)
306+
assert "Loaded 6 alerts for 1 of 1 unchanged packages" in caplog.text
307+
assert not _handler(strict_blocking=True).report_pass(diff)
308+
309+
comment = Messages.security_comment_template(diff, _config())
310+
assert "Existing alerts (6)" in comment
311+
for ghsa, _ in HANDLEBARS_CRITICAL_ADVISORIES:
312+
assert ghsa.upper() in comment
313+
314+
315+
@pytest.mark.parametrize("triaged_action", ["ignore", "monitor"])
316+
def test_a_triaged_advisory_does_not_hide_a_blocking_one_on_the_same_package(core, triaged_action):
317+
"""The triaged advisory comes first in the stream; the Block one must still fail the run."""
318+
alerts = [
319+
_cve_alert("GHSA-w457-6q6x-cgp9", "CVE-2019-19919", action=triaged_action),
320+
_cve_alert("GHSA-765h-qjxv-5f44", "CVE-2021-23383", action="error"),
321+
]
322+
323+
diff = _existing_only_diff(core, _scan_artifact("u1", "handlebars", alerts))
324+
325+
assert [(a.advisory_id(), a.error) for a in diff.unchanged_alerts] == [("GHSA-765H-QJXV-5F44", True)]
326+
assert not _handler(strict_blocking=True).report_pass(diff)
327+
328+
248329
# --- PR comment ------------------------------------------------------------------------
249330

250331

0 commit comments

Comments
 (0)