-
Notifications
You must be signed in to change notification settings - Fork 208
218 lines (192 loc) · 6.93 KB
/
Copy pathcodeql.yml
File metadata and controls
218 lines (192 loc) · 6.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
name: CodeQL Security Scanning
on:
pull_request:
branches:
- main
- develop
push:
branches:
- main
- develop
schedule:
- cron: '0 6 * * 1' # Weekly Monday 06:00 UTC
permissions:
contents: read
security-events: write
actions: read
jobs:
analyze-rust:
name: CodeQL (Rust)
runs-on: ubuntu-latest
if: >-
github.event_name == 'schedule' ||
github.event_name == 'push' ||
(github.event_name == 'pull_request' &&
(github.event.pull_request.base.ref == 'main' || github.event.pull_request.base.ref == 'develop'))
strategy:
fail-fast: false
matrix:
language: ['rust']
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
config: |
paths:
- contracts/
paths-ignore:
- contracts/mock-strategy/
- contracts/vault/src/test.rs
- contracts/vault/src/fuzz_math.rs
- contracts/vault/src/*_tests.rs
query-filters:
- exclude:
id: rust/unsafe-cast
# The trailing `|| true` used to swallow every build failure, which is how
# a non-compiling vault reached main unnoticed. The wasm32 build is
# expected to fail for the vault (blocked upstream by DataKey
# contracttype limits), so fall back to the host build -- and let that
# failure fail the job, as a genuine compile error should.
- name: Build Rust contracts
run: |
cargo build --release --target wasm32-unknown-unknown -p mock-strategy || \
cargo build --release -p vault
working-directory: contracts
env:
RUSTFLAGS: "-C link-arg=-s"
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{ matrix.language }}"
output: rust-results
- name: Upload Rust security artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: codeql-rust-results
path: rust-results/
retention-days: 90
analyze-typescript:
name: CodeQL (TypeScript)
runs-on: ubuntu-latest
if: >-
github.event_name == 'schedule' ||
github.event_name == 'push' ||
(github.event_name == 'pull_request' &&
(github.event.pull_request.base.ref == 'main' || github.event.pull_request.base.ref == 'develop'))
strategy:
fail-fast: false
matrix:
language: ['typescript']
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: '20'
cache: npm
cache-dependency-path: |
backend/package-lock.json
frontend/package-lock.json
packages/api-schemas/package-lock.json
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
config: |
paths:
- frontend/src/
- backend/src/
- packages/api-schemas/
paths-ignore:
- '**/*.test.ts'
- '**/*.test.tsx'
- '**/*.spec.ts'
- '**/*.spec.tsx'
- '**/node_modules/'
- name: Install backend dependencies
run: npm ci
working-directory: backend
- name: Install frontend dependencies
run: npm ci
working-directory: frontend
- name: Build shared API schemas
run: npm ci && npm run build
working-directory: packages/api-schemas
- name: Autobuild
uses: github/codeql-action/autobuild@v3
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{ matrix.language }}"
output: ts-results
- name: Upload TypeScript security artifacts
uses: actions/upload-artifact@v4
if: always()
with:
name: codeql-typescript-results
path: ts-results/
retention-days: 90
security-review:
name: Security Review Summary
runs-on: ubuntu-latest
needs: [analyze-rust, analyze-typescript]
if: always()
steps:
- name: Download all CodeQL artifacts
uses: actions/download-artifact@v4
with:
path: all-results/
pattern: codeql-*-results
merge-multiple: true
- name: Generate security review summary
run: |
echo "## CodeQL Security Scan Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Scan completed at:** $(date -u '+%Y-%m-%d %H:%M:%S UTC')" >> $GITHUB_STEP_SUMMARY
echo "**Triggered by:** ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY
echo "**Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Rust Contracts" >> $GITHUB_STEP_SUMMARY
if [ -d "all-results/rust-results" ]; then
echo "Results available in CodeQL security tab." >> $GITHUB_STEP_SUMMARY
else
echo "No Rust results generated." >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "### TypeScript (Frontend + Backend)" >> $GITHUB_STEP_SUMMARY
if [ -d "all-results/ts-results" ]; then
echo "Results available in CodeQL security tab." >> $GITHUB_STEP_SUMMARY
else
echo "No TypeScript results generated." >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Next Steps" >> $GITHUB_STEP_SUMMARY
echo "1. Review any alerts in the GitHub Security tab" >> $GITHUB_STEP_SUMMARY
echo "2. Triage findings by severity (error > warning > note)" >> $GITHUB_STEP_SUMMARY
echo "3. Address critical/high findings before merge" >> $GITHUB_STEP_SUMMARY
- name: Notify Slack on security findings
if: failure()
env:
SLACK_WEBHOOK_URL: ${{ secrets.SECURITY_SLACK_WEBHOOK_URL }}
run: |
if [ -z "$SLACK_WEBHOOK_URL" ]; then
echo "SECURITY_SLACK_WEBHOOK_URL secret not set; skipping notification."
exit 0
fi
text="🔍 CodeQL scan completed on *${GITHUB_REPOSITORY}* (${GITHUB_REF_NAME}). Review security findings in the GitHub Security tab."
payload=$(jq -n --arg text "$text" '{text: $text}')
curl --fail --silent --show-error -X POST \
-H "Content-Type: application/json" \
--data "$payload" \
"$SLACK_WEBHOOK_URL"