Skip to content

About

Dependency-free secrets scanner: regex rules plus Shannon entropy, redaction and CI-friendly exit codes. Stdlib only.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

secretscan

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.

Why

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.

Usage

python3 secretscan.py <path> [options]

Examples

# 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

Options

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

What it detects

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.

Use in CI

secretscan exits 1 when it finds anything, so a GitHub Actions step is just:

- name: Scan for secrets
  run: python3 secretscan.py . --exclude tests

Or 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
}

Roadmap

  1. secretscan (this repo) - pattern + entropy scanning with redaction.
  2. Git history scanning - walk past commits, not just the working tree.
  3. Baseline / allowlist file - acknowledge known false positives once.
  4. Verified detection - test-call live APIs to confirm a credential is active.
  5. Pre-commit and GitHub Action packaging for one-line adoption.

Notes

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."

About

Dependency-free secrets scanner: regex rules plus Shannon entropy, redaction and CI-friendly exit codes. Stdlib only.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages