Skip to content

Commit 30d64a7

Browse files
Add CI secret-scan safeguard (blocks secrets/private-IPs/key-files on push+PR)
1 parent d3250b9 commit 30d64a7

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: security-scan
2+
3+
# Repo-level safeguard: every push and PR is scanned for committed secrets,
4+
# private IPs and key/.env files. A hit fails the check and blocks the merge.
5+
# Patterns are generic (API-key/token/private-key formats, RFC1918 ranges) so
6+
# the workflow itself carries no sensitive data. No untrusted event input is
7+
# used in run: steps (injection-safe).
8+
9+
on:
10+
push:
11+
branches: [main, master]
12+
pull_request:
13+
14+
jobs:
15+
secret-scan:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 0
21+
- name: Scan for committed secrets
22+
run: |
23+
PAT='(sk-[A-Za-z0-9]{20,}|ghp_[A-Za-z0-9]{36}|gho_[A-Za-z0-9]{36}|github_pat_[A-Za-z0-9_]{50,}|AKIA[0-9A-Z]{16}|AIza[0-9A-Za-z_-]{35}|xox[baprs]-[A-Za-z0-9-]{10,}|-----BEGIN [A-Z ]*PRIVATE KEY-----|hf_[A-Za-z0-9]{30,}|nvapi-[A-Za-z0-9_-]{20,}|glpat-[A-Za-z0-9_-]{20,})'
24+
if grep -rIEn "$PAT" --exclude-dir=.git --exclude-dir=.github . ; then
25+
echo "::error::Potential secret/token detected — push blocked."; exit 1
26+
fi
27+
echo "OK: no secret/token patterns."
28+
- name: Scan for private IPs
29+
run: |
30+
IP='(^|[^0-9.])(10\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}|192\.168\.[0-9]{1,3}\.[0-9]{1,3}|172\.(1[6-9]|2[0-9]|3[01])\.[0-9]{1,3}\.[0-9]{1,3})'
31+
if grep -rIEn "$IP" --include='*.py' --include='*.json' --include='*.md' --include='*.yaml' --include='*.yml' --include='*.txt' --include='*.html' --include='*.js' --exclude-dir=.git --exclude-dir=.github . ; then
32+
echo "::error::Private (RFC1918) IP detected — push blocked. Use 192.0.2.0/24 in examples."; exit 1
33+
fi
34+
echo "OK: no private IPs."
35+
- name: Scan for secret/key/weight files
36+
run: |
37+
HITS=$(find . -path ./.git -prune -o -type f \( -name '*.key' -o -name '*.pem' -o -name '.env' -o -name '*.safetensors' -o -name '*.gguf' \) -print | grep -v '.env.example' || true)
38+
if [ -n "$HITS" ]; then
39+
echo "::error::Secret/key/weight file committed — push blocked:"; echo "$HITS"; exit 1
40+
fi
41+
echo "OK: no key/.env/weight files."

0 commit comments

Comments
 (0)