Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,13 @@ Either field is JSON null when its source value is unavailable. The existing
are distinct from the scan-reference URLs above and do not identify an
individual alert or triage page.

Each selected alert also includes `action`, the scalar action returned by the
Socket API, such as `error`, `warn`, `monitor`, or `ignore`. It is JSON null
when no action is available. Existing alert selection is unchanged: standard
output includes new error and warning findings, and `--strict-blocking` also
includes unchanged error and warning findings. The action field does not
change the CLI process exit code.

Standard Socket JSON also includes four package-change arrays:
`new_packages`, `updated_packages`, `removed_packages`, and `replaced_packages`.
Rows contain `id`, `name`, `version`, `ecosystem`, `direct`, `author`, `size`,
Expand Down
5 changes: 5 additions & 0 deletions socketsecurity/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2836,6 +2836,11 @@ def add_package_alerts_to_collection(self, package: Package, alerts_collection:
pkg_type=package.type,
pkg_name=package.name,
pkg_version=package.version,
api_action=(
alert_item.get("action")
if isinstance(alert_item.get("action"), str)
else None
),
pkg_id=package.id,
props=alert.props,
key=alert.key,
Expand Down
28 changes: 22 additions & 6 deletions socketsecurity/core/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,15 @@ class Issue:
# introduced_by chain, but its manifest is still known.
manifest_files: list
direct: bool
api_action: Optional[str]

def __init__(self, **kwargs):
if kwargs:
for key, value in kwargs.items():
setattr(self, key, value)

if not hasattr(self, "api_action"):
self.api_action = None
if hasattr(self, "created_at"):
self.created_at = self.created_at.strip(" (Coordinated Universal Time)")
if not hasattr(self, "manifest_files"):
Expand Down Expand Up @@ -355,13 +358,22 @@ def __init__(self, **kwargs):
self.ignore = False

def __str__(self):
return json.dumps(self.__dict__)
return json.dumps(self.to_dict())

def to_dict(self) -> dict[str, object]:
result = dict(self.__dict__)
result.pop("api_action", None)
return result

def __eq__(self, other):
return self.__dict__ == other.__dict__
other_dict = dict(other.__dict__)
other_dict.pop("api_action", None)
return self.to_dict() == other_dict

def __ne__(self, other):
return self.__dict__ != other.__dict__
other_dict = dict(other.__dict__)
other_dict.pop("api_action", None)
return self.to_dict() != other_dict


class YamlFile:
Expand Down Expand Up @@ -642,9 +654,13 @@ def to_dict(self) -> dict:
"new_capabilities": self.new_capabilities,
"removed_packages": [p.to_dict() for p in self.removed_packages],
"replaced_packages": [p.to_dict() for p in self.replaced_packages],
"new_alerts": [alert.__dict__ for alert in self.new_alerts],
"unchanged_alerts": [alert.__dict__ for alert in self.unchanged_alerts] if hasattr(self, "unchanged_alerts") else [],
"removed_alerts": [alert.__dict__ for alert in self.removed_alerts] if hasattr(self, "removed_alerts") else [],
"new_alerts": [alert.to_dict() for alert in self.new_alerts],
"unchanged_alerts": [alert.to_dict() for alert in self.unchanged_alerts]
if hasattr(self, "unchanged_alerts")
else [],
"removed_alerts": [alert.to_dict() for alert in self.removed_alerts]
if hasattr(self, "removed_alerts")
else [],
"id": self.id,
"sbom": self.sbom if hasattr(self, "sbom") else [],
"packages": {k: v.to_dict() for k, v in self.packages.items()} if hasattr(self, "packages") else {},
Expand Down
7 changes: 6 additions & 1 deletion socketsecurity/core/report_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,12 @@ def build_socket_json_report(
)
selected_diff = clone_diff_with_selected_alerts(diff_report, selected_alerts)
report = Messages.create_security_comment_json(selected_diff)
for alert_row in report["new_alerts"]:
for issue, alert_row in zip(
selected_alerts,
report["new_alerts"],
strict=True,
):
alert_row["action"] = issue.api_action
package_url = alert_row.get("url")
alert_type = alert_row.get("type")
links = build_alert_links(
Expand Down
Loading
Loading