Skip to content

SARIF file output and reachability filtering#165

Merged
dacoburn merged 19 commits intomainfrom
lelia/fix-sarif-output
Mar 4, 2026
Merged

SARIF file output and reachability filtering#165
dacoburn merged 19 commits intomainfrom
lelia/fix-sarif-output

Conversation

@lelia
Copy link
Contributor

@lelia lelia commented Feb 27, 2026

Summary

Adds two new SARIF output flags and improves Slack bot mode debug logging:

  • --sarif-file <path> — saves SARIF output to a file for upload to GitHub Code Scanning, SonarQube, VS Code, etc.
  • --sarif-reachable-only — filters SARIF output to reachable (blocking) findings only (requires --reach)
  • Improved --enable-debug logging in Slack bot mode to surface silent failures when reachability alerts aren't being sent

Changes

  • --sarif-file: added config field + CLI flag; implies --enable-sarif so users don't need to pass both
  • --sarif-reachable-only: added config field + CLI flag; exits with a clear error if passed without --reach
  • output.py: output_console_sarif now writes to the specified filepath in addition to stdout, and pre-filters alerts when --sarif-reachable-only is set
  • Testing: added unit tests for SARIF file output, reachability filtering, and --sarif-reachable-only config validation; added Unit Tests CI workflow; extended e2e tests to validate --sarif-file output and assert reachable-only is a subset of unfiltered results
  • Slack debugging: surfaces bot token presence, Slack mode, and reachability facts file path/existence; upgraded silent return paths in _send_bot_reachability_alerts to error-level logging

Testing

  • Confirmed all new unit tests pass both locally and in CI
  • Ran socketcli --sarif-file results.sarif against a representative repo
  • Confirmed that a results.sarif file was output with valid syntax

Preview

Representative preview of what results.sarif output looks like:

{
  "$schema": "https://json.schemastore.org/sarif-2.1.0.json",
  "version": "2.1.0",
  "runs": [
    {
      "tool": {
        "driver": {
          "name": "Socket Security",
          "informationUri": "https://socket.dev",
          "rules": [
            {
              "id": "lodash==4.17.20 (package.json)",
              "name": "Alert lodash==4.17.20 (package.json)",
              "shortDescription": {
                "text": "Alert lodash==4.17.20 (package.json)"
              },
              "fullDescription": {
                "text": "Prototype Pollution - test"
              },
              "helpUri": "https://socket.dev/npm/package/lodash/alerts/4.17.20",
              "defaultConfiguration": {
                "level": "error"
              }
            }
          ]
        }
      },
      "results": [
        {
          "ruleId": "lodash==4.17.20 (package.json)",
          "message": {
            "text": "<br/><br/>Suggested Action:<br/><br/><a href=\"https://socket.dev/npm/package/lodash/alerts/4.17.20\">https://socket.dev/npm/package/lodash/alerts/4.17.20</a>"
          },
          "locations": [
            {
              "physicalLocation": {
                "artifactLocation": {
                  "uri": "package.json"
                },
                "region": {
                  "startLine": 1,
                  "snippet": {
                    "text": "package.json not found"
                  }
                }
              }
            }
          ]
        }
      ]
    }
  ]
}

Signed-off-by: lelia <lelia@socket.dev>
Signed-off-by: lelia <lelia@socket.dev>
Signed-off-by: lelia <lelia@socket.dev>
Signed-off-by: lelia <lelia@socket.dev>
Signed-off-by: lelia <lelia@socket.dev>
@lelia lelia requested a review from a team as a code owner February 27, 2026 01:03
@github-actions
Copy link

github-actions bot commented Feb 27, 2026

🚀 Preview package published!

Install with:

pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple socketsecurity==2.2.76.dev6

Docker image: socketdev/cli:pr-165

lelia added 12 commits March 3, 2026 14:25
Signed-off-by: lelia <lelia@socket.dev>
Signed-off-by: lelia <lelia@socket.dev>
Signed-off-by: lelia <lelia@socket.dev>
Signed-off-by: lelia <lelia@socket.dev>
Signed-off-by: lelia <lelia@socket.dev>
Signed-off-by: lelia <lelia@socket.dev>
Signed-off-by: lelia <lelia@socket.dev>
…-reach flag

Signed-off-by: lelia <lelia@socket.dev>
Signed-off-by: lelia <lelia@socket.dev>
Signed-off-by: lelia <lelia@socket.dev>
@socket-security-staging
Copy link

socket-security-staging bot commented Mar 3, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedpypi/​socketdev@​3.0.31 ⏵ 3.0.3298 +1100100100100

View full report

@socket-security
Copy link

socket-security bot commented Mar 3, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatedpypi/​socketdev@​3.0.31 ⏵ 3.0.3298 +1100100100100

View full report

lelia added 2 commits March 3, 2026 16:38
…lus other test fixes

Signed-off-by: lelia <lelia@socket.dev>
@lelia lelia changed the title Add support for writing SARIF results to a file SARIF file output and reachability filtering Mar 3, 2026
@dacoburn dacoburn merged commit b8b49f5 into main Mar 4, 2026
10 checks passed
@dacoburn dacoburn deleted the lelia/fix-sarif-output branch March 4, 2026 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants