Skip to content

Commit 2b0c0aa

Browse files
committed
Implement reachabilty logic for SARIF output
Signed-off-by: lelia <lelia@socket.dev>
1 parent 1ce447f commit 2b0c0aa

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

socketsecurity/output.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,23 @@ def output_console_sarif(self, diff_report: Diff, sbom_file_name: Optional[str]
140140
"""
141141
Generate SARIF output from the diff report and print to console.
142142
If --sarif-file is configured, also save to file.
143+
If --sarif-reachable-only is set, filters to blocking (reachable) alerts only.
143144
"""
144145
if diff_report.id != "NO_DIFF_RAN":
146+
# When --sarif-reachable-only is set, filter to error=True alerts only.
147+
# This mirrors the Slack plugin's reachability_alerts_only behaviou:
148+
# when --reach is used, error=True reflects Socket's reachability-aware policy.
149+
if self.config.sarif_reachable_only:
150+
filtered_alerts = [a for a in diff_report.new_alerts if getattr(a, "error", False)]
151+
diff_report = Diff(
152+
new_alerts=filtered_alerts,
153+
diff_url=getattr(diff_report, "diff_url", ""),
154+
new_packages=getattr(diff_report, "new_packages", []),
155+
removed_packages=getattr(diff_report, "removed_packages", []),
156+
packages=getattr(diff_report, "packages", {}),
157+
)
158+
diff_report.id = "filtered"
159+
145160
# Generate the SARIF structure using Messages
146161
console_security_comment = Messages.create_security_comment_sarif(diff_report)
147162
self.save_sbom_file(diff_report, sbom_file_name)

0 commit comments

Comments
 (0)