Features β’ Demo β’ Installation β’ Usage β’ Rules β’ CI/CD β’ Contributing
Every week, thousands of developers accidentally push API keys, passwords, and credentials to public repositories.
The consequences:
- πΈ AWS keys exposed = bills of thousands of dollars in minutes
- π Database credentials leaked = full data breach
- π³ Stripe keys exposed = fraudulent transactions
- π€ OpenAI keys stolen = huge API costs
Secrets Detector scans your entire codebase and git history in seconds, finding these vulnerabilities before attackers do.
| Feature | Description |
|---|---|
| π 80+ Detection Rules | AWS, GitHub, Stripe, OpenAI, Slack, Firebase, and more |
| π 4 Severity Levels | Critical, High, Medium, Low |
| π 3 Output Formats | Console (colored), JSON, HTML report |
| π Git History Scan | Scan past commits for leaked secrets |
| π« Smart Filtering | Ignores placeholders and test values |
| π§ Remediation Tips | Each finding includes exact fix instructions |
| β‘ Zero Dependencies | Runs with standard Python β no heavy installs |
| π CI/CD Ready | GitHub Actions workflow included |
| π¨ HTML Reports | Beautiful dark-theme security reports |
$ python main.py scan --path ./my-project
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β π Secrets Detector v1.0 β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Scanning: ./my-project
π΄ CRITICAL (2 found)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Rule: AWS Access Key ID
File: src/config.py:14
Match: AKIA**************23
Fix: Revoke immediately at AWS Console β IAM β Security Credentials
Rule: OpenAI API Key
File: .env.backup:3
Match: sk-proj-********************xyz
Fix: Revoke at platform.openai.com/api-keys
π HIGH (1 found)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Rule: Stripe Secret Key
File: src/payment.py:8
Match: sk_live_**************abc
Fix: Rotate immediately at dashboard.stripe.com/apikeys
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π SCAN SUMMARY
Files scanned: 47
Total findings: 3
π΄ Critical: 2
π High: 1
β οΈ Secrets found! Fix before committing.Secrets Detector includes 80+ rules across these categories:
| Category | Examples |
|---|---|
| βοΈ Cloud | AWS Access Key, AWS Secret, GCP Service Account, Firebase, DigitalOcean |
| π³ Payment | Stripe Live/Test, PayPal, Square |
| π€ AI | OpenAI API Key, Anthropic, Cohere, Hugging Face |
| π¬ Communication | Slack Token, Slack Webhook, Telegram Bot, Twilio |
| π§ Email | SendGrid, Mailgun, Mailchimp, Postmark |
| π Cryptography | RSA Private Key, EC Private Key, PGP Key, SSH Key |
| ποΈ Database | MongoDB URI, PostgreSQL, MySQL, Redis with credentials |
| π Authentication | JWT Secret, OAuth Tokens, Basic Auth |
| π¦ Version Control | GitHub Tokens (all types), GitLab, Bitbucket |
| π Generic | Generic API keys, passwords, secrets patterns |
# List all rules
python main.py rules
# Filter by category
python main.py rules --category Cloud- Python 3.9+
git clone https://github.com/khaledxbenali92/secrets-detector.git
cd secrets-detector
pip install -r requirements.txtgit clone https://github.com/khaledxbenali92/secrets-detector.git
cd secrets-detector
python main.py --help# Basic scan
python main.py scan --path ./my-project
# Only show high and critical
python main.py scan --path . --severity high
# Exclude directories
python main.py scan --path . --exclude tests/ --exclude node_modules/
# Save as JSON
python main.py scan --path . --format json --output results.json
# Generate HTML report
python main.py scan --path . --format html --output report.htmlpython main.py scan --path ./src/config.py# Scan last 20 commits (default)
python main.py git
# Scan last 100 commits
python main.py git --commits 100
# Scan specific branch
python main.py git --commits 50 --branch develop# Generates a detailed HTML report
python main.py audit --path ./my-project --output audit.htmlpython main.py rules
python main.py rules --category PaymentThe repository includes a ready-to-use GitHub Actions workflow.
Add to your project's .github/workflows/secrets-scan.yml:
name: π Secrets Scan
on: [push, pull_request]
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- run: |
git clone https://github.com/khaledxbenali92/secrets-detector.git detector
cd detector && pip install -r requirements.txt
python main.py scan --path ../ --severity highThis will block pull requests if high/critical secrets are found. β
Add to .git/hooks/pre-commit:
#!/bin/bash
python /path/to/secrets-detector/main.py scan --path . --severity high
if [ $? -ne 0 ]; then
echo "π Secrets detected! Commit blocked."
exit 1
fichmod +x .git/hooks/pre-commitsecrets-detector/
βββ main.py # CLI entry point
βββ src/
β βββ __init__.py
β βββ scanner.py # Core scanning engine
β βββ rules.py # 80+ detection rules
β βββ reporters/
β β βββ console.py # Colored terminal output
β β βββ json_reporter.py # JSON export
β β βββ html_reporter.py # Beautiful HTML report
β βββ utils/
β βββ display.py # UI utilities
βββ tests/
β βββ test_scanner.py # Full test suite
βββ .github/
β βββ workflows/
β βββ ci.yml # GitHub Actions CI
βββ requirements.txt
βββ .gitignore
βββ README.md
# Install pytest
pip install pytest pytest-cov
# Run tests
pytest tests/ -v
# With coverage report
pytest tests/ --cov=src --cov-report=term-missing- 80+ detection rules
- Console, JSON, HTML reporters
- Git history scanning
- Smart placeholder filtering
- GitHub Actions integration
- Pre-commit hook support
- VS Code Extension
- PyPI package (
pip install secrets-detector) - Custom rules via YAML config
- Slack/Discord notifications
- Baseline file (ignore known false positives)
- Web dashboard
Contributions are very welcome! Here's how:
Edit src/rules.py and add your rule:
{
"id": "MY_SERVICE_KEY",
"name": "My Service API Key",
"category": "My Category",
"severity": "high", # critical / high / medium / low
"pattern": r"myservice_[a-zA-Z0-9]{32}",
"description": "My Service API Key β what it can access",
"remediation": "How to revoke/rotate this secret",
},Then add a test in tests/test_scanner.py.
# Fork & clone
git clone https://github.com/YOUR-USERNAME/secrets-detector.git
cd secrets-detector
# Create branch
git checkout -b feat/add-my-service-rule
# Make changes + add tests
pytest tests/ -v # must pass
# Commit
git commit -m "feat: add My Service API key detection"
git push origin feat/add-my-service-rule
# Open Pull Request- π New service API key patterns
- π Translations of the README
- π§ͺ More test cases
- π Documentation improvements
- π Bug reports
This tool is for defensive security purposes only. Use it on codebases you own or have explicit permission to scan. The authors are not responsible for misuse.
MIT License β see LICENSE for details.
Khaled Ben Ali β Cybersecurity & Full-Stack Founder
β If this tool helped secure your codebase, please star it! β
Every star helps more developers find this tool and keep their secrets safe.