-
Notifications
You must be signed in to change notification settings - Fork 0
348 lines (296 loc) · 10.2 KB
/
Copy pathsecurity.yml
File metadata and controls
348 lines (296 loc) · 10.2 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
name: Security Scan
on:
push:
branches: [ main, dev, develop ]
pull_request:
branches: [ main, dev, develop ]
schedule:
# Run security scans daily at 2 AM UTC
- cron: '0 2 * * *'
jobs:
dependency-scan:
name: Dependency Security Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pip-audit
- name: Run pip-audit on locked requirements
# CVE-2025-3000: memory corruption in torch.jit.script, local-host attack
# only, no patched torch release exists. torch is a transitive dependency
# (transformers / sentence-transformers) and the app never calls
# torch.jit.script on any input — not reachable. Accepted-risk suppression;
# revisit when an upstream fix ships. See TODO.md "CI And Security Evidence".
run: |
pip-audit -r requirements.txt --desc --format json --output pip-audit-report.json --ignore-vuln CVE-2025-3000
- name: Upload dependency scan report
uses: actions/upload-artifact@v5
with:
name: pip-audit-report
path: pip-audit-report.json
npm-audit:
name: NPM Security Audit
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
- name: Run npm audit
env:
# npm audit only needs the dependency tree, not the binaries. Skipping
# the electron/chromedriver postinstall downloads keeps this job from
# flaking on transient CDN errors (e.g. HTTP 502 from electron install.js).
ELECTRON_SKIP_BINARY_DOWNLOAD: 1
CHROMEDRIVER_SKIP_DOWNLOAD: true
run: |
cd frontend
npm ci
npm audit --audit-level=high --json > ../npm-audit.json
cat ../npm-audit.json
- name: Upload npm audit report
uses: actions/upload-artifact@v5
with:
name: npm-audit-report
path: npm-audit.json
code-security:
name: Code Security Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Install bandit
run: pip install bandit[toml]
- name: Run Bandit full report
run: |
bandit -r backend/ core/ --exit-zero -f json -o bandit-full-report.json
- name: Validate Bandit baseline exists
run: |
test -f .bandit-baseline.json
- name: Normalize Bandit baseline paths
run: |
python - <<'PY'
import json
from pathlib import Path
source = Path(".bandit-baseline.json")
target = Path(".bandit-baseline.ci.json")
data = json.loads(source.read_text())
metrics = data.get("metrics", {})
data["metrics"] = {
key.replace("\\", "/") if key != "_totals" else key: value
for key, value in metrics.items()
}
for result in data.get("results", []):
filename = result.get("filename")
if isinstance(filename, str):
result["filename"] = filename.replace("\\", "/")
target.write_text(json.dumps(data, indent=2, sort_keys=True) + "\n")
PY
- name: Run Bandit delta gate (new high-confidence issues)
run: |
bandit -r backend/ core/ -b .bandit-baseline.ci.json --exit-zero -f json -o bandit-report.json
bandit -r backend/ core/ -b .bandit-baseline.ci.json -ll -ii -f screen
- name: Upload Bandit report
uses: actions/upload-artifact@v5
with:
name: bandit-report
path: |
bandit-report.json
bandit-full-report.json
secret-scan:
name: Secret Scanning
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Resolve TruffleHog diff range
if: github.event_name != 'schedule'
id: trufflehog-diff
uses: actions/github-script@v7
with:
script: |
const before = context.payload.before || '';
const isZero = /^0+$/.test(before);
let base = before;
if (context.eventName === 'pull_request') {
base = context.payload.pull_request.base.sha;
} else if (!base || isZero) {
const commits = (await github.rest.repos.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 2,
sha: context.sha,
})).data;
base = commits.length > 1 ? commits[commits.length - 1].sha : context.sha;
}
core.setOutput('base', base);
core.setOutput('head', context.eventName === 'pull_request'
? context.payload.pull_request.head.sha
: context.sha);
- name: TruffleHog OSS (push/pr diff)
if: github.event_name != 'schedule'
uses: trufflesecurity/trufflehog@v3.93.1
with:
path: ./
base: ${{ steps.trufflehog-diff.outputs.base }}
head: ${{ steps.trufflehog-diff.outputs.head }}
extra_args: --debug --only-verified
- name: TruffleHog OSS (scheduled full scan)
if: github.event_name == 'schedule'
uses: trufflesecurity/trufflehog@v3.93.1
with:
path: ./
extra_args: --debug --only-verified
codeql-analysis:
name: CodeQL Analysis
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
strategy:
matrix:
language: [ 'python', 'javascript' ]
steps:
- name: Checkout repository
uses: actions/checkout@v6
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
- name: Autobuild
uses: github/codeql-action/autobuild@v4
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
sbom:
name: SBOM Generation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Install CycloneDX tools
run: pip install cyclonedx-bom
- name: Generate Backend SBOM
run: |
if [ -f requirements-enterprise.txt ]; then
cyclonedx-py requirements requirements-enterprise.txt --output-file sbom-backend.json
else
cyclonedx-py requirements requirements.txt --output-file sbom-backend.json
fi
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: '24'
- name: Generate Frontend SBOM
run: |
if [ -f frontend/package-lock.json ]; then
cd frontend
npx @cyclonedx/cyclonedx-npm --package-lock-only --ignore-npm-errors --output-file ../sbom-frontend.json
fi
- name: Upload SBOMs
uses: actions/upload-artifact@v5
with:
name: sbom-reports
path: |
sbom-backend.json
sbom-frontend.json
if-no-files-found: error
artifact-signing:
name: Artifact Signing (Cosign)
needs: [sbom]
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
permissions:
contents: read
id-token: write
steps:
- name: Download SBOM artifacts
uses: actions/download-artifact@v5
with:
name: sbom-reports
path: .
- name: Install Cosign
uses: sigstore/cosign-installer@v4.0.0
- name: Sign SBOM artifacts (keyless OIDC)
env:
COSIGN_EXPERIMENTAL: "1"
run: |
set +e
cosign version
test -f sbom-backend.json
cosign sign-blob --yes sbom-backend.json \
--output-signature sbom-backend.json.sig \
--output-certificate sbom-backend.json.pem
backend_status=$?
if [ "$backend_status" -ne 0 ]; then
echo "::warning::Cosign SBOM signing is unavailable for this run; continuing without signatures."
rm -f sbom-backend.json.sig sbom-backend.json.pem sbom-frontend.json.sig sbom-frontend.json.pem
exit 0
fi
if [ -f sbom-frontend.json ]; then
cosign sign-blob --yes sbom-frontend.json \
--output-signature sbom-frontend.json.sig \
--output-certificate sbom-frontend.json.pem
frontend_status=$?
if [ "$frontend_status" -ne 0 ]; then
echo "::warning::Cosign frontend SBOM signing failed; backend SBOM signature was preserved."
rm -f sbom-frontend.json.sig sbom-frontend.json.pem
fi
fi
- name: Upload signing artifacts
uses: actions/upload-artifact@v5
with:
name: sbom-signatures
path: |
sbom-backend.json.sig
sbom-backend.json.pem
sbom-frontend.json.sig
sbom-frontend.json.pem
if-no-files-found: warn
crash-reporting-probe:
name: Crash Reporting Probe
runs-on: ubuntu-latest
if: github.event_name == 'schedule' || github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v6
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Check crash reporting configuration
id: crash-reporting-config
env:
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
run: |
if [ -n "$SENTRY_DSN" ]; then
echo "configured=true" >> "$GITHUB_OUTPUT"
else
echo "configured=false" >> "$GITHUB_OUTPUT"
echo "::notice::SENTRY_DSN is not configured; skipping crash-reporting probe."
fi
- name: Send Sentry probe event
if: steps.crash-reporting-config.outputs.configured == 'true'
env:
SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
FLASK_ENV: "production"
APP_VERSION: "security-workflow-probe"
run: |
python scripts/send_sentry_test_event.py --message "DataLogicEngine security workflow crash probe" --tag source=security --tag workflow=security