Repository navigation
160 lines (141 loc) · 5.59 KB
/
Copy pathsecurity-scan.yml
File metadata and controls
160 lines (141 loc) · 5.59 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
name: Security Scan
on:
push:
branches:
- '**'
pull_request:
branches:
- '**'
schedule:
# Run daily at 06:00 UTC so new CVEs are caught even without a push
- cron: '0 6 * * *'
permissions:
contents: read
security-events: write # required to upload SARIF results to GitHub Security tab
jobs:
# ── 1. Trivy full-repo scan ──────────────────────────────────────────────────
# Trivy (Aqua Security) scans the entire codebase for:
# - OS/library CVEs (SCA)
# - Leaked secrets / hardcoded credentials
# - Misconfigurations (IaC, Docker, GitHub Actions)
# - Supply-chain issues (compromised packages / domains)
#
# NOTE: trivy-action had a supply chain incident 2026-03-19 where 76/77
# version tags were force-pushed to credential-stealing malware. v0.36.0
# (released 2026-04-22, after the incident was remediated) is the current
# clean release. For maximum protection, pin this to the full commit SHA:
# gh api repos/aquasecurity/trivy-action/git/ref/tags/v0.36.0 --jq .object.sha
trivy-scan:
name: Trivy — filesystem, secrets & misconfig
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Run Trivy (SARIF report)
uses: aquasecurity/trivy-action@v0.36.0
with:
scan-type: 'fs'
scan-ref: '.'
format: 'sarif'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
scanners: 'vuln,secret,misconfig'
exit-code: '0' # don't fail the step — upload SARIF first
limit-severities-for-sarif: 'true'
- name: Upload Trivy SARIF to GitHub Security tab
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: 'trivy-results.sarif'
category: 'trivy'
- name: Fail on CRITICAL/HIGH findings
uses: aquasecurity/trivy-action@v0.36.0
with:
scan-type: 'fs'
scan-ref: '.'
format: 'table'
severity: 'CRITICAL,HIGH'
scanners: 'vuln,secret,misconfig'
exit-code: '1'
# ── 2. Python dependency CVE audit ──────────────────────────────────────────
pip-audit:
name: pip-audit — Python dependency CVEs
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: '3.13'
- name: Install package + pip-audit
run: |
pip install --upgrade pip
pip install pip-audit
pip install -e ".[dev,docs]" --ignore-requires-python 2>/dev/null || \
pip install -e "." --ignore-requires-python 2>/dev/null || true
- name: Audit Python dependencies
run: pip-audit --desc --output-format markdown 2>&1 | tee pip-audit-results.md
continue-on-error: false
# ── 3. Bandit — Python SAST ─────────────────────────────────────────────────
bandit:
name: Bandit — Python static security analysis
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-python@v7
with:
python-version: '3.13'
- name: Install Bandit + SARIF formatter
# bandit-sarif-formatter registers the 'sarif' output format as a plugin
run: pip install "bandit[toml]" bandit-sarif-formatter
- name: Run Bandit (SARIF report)
# --exit-zero ensures the file is always written even when findings exist;
# a separate step below gates the build on HIGH severity.
run: |
bandit -r src/ \
--severity-level medium \
--confidence-level medium \
--format sarif \
--output bandit-results.sarif \
--exit-zero
- name: Upload Bandit SARIF to GitHub Security tab
uses: github/codeql-action/upload-sarif@v4
if: always()
with:
sarif_file: 'bandit-results.sarif'
category: 'bandit'
- name: Fail on HIGH severity findings
run: |
bandit -r src/ \
--severity-level high \
--confidence-level medium \
--format txt
# ── 4. Banned / compromised CDN domain check ────────────────────────────────
# Belt-and-suspenders grep to catch compromised CDN domains before they
# reach the built docs or runtime JavaScript.
banned-cdn-check:
name: Banned CDN domain check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Check for known-compromised CDN domains
run: |
BANNED=(
"polyfill\.io"
"bootcss\.com"
"bootcdn\.net"
"freecdn\.cn"
)
FOUND=0
for pat in "${BANNED[@]}"; do
hits=$(grep -rn -E "$pat" \
--include="*.yml" --include="*.yaml" \
--include="*.html" --include="*.js" --include="*.ts" \
--include="*.py" --include="*.md" --include="*.json" \
--exclude="security-scan.yml" \
. 2>/dev/null || true)
if [ -n "$hits" ]; then
echo "::error::Banned CDN pattern '$pat' found:"
echo "$hits"
FOUND=1
fi
done
[ "$FOUND" -eq 0 ] && echo "OK: no banned CDN domains." || exit 1