Skip to main content

secret-guard

A zero-dependency secret scanner for Python, CI, and pre-commit hooks.

Detect AWS keys, GitHub tokens, private keys, and hundreds of other secrets before they reach your git history.

CI secret-guard scan PyPI - Version PyPI - Python Versions License: MIT


What it does

secret-guard scans source files for hardcoded credentials using 13 pattern rules plus Shannon-entropy detection, and reports each finding with a severity and a masked value. By default it never prints the secret itself.

Category Rules
Cloud / SaaS AWS Access Key IDs, AWS temporary & dashed keys, Google API Keys, Stripe live keys
Tokens GitHub PAT (classic & fine-grained), Slack tokens, Square access tokens, JWTs
Key material RSA / EC / DSA / OpenSSH / PGP private keys (CRITICAL)
Heuristics Generic secret keys, credential assignments, high-entropy strings

On top of pattern matching, secret-guard catches .env files with secret-looking variable names (.env, .env.local, prod.env, …). It reports the key name and severity but never the value.

Features

  • Zero runtime dependencies — pure Python, no network calls.
  • Masked by default — secret values are redacted in console and JSON output; --show-value is an explicit opt-in for recovery/rotation work.
  • Git-aware --staged: scans the git index blob, not the working tree, so it catches secrets that are staged but already deleted from disk.
  • gitignore-aware: skips .git, node_modules, venv, and whatever your .gitignore already covers; repeatable --exclude for anything else.
  • Entropy detection: flags high-entropy strings even when no rule matches.
  • Fast, single-file install: works in CI in one line.

Install

pip install secret-guard-scan

The CLI is secret-guard. You can also run the repo without installing (Python ≥ 3.8):

python -m secretguard

Quick start

# Scan the current directory
secret-guard scan

# Scan a specific path
secret-guard scan ./src

# JSON output for CI / tooling
secret-guard scan --json

# Only files staged for commit (reads the git index)
secret-guard scan --staged

# Guard every future commit with a git pre-commit hook
secret-guard install-hook

Example output

config.py:12 [HIGH    ] GitHub Token: ghp_**************
.env:4    [CRITICAL] Private Key: -----BEGIN [REDACTED]-----
app.py:40 [MEDIUM  ] Credential Assignment: password = 'hunter 2'

1 critical, 1 high, 1 medium, 0 low — 3 total

Values are masked by default. Use --show-value only when you actually need the full string — for example, to rotate the key you just found.

Usage

secret-guard scan [path] [options]

positional arguments:
  path              Path to scan (default: .)

options:
  --exclude DIR     Skip additional directory names (repeatable)
  --no-entropy      Disable high-entropy string detection
  --json            Output findings as JSON
  --show-value      Print full secret values (default masks them)
  --staged          Scan only files staged in git

Exit codes

  • 0 — no secrets found, or --help/--version
  • 1 — at least one secret detected (or an error occurred)

Use this in CI — the job fails the moment a secret shows up:

- name: Scan for secrets
  run: |
    pip install secret-guard-scan
    secret-guard scan . \
      --json \
      --exclude tests \
      --exclude .venv

Staged scanning

secret-guard scan --staged

reads each staged file directly from the git index (git show :<path>). This matters when a secret was added, staged, and then deleted from the working tree: a worktree-only scan would miss it, but the staged version caught by secret-guard is exactly what would otherwise be committed.

Local development

python -m unittest discover -s tests
python -m ruff check secretguard tests
python -m secretguard scan . --exclude tests --no-entropy

The repository enforces these in CI (tests on Python 3.9 / 3.11 / 3.13, lint, and a self-scan job) and runs GitGuardian on every pull request.

Contributing

Contributions of any size are welcome — new detection rules, false-positive reports, docs, editor integrations. Start with CONTRIBUTING. Please read our Code of Conduct and report security issues per our Security Policy.

Roadmap

  • Rule-based detection (cloud keys, tokens, private keys)
  • Entropy-based heuristics
  • .env support (.env, .env.*, *.env, *.env.*)
  • Masked output by default
  • Git-index-aware --staged scanning
  • git hook + pre-commit integration
  • OIDC trusted publishing to PyPI
  • Git history scanning
  • Baseline / allowlist support
  • SARIF output for GitHub code scanning
  • Custom rule manifests

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

secret_guard_scan-0.1.1.post1.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

secret_guard_scan-0.1.1.post1-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file secret_guard_scan-0.1.1.post1.tar.gz.

File metadata

  • Download URL: secret_guard_scan-0.1.1.post1.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for secret_guard_scan-0.1.1.post1.tar.gz
Algorithm Hash digest
SHA256 ef7e2e96ec1133efe709c389c237b693f8262fb529fba3451468fd606a5602d4
MD5 660d091965ed731b2392c6a9ca8485f5
BLAKE2b-256 2d5f0fb4c8f13f961e61b5da524e6f88e5833d3c9331d532e0ed49af7daf9c1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for secret_guard_scan-0.1.1.post1.tar.gz:

Publisher: publish.yml on taksh1507/secret-guard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file secret_guard_scan-0.1.1.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for secret_guard_scan-0.1.1.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 3b365ba22bb93ba9d6759ec38b59c9a91152dbb05c1ddae347cedf62d4db45b5
MD5 648fe420eeeb77ce4d03a5346eacbde2
BLAKE2b-256 b3a2e714c022f41071a48973c42499ebe9227fe7b6b0b07f5af12faa3fedb79b

See more details on using hashes here.

Provenance

The following attestation bundles were made for secret_guard_scan-0.1.1.post1-py3-none-any.whl:

Publisher: publish.yml on taksh1507/secret-guard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page