Skip to content

Commit 3f0df8e

Browse files
committed
Post a Slack scan summary from the demo workflow
Add an optional step (7) to nightvision.yml that posts a one-line summary of the DAST scan to a Slack Incoming Webhook: on success, the finding counts (total, critical, high) parsed from results.sarif plus links to the GitHub code-scanning tab and the run; on failure, the job status and run link. - Gated on a SLACK_WEBHOOK_URL secret (mapped to env) so the step is skipped, and the scan still passes, when Slack is not configured. - Uses curl against the webhook with a jq-built (escaped) JSON payload; no third-party action and no token-based importer to maintain. - Runs with always() so a failed scan still notifies.
1 parent d8659b6 commit 3f0df8e

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

.github/workflows/nightvision.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ env:
3434
NIGHTVISION_TOKEN: ${{ secrets.NIGHTVISION_TOKEN }}
3535
NIGHTVISION_TARGET: javaspringvulny
3636
NIGHTVISION_AUTH: javaspringvulny
37+
# Optional: a Slack Incoming Webhook URL. When set, step (7) posts a scan
38+
# summary; when unset, that step is skipped and the scan still runs and uploads.
39+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
3740

3841
jobs:
3942
test:
@@ -89,3 +92,26 @@ jobs:
8992
if: success()
9093
with:
9194
sarif_file: results.sarif
95+
96+
# Post a one-line scan summary to a Slack Incoming Webhook. Runs on both success
97+
# and failure (always()), skipped when SLACK_WEBHOOK_URL is not set. Best-effort:
98+
# a webhook POST failure prints a warning but does not fail the run (the scan and
99+
# SARIF upload have already succeeded). jq builds the JSON payload so the message
100+
# text is escaped safely.
101+
- name: (7) Post scan summary to Slack
102+
if: ${{ always() && env.SLACK_WEBHOOK_URL != '' }}
103+
run: |
104+
run_url="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
105+
if [ "${{ job.status }}" = "success" ] && [ -f results.sarif ]; then
106+
total=$(jq '[.runs[].results[]] | length' results.sarif)
107+
crit=$(jq '[.runs[].results[] | select(.properties["nightvision-risk"] == "CRITICAL")] | length' results.sarif)
108+
high=$(jq '[.runs[].results[] | select(.properties["nightvision-risk"] == "HIGH")] | length' results.sarif)
109+
findings_url="${{ github.server_url }}/${{ github.repository }}/security/code-scanning"
110+
text="NightVision scan of ${NIGHTVISION_TARGET} in ${{ github.repository }} succeeded: ${total} findings (${crit} critical, ${high} high). <${findings_url}|Findings> | <${run_url}|Run>"
111+
else
112+
text="NightVision scan of ${NIGHTVISION_TARGET} in ${{ github.repository }} did not complete (status ${{ job.status }}). <${run_url}|Run>"
113+
fi
114+
curl -sSf -X POST -H 'Content-type: application/json' \
115+
--data "$(jq -n --arg t "$text" '{text: $t, unfurl_links: false, unfurl_media: false}')" \
116+
"$SLACK_WEBHOOK_URL" \
117+
|| echo "::warning::Slack notification failed; continuing (scan result unaffected)."

0 commit comments

Comments
 (0)