Skip to main content

CLI tool to detect leaked secrets and API keys in codebases and public GitHub repos — including git history

Project description

secret-scanner

A CLI tool that scans local codebases and public GitHub repos for leaked API keys and secrets — including secrets deleted from code but still alive in git history.

demo

Features

Detection

  • 55+ regex patterns: AWS, GitHub, GitLab, Stripe, OpenAI, Anthropic, Slack, Twilio, Discord, Telegram, npm, PyPI, Shopify, DigitalOcean, Dropbox, Notion, Linear, Terraform, Vault, New Relic, Mapbox, Square, Mailchimp, and more
  • Shannon entropy detection for unquoted values (.env, YAML, INI files)
  • Inline suppression: # nosec, # gitleaks:allow, # secretscanner:allow
  • AWS Access Key ID pattern anchored to real prefixes (AKIA, AGPA, AROA, etc.) — no false positives on random uppercase strings

Verification

  • --verify makes live API calls to check if found secrets are still active
  • Supports: GitHub, GitLab, Stripe, OpenAI, Anthropic, HuggingFace, SendGrid, Slack, npm, Replicate

Scanning scope

  • Local file trees (parallel, 8 threads)
  • Git history: commits, any branch, with --since DATE for date-bounded scans
  • GitHub profile: all public repos for a user or org
  • GitHub repo by URL: secrets scan https://github.com/owner/repo
  • GitHub Gists: --include-gists

CI/CD integration

  • Exit code 1 on any CRITICAL or HIGH finding
  • SARIF output for GitHub Security tab / GitLab SAST
  • Baseline mode: save known findings, only alert on new secrets
  • Pre-commit hook with automatic baseline support
  • .secretignore with full ** glob support

Output formats

  • Terminal (rich table with severity colors)
  • JSON (with fingerprints and verification status)
  • CSV
  • SARIF 2.1.0
  • Markdown disclosure report

Installation

pip install leakscan

Or from source:

git clone https://github.com/Vasishta03/secret-scanner
cd secret-scanner
pip install -e .

Usage

Basic local scan

secrets scan ./myproject
secrets scan . --severity HIGH --no-entropy

Scan git history (catches deleted secrets)

secrets scan . --history
secrets scan . --history --depth 500 --since 2023-01-01
secrets scan . --history --branch main

Verify secrets are live

secrets scan . --verify
secrets scan . --verify --severity HIGH

Scan a public GitHub repo by URL

secrets scan https://github.com/owner/repo
secrets scan https://github.com/owner/repo --history --verify

Scan a GitHub user's repos and gists

secrets scan --github username
secrets scan --github username --include-gists
secrets scan --github username --history --token $GITHUB_TOKEN

Baseline mode (CI-friendly: only alert on new findings)

secrets scan . --save-baseline .secrets.baseline
secrets scan . --baseline .secrets.baseline

Output formats

secrets scan . --format json --output results.json
secrets scan . --format csv  --output findings.csv
secrets scan . --format sarif --output results.sarif
secrets scan --github username --format disclosure --output report.md

Redact secrets in output (safe for shared logs)

secrets scan . --redact
secrets scan . --format json --redact --output safe-results.json

Install as pre-commit hook

cd your-git-repo
secrets install-hook

The hook uses .secrets.baseline automatically if present, suppressing already-known findings.

To suppress a specific line: add # nosec or # gitleaks:allow to the line.

.secretignore

Create .secretignore in your project root to exclude paths:

tests/fixtures/**
vendor/**
*.example
docs/

Supports full ** glob syntax (like .gitignore).

GitHub Actions

- name: Scan for secrets
  run: secrets scan . --severity HIGH --no-entropy --format sarif --output results.sarif

- name: Upload SARIF
  uses: github/codeql-action/upload-sarif@v3
  with:
    sarif_file: results.sarif

Severity levels

Level Examples
CRITICAL Private keys (RSA/EC/PGP/OpenSSH/PKCS#8), AWS credentials, Azure storage keys
HIGH GitHub/GitLab tokens, Stripe live keys, OpenAI/Anthropic keys, Slack tokens, npm/PyPI tokens, Telegram/Discord bots
MEDIUM Generic API keys, hardcoded passwords, JWT tokens, database URLs, Stripe test keys
LOW High-entropy strings (possible unknown secrets)

Why history scanning matters

Deleting a secret from your latest commit does not remove it from git history. Anyone who clones your repo can run git log -p and recover it. Most scanners miss this completely.

# Find secrets that were committed at any point in the last year
secrets scan . --history --depth 1000 --since 2024-01-01

Architecture

scanner/
  cli.py           entry point (click)
  engine.py        file walker, parallel scanner, git history, shared kernel
  patterns.py      55+ regex patterns
  entropy.py       Shannon entropy scorer (quoted + unquoted values)
  verifier.py      live API verification (10 services)
  baseline.py      save/load/compare baseline fingerprints
  reporter.py      terminal/JSON/CSV/SARIF/disclosure output
  ignorefile.py    .secretignore parser with ** glob support
  github/
    fetcher.py     GitHub API client: repos, gists, commit history

Contributing

git clone https://github.com/Vasishta03/secret-scanner
cd secret-scanner
pip install -e ".[dev]"
pytest tests/

To add a pattern: edit scanner/patterns.py and add a test in tests/test_scanner.py.

License

MIT

Project details


Download files

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

Source Distribution

leakscan-0.2.0.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

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

leakscan-0.2.0-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file leakscan-0.2.0.tar.gz.

File metadata

  • Download URL: leakscan-0.2.0.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for leakscan-0.2.0.tar.gz
Algorithm Hash digest
SHA256 341d4bdb6ec1735d761637a3b6d0fee3ba0ce8b6c48c76e50bb63e7db646c145
MD5 8f3a72955ac9763fd84f4bf765264087
BLAKE2b-256 c67add7677edcd0373cad6f42ff6deb7d96afba5f57aec2d8a173acc71011649

See more details on using hashes here.

File details

Details for the file leakscan-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: leakscan-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for leakscan-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85ecb506d6be1cb5ea51cb25fa97c9d8e69ad13cc04ead365f8887d1242217f4
MD5 93ebbcb96fd711fdddc60d64a977e5ea
BLAKE2b-256 4f9891ad79a1d02e3de8c279089aa46c0a002756b43ce3d5d4c88d59569e18e4

See more details on using hashes here.

Supported by

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