A dependency-free secrets scanner. Standard library only, no pip install. It
walks a file or directory tree and flags hardcoded credentials using a set of
named pattern rules plus a Shannon-entropy check for generic high-entropy
strings. Matched secrets are redacted in the output, and the process exits
non-zero when anything is found, so it drops straight into a CI pipeline or a
pre-commit hook.
Leaked credentials in source control are one of the most common ways cloud accounts get popped. I wanted a small, auditable scanner I could read in one sitting and wire into a pipeline, rather than a black box. It pairs with my aws-iam-privesc-finder: one keeps secrets out of the repo, the other checks what those credentials can do once they exist.
python3 secretscan.py <path> [options]# Scan the current project
python3 secretscan.py .
# Scan a directory, skip the tests folder, raise the entropy bar
python3 secretscan.py src/ --exclude tests --min-entropy 4.5
# Machine-readable output
python3 secretscan.py config.yaml --json| Flag | Description | Default |
|---|---|---|
-x, --exclude |
Skip paths containing this substring (repeatable) | none |
--min-entropy |
Entropy threshold for generic strings | 4.3 |
--no-entropy |
Disable the high-entropy string check | off |
--json |
Emit results as JSON | off |
AWS access keys and secret keys, GitHub tokens (classic and fine-grained),
Slack tokens and webhooks, Google API keys, Stripe live keys, JSON Web Tokens,
PEM private keys, and generic secret = "..." style assignments. A Shannon
-entropy pass catches high-randomness strings that no named rule covers.
Obvious placeholders (example, your_api_key, changeme, <...>) are
filtered out to keep the signal-to-noise ratio sane.
secretscan exits 1 when it finds anything, so a GitHub Actions step is just:
- name: Scan for secrets
run: python3 secretscan.py . --exclude testsOr as a pre-commit hook (.git/hooks/pre-commit):
#!/bin/sh
python3 /path/to/secretscan.py . || {
echo "secretscan blocked the commit. Remove the secret or use an env var."
exit 1
}- secretscan (this repo) - pattern + entropy scanning with redaction.
- Git history scanning - walk past commits, not just the working tree.
- Baseline / allowlist file - acknowledge known false positives once.
- Verified detection - test-call live APIs to confirm a credential is active.
- Pre-commit and GitHub Action packaging for one-line adoption.
This is a heuristic tool. It will miss secrets that match no rule and stay below the entropy threshold, and it will occasionally flag something benign. Treat a clean run as "no obvious secrets," not "definitely none."