Skip to content

Commit fe1b610

Browse files
committed
Include API actions in JSON findings
Expose the Socket API action on selected standard JSON findings while preserving legacy Issue serialization, equality, alert selection, and process exit behavior. Verify both real SDK transport paths with the local HTTP fixture. Assisted-by: Codex:gpt-6-luna
1 parent 9b1a282 commit fe1b610

6 files changed

Lines changed: 471 additions & 15 deletions

File tree

‎docs/cli-reference.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,13 @@ Either field is JSON null when its source value is unavailable. The existing
349349
are distinct from the scan-reference URLs above and do not identify an
350350
individual alert or triage page.
351351
352+
Each selected alert also includes `action`, the scalar action returned by the
353+
Socket API, such as `error`, `warn`, `monitor`, or `ignore`. It is JSON null
354+
when no action is available. Existing alert selection is unchanged: standard
355+
output includes new error and warning findings, and `--strict-blocking` also
356+
includes unchanged error and warning findings. The action field does not
357+
change the CLI process exit code.
358+
352359
Standard Socket JSON also includes four package-change arrays:
353360
`new_packages`, `updated_packages`, `removed_packages`, and `replaced_packages`.
354361
Rows contain `id`, `name`, `version`, `ecosystem`, `direct`, `author`, `size`,

‎socketsecurity/core/__init__.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2836,6 +2836,11 @@ def add_package_alerts_to_collection(self, package: Package, alerts_collection:
28362836
pkg_type=package.type,
28372837
pkg_name=package.name,
28382838
pkg_version=package.version,
2839+
api_action=(
2840+
alert_item.get("action")
2841+
if isinstance(alert_item.get("action"), str)
2842+
else None
2843+
),
28392844
pkg_id=package.id,
28402845
props=alert.props,
28412846
key=alert.key,

‎socketsecurity/core/classes.py‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,15 @@ class Issue:
322322
# introduced_by chain, but its manifest is still known.
323323
manifest_files: list
324324
direct: bool
325+
api_action: Optional[str]
325326

326327
def __init__(self, **kwargs):
327328
if kwargs:
328329
for key, value in kwargs.items():
329330
setattr(self, key, value)
330331

332+
if not hasattr(self, "api_action"):
333+
self.api_action = None
331334
if hasattr(self, "created_at"):
332335
self.created_at = self.created_at.strip(" (Coordinated Universal Time)")
333336
if not hasattr(self, "manifest_files"):
@@ -355,13 +358,22 @@ def __init__(self, **kwargs):
355358
self.ignore = False
356359

357360
def __str__(self):
358-
return json.dumps(self.__dict__)
361+
return json.dumps(self.to_dict())
362+
363+
def to_dict(self) -> dict[str, object]:
364+
result = dict(self.__dict__)
365+
result.pop("api_action", None)
366+
return result
359367

360368
def __eq__(self, other):
361-
return self.__dict__ == other.__dict__
369+
other_dict = dict(other.__dict__)
370+
other_dict.pop("api_action", None)
371+
return self.to_dict() == other_dict
362372

363373
def __ne__(self, other):
364-
return self.__dict__ != other.__dict__
374+
other_dict = dict(other.__dict__)
375+
other_dict.pop("api_action", None)
376+
return self.to_dict() != other_dict
365377

366378

367379
class YamlFile:
@@ -642,9 +654,13 @@ def to_dict(self) -> dict:
642654
"new_capabilities": self.new_capabilities,
643655
"removed_packages": [p.to_dict() for p in self.removed_packages],
644656
"replaced_packages": [p.to_dict() for p in self.replaced_packages],
645-
"new_alerts": [alert.__dict__ for alert in self.new_alerts],
646-
"unchanged_alerts": [alert.__dict__ for alert in self.unchanged_alerts] if hasattr(self, "unchanged_alerts") else [],
647-
"removed_alerts": [alert.__dict__ for alert in self.removed_alerts] if hasattr(self, "removed_alerts") else [],
657+
"new_alerts": [alert.to_dict() for alert in self.new_alerts],
658+
"unchanged_alerts": [alert.to_dict() for alert in self.unchanged_alerts]
659+
if hasattr(self, "unchanged_alerts")
660+
else [],
661+
"removed_alerts": [alert.to_dict() for alert in self.removed_alerts]
662+
if hasattr(self, "removed_alerts")
663+
else [],
648664
"id": self.id,
649665
"sbom": self.sbom if hasattr(self, "sbom") else [],
650666
"packages": {k: v.to_dict() for k, v in self.packages.items()} if hasattr(self, "packages") else {},

‎socketsecurity/core/report_output.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,12 @@ def build_socket_json_report(
142142
)
143143
selected_diff = clone_diff_with_selected_alerts(diff_report, selected_alerts)
144144
report = Messages.create_security_comment_json(selected_diff)
145-
for alert_row in report["new_alerts"]:
145+
for issue, alert_row in zip(
146+
selected_alerts,
147+
report["new_alerts"],
148+
strict=True,
149+
):
150+
alert_row["action"] = issue.api_action
146151
package_url = alert_row.get("url")
147152
alert_type = alert_row.get("type")
148153
links = build_alert_links(

0 commit comments

Comments
 (0)