Detect, migrate, and prevent hardcoded secrets from being leaked to GitHub.
A security tool that scans your codebase for accidentally hardcoded API keys, tokens, and other secrets that should be stored in environment variables instead. Prevent credential leaks before they reach your repository.
Accidentally committing API keys, tokens, or passwords to GitHub is a common security mistake that can lead to:
- Unauthorized access to your services and data
- Financial loss from compromised cloud accounts
- Data breaches exposing customer information
- Account suspension by service providers
Secrets Sentry helps you:
- ✅ Find hardcoded secrets in your code before they reach GitHub
- ✅ Automatically refactor code to use environment variables
- ✅ Block future commits containing secrets with pre-commit hooks
- ✅ Scan git history for previously leaked secrets
- Scan code and git history for leaked secrets (entropy + patterns + heuristics)
- Auto-migrate hardcoded secrets to environment variables and refactor code automatically
- Pre-commit hooks block new secrets from being committed to GitHub
- Web dashboard for viewing findings and managing settings
- Notifications via Slack/Discord webhooks
- Automated reports and branch/PR creation with fixes
pip install -r requirements.txt# Scan working tree only
python -m scripts.scan
# Scan including git history (last 100 commits)
python -m scripts.scan --history
# Scan with custom commit depth
python -m scripts.scan --history --depth 50python -m scripts.install_hookpython -m scripts.serve
# Or with custom port
python -m scripts.serve --port 3000Visit http://localhost:8000 to view the dashboard.
# Interactive mode (confirms each fix)
python -m scripts.fix
# Auto mode (fixes all without confirmation)
python -m scripts.fix --autoSettings are stored in data/settings.json:
{
"entropyThreshold": 4.0,
"minTokenLength": 20,
"historyDepth": 100,
"excludePatterns": [
"node_modules/**",
".venv/**",
"dist/**",
"build/**"
],
"webhooks": {
"slack": "https://hooks.slack.com/services/...",
"discord": "https://discord.com/api/webhooks/..."
},
"notifications": {
"enabled": true,
"channels": ["slack", "discord"]
}
}Secrets Sentry detects 10+ types of secrets:
- AWS Access Keys & Secret Keys
- OpenAI API Keys
- Slack Tokens
- Discord Tokens
- GitHub Personal Access Tokens
- JWT Tokens
- Private Keys (RSA, EC, OpenSSH)
- Firebase API Keys
- Stripe API Keys
- Twilio Auth Tokens
- Generic high-entropy secrets
- Detection: Uses Shannon entropy calculation, regex patterns, and filename heuristics to find hardcoded secrets
- Migration: Generates SCREAMING_SNAKE_CASE env var names, refactors code to use
os.environorprocess.env - Guidance: Provides instructions to add secrets to your environment variables (
.envfile, system env, or hosting platform) - Prevention: Pre-commit hook scans staged files and blocks commits containing secrets before they reach GitHub
The web dashboard provides:
- Summary tiles (scans run, leaks found, fixed, remaining)
- Findings table with filters
- Settings management
- Webhook testing
- "Run Scan Now" button for on-demand scans
Configure Slack and Discord webhooks to receive scan completion notifications:
- Create an incoming webhook in Slack or Discord
- Add the webhook URL to
data/settings.jsonor via the dashboard - Test the webhook using the "Test Webhook" button
The pre-commit hook:
- Runs automatically before each commit
- Scans staged files for secrets
- Blocks commit if secrets are detected
- Provides clear error messages with remediation steps
To override in emergencies:
git commit --allow-once "Emergency hotfix for production incident #123"Scan reports are saved to reports/scan_<timestamp>.md and include:
- Summary statistics
- Detailed findings table (with redacted snippets)
- Redacted code diffs
- List of created environment variables
- Next steps for remediation
After running a fix, Secrets Sentry:
- Creates a new branch:
chore/secret-migration-<date> - Commits atomic changes with descriptive messages
- Optionally creates a PR (if GitHub integration is configured)
See CONTRIBUTING.md for development setup and guidelines.
MIT License - see LICENSE file.
- project.md - Full project specification
- GitHub Security Best Practices
- OWASP Secrets Management
For issues, questions, or contributions, please see CONTRIBUTING.md.