swadhinbiswas Scrub committed API keys and personal paths; enforce secret scan pre-commit · 8/24/2026
70bd3af
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
#!/bin/bash
# de-omarchy secret scan — run before EVERY commit/push (see SECURITY.md).
# Uses gitleaks when available, plus manual greps for what scanners miss.
set -u
cd "$(dirname "${BASH_SOURCE[0]}")/.."
HITS=0
fail() { echo " [SECRET?] $*"; HITS=$((HITS+1)); }
echo "== gitleaks =="
if command -v gitleaks >/dev/null 2>&1; then
gitleaks detect --source . --no-banner -v || echo " gitleaks clean"
else
echo " gitleaks not installed — install it: pacman -S gitleaks"
fi
echo "== manual greps =="
PATTERNS=(
'BEGIN OPENSSH PRIVATE KEY' 'BEGIN RSA PRIVATE KEY' 'BEGIN EC PRIVATE KEY'
'BEGIN PGP PRIVATE KEY'
'ANTHROPIC_AUTH_TOKEN=' 'ANTHROPIC_API_KEY='
'(password|passwd|psk)\s*=\s*["'"'"'][^"'"'"']{4,}'
'Bearer [A-Za-z0-9_\-\.]{10,}'
'Authorization:'
'AKIA[0-9A-Z]{16}'
'ghp_[A-Za-z0-9]{30,}' 'github_pat_'
'sk-[A-Za-z0-9]{20,}'
'"apiKey":\s*"[^"{]' # any literal API key in JSON — env refs ({env:…}) pass
'\bix_[a-f0-9]{32,}\b' # provider-specific key prefixes (InferX et al)
'/home/[a-z0-9_]+' # hardcoded real usernames must not appear
)
for p in "${PATTERNS[@]}"; do
# shellcheck disable=SC2086
while IFS=: read -r file line _; do
case $file in
.git/*|audit/system-fingerprint.md) continue ;; # fingerprint is scrubbed by design
esac
fail "$file:$line matches /$p/"
done < <(grep -rInE "$p" . --exclude-dir=.git --exclude-dir=node_modules \
--exclude-dir=.claude --exclude-dir=.understand-anything \
--exclude=KEYMAP.md --exclude=MAPPING.md --exclude=AUDIT.md \
--exclude="$(basename "${BASH_SOURCE[0]}")" 2>/dev/null \
| grep -v '/home/user') # generic doc placeholder, not a real username
done
echo "== sensitive paths that must never be vendored =="
for p in .ssh id_rsa id_ed25519 known_hosts .netrc docker/config.json .aws gh/hosts.yml; do
found=$(find . -path ./.git -prune -o -name "*$p*" -print 2>/dev/null | head -3)
[[ -n $found ]] && fail "sensitive path present: $found"
done
echo "== result: $HITS potential hits =="
exit $(( HITS > 0 ))