Skip to content

Commit a7c6ba3

Browse files
authored
fix: always filter diff scan artifacts
1 parent 2315da3 commit a7c6ba3

2 files changed

Lines changed: 63 additions & 1 deletion

File tree

socketsecurity/core/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,12 @@ def get_diff_scan_artifacts(
15951595
# failed comparison in a CI log back to a server-side diff scan, and it is
15961596
# needed even when the run later falls back to the streaming comparison.
15971597
log.info(f"Diff scan created: id={diff_scan_id}")
1598-
artifacts_dict = diff_scan.get("artifacts")
1598+
1599+
# The create and list endpoints are metadata-only. Always fetch artifacts
1600+
# through GET below, even if an unexpected/legacy response happens to embed
1601+
# them, so omit_unchanged and the bounded cached-polling contract cannot be
1602+
# bypassed by an eager response.
1603+
artifacts_dict = None
15991604

16001605
# cached=true is the polling contract (202 while computing, 200 when
16011606
# ready). The API ignores omit_license_details when cached=true - cached

tests/core/test_diff_scan_polling.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,63 @@ def test_duplicate_conflict_uses_cached_polling(core, diff_scan_get_response):
104104
assert len(artifacts.added) > 0
105105

106106

107+
def test_eager_create_artifacts_do_not_bypass_filtered_get(core, diff_scan_get_response):
108+
"""Unexpected create artifacts are ignored so the filtered GET remains canonical."""
109+
from types import SimpleNamespace
110+
111+
core.cli_config = SimpleNamespace(
112+
strict_blocking=False,
113+
enable_gitlab_security=False,
114+
generate_license=False,
115+
legal_format="socket",
116+
)
117+
core.sdk.diffscans.create_from_ids.return_value = {
118+
"diff_scan": {
119+
"id": "diff-scan-123",
120+
"artifacts": diff_scan_get_response["diff_scan"]["artifacts"],
121+
}
122+
}
123+
124+
core.get_diff_scan_artifacts("head", "new")
125+
126+
core.sdk.diffscans.get.assert_called_once_with(
127+
core.config.org_slug,
128+
"diff-scan-123",
129+
params={"cached": "true", "omit_unchanged": "true"},
130+
)
131+
132+
133+
def test_eager_list_artifacts_do_not_bypass_filtered_get(core, diff_scan_get_response):
134+
"""Unexpected duplicate-list artifacts cannot skip the filtered GET either."""
135+
from types import SimpleNamespace
136+
137+
core.cli_config = SimpleNamespace(
138+
strict_blocking=False,
139+
enable_gitlab_security=False,
140+
generate_license=False,
141+
legal_format="socket",
142+
)
143+
core.sdk.diffscans.create_from_ids.side_effect = APIFailure(
144+
"duplicate", status_code=409
145+
)
146+
core.sdk.diffscans.list.return_value = {
147+
"results": [
148+
{
149+
"id": "existing-diff-scan",
150+
"artifacts": diff_scan_get_response["diff_scan"]["artifacts"],
151+
}
152+
],
153+
}
154+
155+
core.get_diff_scan_artifacts("head", "new")
156+
157+
core.sdk.diffscans.get.assert_called_once_with(
158+
core.config.org_slug,
159+
"existing-diff-scan",
160+
params={"cached": "true", "omit_unchanged": "true"},
161+
)
162+
163+
107164
def test_fallback_to_streaming_diff_on_failure(core):
108165
"""If the diff-scans flow fails (e.g. token missing the diff-scans scopes),
109166
the comparison falls back to the legacy streaming diff transparently."""

0 commit comments

Comments
 (0)