Skip to content

Commit edaf9b7

Browse files
Setup CodeQL Slack notifications
Signed-off-by: kysimmon <kylesimmons96@protonmail.com>
1 parent dc3bbca commit edaf9b7

File tree

1 file changed

+66
-2
lines changed

1 file changed

+66
-2
lines changed

.github/workflows/codeql.yml

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: CodeQL
33
on:
44
workflow_dispatch:
55
schedule:
6-
# Run at the end of every Monday
7-
- cron: '0 0 * * 1'
6+
# Run at the end of every day from Monday to Friday
7+
- cron: '0 0 * * 1-5'
88

99
jobs:
1010
analyze:
@@ -68,3 +68,67 @@ jobs:
6868
uses: github/codeql-action/analyze@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3
6969
with:
7070
category: '/language:${{matrix.config.language}}'
71+
output: sarif-output-${{ matrix.config.language }}.sarif
72+
- name: Filter SARIF Results
73+
run: |
74+
REPO_URL="https://github.com/${{ github.repository }}/blob/${{ github.ref_name }}/"
75+
jq --arg baseUrl "$REPO_URL" '[.runs[].results[] |
76+
{
77+
ruleId: .ruleId,
78+
message: .message.text,
79+
url: "\($baseUrl)\(.locations[0].physicalLocation.artifactLocation.uri)#L\(.locations[0].physicalLocation.region.startLine)\(if .locations[0].physicalLocation.region.endLine != null then "-L\(.locations[0].physicalLocation.region.endLine)" else "" end)"
80+
}]' sarif-output-${{ matrix.config.language }}.sarif/${{ matrix.config.language }}.sarif > filtered-${{ matrix.config.language }}.json
81+
- name: Display Filtered Results
82+
run: cat filtered-${{ matrix.config.language }}.json
83+
- name: Send Slack Notification
84+
env:
85+
SEC_BOT_SLACK_WEBHOOK: ${{ secrets.SEC_BOT_SLACK_WEBHOOK }}
86+
CHANNEL: "#security-team"
87+
run: |
88+
jq -c '.[]' filtered-${{ matrix.config.language }}.json | while read -r item; do
89+
RULE_ID=$(echo "$item" | jq -r '.ruleId')
90+
MESSAGE=$(echo "$item" | jq -r '.message')
91+
URL=$(echo "$item" | jq -r '.url')
92+
93+
PAYLOAD=$(cat <<EOF
94+
{
95+
"channel": "$CHANNEL",
96+
"blocks": [
97+
{
98+
"type": "header",
99+
"text": {
100+
"type": "plain_text",
101+
"text": "🚨 CodeQL Alert for ${{ matrix.config.language }} 🚨",
102+
"emoji": true
103+
}
104+
},
105+
{
106+
"type": "section",
107+
"text": {
108+
"type": "mrkdwn",
109+
"text": "*Rule:* $RULE_ID"
110+
}
111+
},
112+
{
113+
"type": "section",
114+
"text": {
115+
"type": "mrkdwn",
116+
"text": "*Message:* $MESSAGE"
117+
}
118+
},
119+
{
120+
"type": "section",
121+
"text": {
122+
"type": "mrkdwn",
123+
"text": "*File:* $URL"
124+
}
125+
}
126+
]
127+
}
128+
EOF
129+
)
130+
131+
curl -X POST -H "Authorization: Bearer $SEC_BOT_SLACK_WEBHOOK" \
132+
-H "Content-type: application/json" \
133+
--data-raw "$PAYLOAD" https://slack.com/api/chat.postMessage
134+
done

0 commit comments

Comments
 (0)