check-secrets.sh
Language Shell743 B20 lines
#!/usr/bin/env bash# Nothing that looks like a real credential is committed. Keys live in the# OS keychain; tests use the stand-in and fake keys ("good-key", "bad-key").set -euo pipefailcd "$(dirname "$0")/.."patterns=('sk-[A-Za-z0-9_-]{20,}''hf_[A-Za-z0-9]{30,}''ghp_[A-Za-z0-9]{30,}''github_pat_[A-Za-z0-9_]{40,}''AKIA[0-9A-Z]{16}''-----BEGIN [A-Z ]*PRIVATE KEY-----''[Bb]earer [A-Za-z0-9._-]{32,}')hit=0for p in "${patterns[@]}"; doif git ls-files -z | grep -zv 'package-lock.json\|Cargo.lock' | xargs -0 grep -nIE -e "$p" -- 2>/dev/null; then hit=1; fidoneif git ls-files | grep -E '(^|/)\.env($|\.)' ; then hit=1; fi[ "$hit" = 0 ] && echo "no secrets" || { echo "Possible secrets above." >&2; exit 1; }