A high-performance Go-based scanner that detects leaked secrets, API keys, tokens, and credentials in source code and Git history. Built for speed with concurrent workers, configurable patterns, and CI/CD integration through SARIF output.
- 🔍 Multi-pattern Detection: Pre-configured patterns for AWS keys, GitHub tokens, API keys, private keys, and more
- 🧮 Entropy Analysis: Advanced Shannon entropy calculations to detect high-entropy strings
- ⚡ Concurrent Scanning: Worker pool architecture for fast parallel file processing
- 📜 Git History: Deep scanning of Git repository history using go-git
- 🎯 Low False Positives: Entropy thresholds and pattern validation reduce noise
- 🚫 Allowlisting: Support for allowlisted secrets via configuration or files
- 📁 Ignore Patterns: Flexible file and directory exclusion (node_modules, vendor, etc.)
- 📊 Multiple Output Formats: Text, JSON, and SARIF for CI/CD integration
- ⚙️ Configurable: YAML/JSON configuration files with custom pattern support
- 🚀 CI/CD Ready: SARIF output integrates with GitHub Security, Azure DevOps, and more
git clone https://github.com/BaseMax/go-secret-hunter.git
cd go-secret-hunter
go build -o secret-hunter ./cmd/secret-huntergo install github.com/BaseMax/go-secret-hunter/cmd/secret-hunter@latestScan current directory for secrets:
secret-huntersecret-hunter --paths=/path/to/code,/another/pathsecret-hunter --git --verbosesecret-hunter --format=sarif --output=secrets-report.sarif# Generate example config
secret-hunter --generate-config=config.yaml
# Run with config
secret-hunter --config=config.yaml| Flag | Description | Default |
|---|---|---|
--config |
Path to configuration file (YAML or JSON) | - |
--paths |
Comma-separated paths to scan | . |
--format |
Output format: text, json, sarif | text |
--output |
Output file (default: stdout) | - |
--workers |
Number of concurrent workers | 4 |
--verbose |
Verbose output | false |
--git |
Include Git history scanning | false |
--allowlist |
Path to allowlist file | - |
--version |
Show version | - |
--generate-config |
Generate example config file | - |
Example config.yaml:
paths:
- .
- src/
include_git: true
max_depth: -1
workers: 8
ignore_patterns:
- node_modules/
- .git/
- vendor/
- '*.min.js'
- '*.lock'
- '*.log'
allowed_secrets:
- "EXAMPLE_NOT_A_REAL_SECRET"
file_extensions:
- .go
- .py
- .js
- .ts
- .java
- .env
- .yaml
- .json
output_format: sarif
output_file: secrets-report.sarif
verbose: true
custom_patterns:
- name: Custom API Key
pattern: 'custom_api_key[:=]\s*[''"]?([a-zA-Z0-9]{32})[''"]?'
description: Custom API Key Pattern
entropy: 3.5- AWS Access Keys (AKIA...)
- AWS Secret Keys
- GitHub Tokens (ghp_...)
- GitHub OAuth Tokens
- Google API Keys (AIza...)
- Google OAuth Client IDs
- Slack Tokens (xox...)
- Slack Webhooks
- Stripe API Keys
- Heroku API Keys
- Twilio API Keys
- NPM Tokens
- PyPI Tokens
- JWT Tokens
- Private Keys (RSA, SSH, PGP)
- Azure Client Secrets
- Docker Auth Tokens
- MailChimp API Keys
- MailGun API Keys
- Generic API Keys
- Generic Secrets/Passwords
- Generic Tokens
Add your own patterns in the configuration file:
custom_patterns:
- name: My Custom Secret
pattern: 'my_secret[:=]\s*[''"]?([a-zA-Z0-9]{20,})[''"]?'
description: Organization-specific secret pattern
entropy: 4.0 # Minimum entropy (0 = no entropy check)The scanner uses Shannon entropy to detect high-entropy strings that may be secrets:
- Entropy Score: Calculated as bits per character (0-8 scale)
- Thresholds: Configurable per pattern
- False Positive Reduction: Filters repeated patterns ("aaaa", "1111")
allowed_secrets:
- "NOT_A_REAL_SECRET"
- "EXAMPLE_KEY_FOR_TESTS"Create a file with one entry per line:
# allowlist.txt
NOT_A_REAL_SECRET
EXAMPLE_KEY_FOR_TESTS
test_api_key_12345
Use it:
secret-hunter --allowlist=allowlist.txtFound 3 potential secret(s):
[1] AWS Access Key
File: src/config.go:15:10
Description: AWS Access Key ID
Match: AKIAIOSFODNN7EXAMPLE
Entropy: 3.68
Context: awsKey := "AKIAIOSFODNN7EXAMPLE"
[
{
"type": "AWS Access Key",
"description": "AWS Access Key ID",
"file": "src/config.go",
"line": 15,
"column": 10,
"match": "AKIAIOSFODNN7EXAMPLE",
"context": "awsKey := \"AKIAIOSFODNN7EXAMPLE\"",
"entropy": 3.68
}
]Integrates with:
- GitHub Code Scanning
- Azure DevOps Security
- GitLab Security Dashboard
- Jenkins
- Many other CI/CD tools
Example usage with GitHub Actions:
- name: Run Secret Scanner
run: secret-hunter --format=sarif --output=secrets.sarif
- name: Upload SARIF
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: secrets.sarifname: Secret Scanning
on: [push, pull_request]
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Get full history for Git scanning
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Install Secret Hunter
run: go install github.com/BaseMax/go-secret-hunter/cmd/secret-hunter@latest
- name: Scan for Secrets
run: secret-hunter --git --format=sarif --output=secrets.sarif
- name: Upload Results
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: secrets.sarifsecret_scan:
stage: security
image: golang:1.21
script:
- go install github.com/BaseMax/go-secret-hunter/cmd/secret-hunter@latest
- secret-hunter --git --format=json --output=secrets.json
artifacts:
reports:
secret_detection: secrets.json- Concurrent Workers: Adjustable worker pool (default: 4)
- Binary Detection: Automatically skips binary files
- Smart Filtering: Ignore patterns reduce unnecessary scans
- Efficient Git: Uses go-git for optimized repository traversal
Example performance:
- ~1000 files/second on typical hardware
- Full Git history scan: depends on repository size
- Memory usage: ~50-100MB for most projects
- Use Allowlisting Carefully: Only allowlist confirmed false positives
- Scan Git History: Use
--gitflag to catch historical leaks - CI/CD Integration: Run on every commit and PR
- Configure Ignores: Exclude build artifacts, dependencies
- Custom Patterns: Add organization-specific secret patterns
- Review Findings: Manually verify high-priority findings
- Rotate Secrets: Immediately rotate any exposed credentials
0: No secrets found1: Secrets found or error occurred
go build -o secret-hunter ./cmd/secret-huntergo test ./...Edit internal/patterns/patterns.go to add new built-in patterns.
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
If you discover a security issue, please email security@example.com instead of using the issue tracker.
- Built with go-git for Git integration
- Inspired by tools like truffleHog, gitleaks, and git-secrets
- 📫 Issues: GitHub Issues
- 💬 Discussions: GitHub Discussions