blob: d8f02dfd18c6fea607ffe8010b99bc199e018a7f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
#!/bin/sh
# Fail if the tree contains anything that looks like a secret. Used by export.sh and by buildbot.
R=${1:-.}
bad=0
check() { # description, extended regex
if grep -rIEn --exclude-dir=.git --exclude-dir=tests --exclude=scan-secrets.sh --exclude=export.sh --exclude=export-secrets.sh -e "$2" "$R" >/tmp/scan.$$ 2>/dev/null; then
echo "SECRET? $1:"; sed 's/^\(.\{0,160\}\).*/ \1/' /tmp/scan.$$ | head -5; bad=1; fi
}
check "private key block" 'BEGIN [A-Z ]*PRIVATE KEY'
check "password hash" '\{(SSHA|SSHA512|SHA|CRYPT|MD5)\}[A-Za-z0-9+/=]{10,}|\$(1|2[aby]|5|6|y)\$[A-Za-z0-9./$]{8,}'
check "password assignment" '^[[:space:]]*(rootpw|bindpw|credentials|userPassword|password)[[:space:]=:]+[^<@[:space:]#]'
check "snmp community / token" 'community[^#]*[0-9a-f]{16,}|[0-9a-f]{24,}@[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+'
check "api token / .git-credentials" 'https?://[^/@[:space:]]+:[^/@[:space:]]+@'
rm -f /tmp/scan.$$
[ $bad = 0 ] && echo "secret scan: clean" || { echo "secret scan: FAILED"; exit 1; }
|