A simple secret/credential scanner for source code repositories.
Project description
secret-scan
A fast, lightweight CLI tool to detect secrets in source code. Zero dependencies — stdlib only.
secret-scan scans directories for sensitive data such as:
- AWS Access Keys and Secret Keys
- GitHub tokens (PAT, OAuth, App, fine-grained)
- Slack tokens (bot, user)
- Stripe keys (live and test)
- Google API keys
- OpenAI API keys
- npm and PyPI tokens
- Twilio and SendGrid API keys
- Heroku and HashiCorp Vault tokens
- Passwords, Bearer tokens, and JWTs
- SSH/RSA/PGP private keys
- Azure storage keys
- Database connection strings
It skips binary files, ignores common junk directories (node_modules, .git, venv, etc.), avoids scanning large files, and supports extensible detection rules.
Installation
pip install secret-scan
To upgrade:
pip install --upgrade secret-scan
Basic Usage
Scan the current directory:
secret-scan .
Scan a specific directory:
secret-scan ~/projects/my-repo
Write results to a file (default: docsCred.txt):
secret-scan . --output secrets.txt
Exit Codes
secret-scan returns meaningful exit codes for CI/CD integration:
| Exit Code | Meaning |
|---|---|
| 0 | No secrets found |
| 1 | Secrets were found |
Use --no-fail to always exit with 0 (advisory mode):
secret-scan . --no-fail
JSON Output
Generate JSON output (useful for CI pipelines):
secret-scan . --json
Example output:
[
{
"file": "config/settings.py",
"line": 20,
"match": "AWS_ACCESS_KEY_ID=AKIA1234567890ABCD12",
"rule_id": "aws-access-key-assignment",
"rule_name": "AWS Access Key Assignment",
"severity": "error",
"column": 0,
"end_column": 42
}
]
SARIF Output
Generate SARIF v2.1.0 output for integration with GitHub Code Scanning, GitLab SAST, and other security tools:
secret-scan . --sarif
Upload to GitHub Code Scanning:
secret-scan . --sarif > results.sarif
gh api repos/{owner}/{repo}/code-scanning/sarifs \
-X POST -F "sarif=@results.sarif"
Suppressing False Positives
.secretscanignore
Create a .secretscanignore file in your project root to suppress known false positives:
# Ignore entire files or directories
tests/fixtures/*.json
docs/**
# Ignore a specific rule for a specific file
config/settings.py:generic-secret
# Ignore matches containing specific text
!match:EXAMPLE_KEY_DO_NOT_USE
Inline suppression
Add # nosecret to any line to suppress detection on that line:
DEFAULT_KEY = "sk-placeholder-not-real" # nosecret
Use --no-ignore to bypass all suppression rules:
secret-scan . --no-ignore
Command-Line Options
| Flag | Description |
|---|---|
| --output <file> | Save text results (default: docsCred.txt) |
| --skip-ext .log | Skip specific file extensions |
| --skip-dir <dir> | Skip specific directories |
| --max-size-mb N | Scan only files smaller than N MB |
| --json | Print JSON results to stdout |
| --sarif | Print SARIF v2.1.0 results to stdout |
| --no-fail | Always exit 0 even if secrets are found |
| --no-ignore | Do not read .secretscanignore file |
Example:
secret-scan . --skip-ext .log --skip-dir build --json
What It Detects
Each detection rule has a unique rule_id and a severity level (error, warning, or note).
Cloud Providers
| Provider | What | Severity |
|---|---|---|
| AWS | Access Key IDs (AKIA...), Secret Access Keys | error |
| Azure | Storage account keys, Account keys | error |
| API keys (AIza...) | error | |
| Heroku | API key assignments | error |
| HashiCorp Vault | Service tokens (hvs.) | error |
SaaS / API Platforms
| Provider | What | Severity |
|---|---|---|
| GitHub | PAT, OAuth, App, Refresh, Fine-grained tokens | error |
| Slack | Bot tokens (xoxb-), User tokens (xoxp-) | error |
| Stripe | Live secret/publishable/restricted keys | error/warning |
| Stripe | Test keys | note |
| OpenAI | API keys (sk-) | error |
| Twilio | API keys (SK...) | error |
| SendGrid | API keys (SG.) | error |
| npm | Access tokens | error |
| PyPI | API tokens | error |
Generic Patterns
| What | Severity |
|---|---|
| Password assignments (password=, passwd=, pwd=) | warning |
| Bearer tokens | error |
| JWT tokens | warning |
| API key/token assignments | warning |
| Private key blocks (PEM headers) | error |
| SSH RSA public keys | note |
| Database connection strings | warning |
| Generic secret assignments | warning |
Automatic Skips
The scanner automatically ignores:
- .git, .hg, .svn
- node_modules
- Python virtual environments (venv, .venv, env)
- IDE directories (.idea, .vscode)
- Binary files (null-byte detection)
- Large files (over 5 MB by default)
- Common non-text extensions (images, archives, executables)
Extending Detection Patterns
Detection patterns are defined as SecretPattern dataclass instances in:
src/secret_scanner/patterns.py
Each pattern has a rule_id, name, severity, pattern (regex), and description. You can add new patterns by appending to the PATTERNS list.
Programmatic Usage
Example using the Python API:
from pathlib import Path
from secret_scanner import scan_directory
matches = scan_directory(Path("."), output_path=None)
for m in matches:
print(f"[{m['severity']}] {m['rule_name']}: {m['file']}:{m['line']}")
Running Tests
PYTHONPATH=src pytest tests/ -q
Contributing
Contributions are welcome.
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Open a pull request
License
This project is licensed under the MIT License. See the LICENSE file for full details.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file secret_scan-0.2.0.tar.gz.
File metadata
- Download URL: secret_scan-0.2.0.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4eec8e3e99fc774f022c3b97e84e07f95094cbd2d992a018804243a1523ab00e
|
|
| MD5 |
d7dfd20602a1fd5f21a8cfc18f4f645b
|
|
| BLAKE2b-256 |
121e6b3741fe78771f8b89983aade4ba699e37e03b841b06031405abee925781
|
Provenance
The following attestation bundles were made for secret_scan-0.2.0.tar.gz:
Publisher:
publish.yml on harshahemanth/secret-scan
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
secret_scan-0.2.0.tar.gz -
Subject digest:
4eec8e3e99fc774f022c3b97e84e07f95094cbd2d992a018804243a1523ab00e - Sigstore transparency entry: 1035247641
- Sigstore integration time:
-
Permalink:
harshahemanth/secret-scan@b752a878b952f80c1bd4174e95025ff491461eda -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/harshahemanth
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b752a878b952f80c1bd4174e95025ff491461eda -
Trigger Event:
release
-
Statement type:
File details
Details for the file secret_scan-0.2.0-py3-none-any.whl.
File metadata
- Download URL: secret_scan-0.2.0-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6ff57ff796343e33d68238026fc37c74eedef5b1c2229f9b0ae9a10c6251876
|
|
| MD5 |
cce87de654b42b6b969941b7fb239409
|
|
| BLAKE2b-256 |
fa45735f16979321b04311bb57e79b8a7e183731604ffbed491767228c66da45
|
Provenance
The following attestation bundles were made for secret_scan-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on harshahemanth/secret-scan
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
secret_scan-0.2.0-py3-none-any.whl -
Subject digest:
e6ff57ff796343e33d68238026fc37c74eedef5b1c2229f9b0ae9a10c6251876 - Sigstore transparency entry: 1035247709
- Sigstore integration time:
-
Permalink:
harshahemanth/secret-scan@b752a878b952f80c1bd4174e95025ff491461eda -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/harshahemanth
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b752a878b952f80c1bd4174e95025ff491461eda -
Trigger Event:
release
-
Statement type: