Secret Detection Patterns
This reference provides regex patterns and search strategies for detecting secrets in repositories.
Cloud Provider Credentials
AWS
| Secret Type |
Pattern |
Example |
| Access Key ID |
AKIA[0-9A-Z]{16} |
AKIAIOSFODNN7EXAMPLE |
| Secret Access Key |
[A-Za-z0-9/+=]{40} (near AWS context) |
40-char base64 string |
| MWS Auth Token |
amzn\.mws\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} |
|
Google Cloud Platform
| Secret Type |
Pattern |
Example |
| API Key |
AIza[0-9A-Za-z\\-_]{35} |
AIzaSyDaGmWKa4JsXZ-example |
| OAuth Client ID |
[0-9]+-[0-9A-Za-z_]{32}\.apps\.googleusercontent\.com |
|
| Service Account |
"type":\s*"service_account" (in JSON) |
|
Azure
| Secret Type |
Pattern |
Example |
| Storage Account Key |
[A-Za-z0-9+/]{86}== |
88-char base64 string |
| Connection String |
DefaultEndpointsProtocol=https;AccountName= |
|
| SAS Token |
sv=\d{4}-\d{2}-\d{2}&s[a-z]= |
|
Version Control Platforms
GitHub
| Secret Type |
Pattern |
Example |
| Personal Access Token (new) |
ghp_[A-Za-z0-9]{36} |
ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| Personal Access Token (old) |
[0-9a-f]{40} (in GitHub context) |
40-char hex string |
| OAuth Access Token |
gho_[A-Za-z0-9]{36} |
|
| App Token |
ghu_[A-Za-z0-9]{36} |
|
| App Refresh Token |
ghr_[A-Za-z0-9]{76} |
|
| Fine-grained PAT |
github_pat_[A-Za-z0-9]{22}_[A-Za-z0-9]{59} |
|
GitLab
| Secret Type |
Pattern |
Example |
| Personal Access Token |
glpat-[A-Za-z0-9\-]{20} |
|
| Pipeline Token |
glpt-[A-Za-z0-9\-]{20} |
|
| Runner Token |
GR1348941[A-Za-z0-9\-]{20} |
|
Bitbucket
| Secret Type |
Pattern |
Example |
| App Password |
ATBB[A-Za-z0-9]{32} |
|
AI/ML Services
OpenAI
| Secret Type |
Pattern |
Example |
| API Key |
sk-[A-Za-z0-9]{48} |
sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| Project Key |
sk-proj-[A-Za-z0-9]{48} |
|
Anthropic
| Secret Type |
Pattern |
Example |
| API Key |
sk-ant-[A-Za-z0-9\-]{95} |
|
Hugging Face
| Secret Type |
Pattern |
Example |
| Token |
hf_[A-Za-z0-9]{34} |
hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
Cohere
| Secret Type |
Pattern |
Example |
| API Key |
[A-Za-z0-9]{40} (near Cohere context) |
|
Authentication Tokens
JWT
| Secret Type |
Pattern |
Example |
| JWT Token |
eyJ[A-Za-z0-9_-]*\.eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]* |
Base64 encoded JSON |
OAuth/Bearer
| Secret Type |
Pattern |
Example |
| Bearer Token |
[Bb]earer\s+[A-Za-z0-9\-_\.]+ |
|
| OAuth Token |
ya29\.[0-9A-Za-z\-_]+ |
Google OAuth |
Database Credentials
Connection Strings
| Secret Type |
Pattern |
Example |
| PostgreSQL |
postgres(ql)?://[^:]+:[^@]+@ |
postgres://user:pass@host |
| MySQL |
mysql://[^:]+:[^@]+@ |
mysql://user:pass@host |
| MongoDB |
mongodb(\+srv)?://[^:]+:[^@]+@ |
mongodb://user:pass@host |
| Redis |
redis://:[^@]+@ |
redis://:password@host |
| JDBC |
jdbc:[a-z]+://[^:]+:[^@]+@ |
|
Password Fields
| Secret Type |
Pattern |
Example |
| Password assignment |
[Pp]assword\s*[=:]\s*['"][^'"]+['"] |
password = "secret" |
| DB Password |
DB_PASSWORD\s*=\s*['"]?[^'"\\s]+ |
|
Private Keys
SSH/RSA Keys
| Secret Type |
Pattern |
Example |
| RSA Private Key |
-----BEGIN RSA PRIVATE KEY----- |
|
| OpenSSH Private Key |
-----BEGIN OPENSSH PRIVATE KEY----- |
|
| DSA Private Key |
-----BEGIN DSA PRIVATE KEY----- |
|
| EC Private Key |
-----BEGIN EC PRIVATE KEY----- |
|
| PGP Private Key |
-----BEGIN PGP PRIVATE KEY BLOCK----- |
|
| Generic Private Key |
-----BEGIN PRIVATE KEY----- |
|
| Encrypted Private Key |
-----BEGIN ENCRYPTED PRIVATE KEY----- |
|
Communication Services
Slack
| Secret Type |
Pattern |
Example |
| Bot Token |
xoxb-[0-9]{10,13}-[0-9]{10,13}-[A-Za-z0-9]{24} |
|
| User Token |
xoxp-[0-9]{10,13}-[0-9]{10,13}-[A-Za-z0-9]{24} |
|
| Webhook URL |
https://hooks\.slack\.com/services/T[A-Z0-9]+/B[A-Z0-9]+/[A-Za-z0-9]+ |
|
Discord
| Secret Type |
Pattern |
Example |
| Bot Token |
[MN][A-Za-z\d]{23,}\.[\w-]{6}\.[\w-]{27} |
|
| Webhook URL |
https://discord(app)?\.com/api/webhooks/[0-9]+/[A-Za-z0-9_-]+ |
|
Twilio
| Secret Type |
Pattern |
Example |
| Account SID |
AC[a-z0-9]{32} |
|
| Auth Token |
[a-f0-9]{32} (near Twilio context) |
|
Payment Services
Stripe
| Secret Type |
Pattern |
Example |
| Secret Key (Live) |
sk_live_[A-Za-z0-9]{24,} |
|
| Secret Key (Test) |
sk_test_[A-Za-z0-9]{24,} |
|
| Publishable Key |
pk_(live|test)_[A-Za-z0-9]{24,} |
|
PayPal
| Secret Type |
Pattern |
Example |
| Client ID |
A[A-Za-z0-9_-]{79} |
|
Square
| Secret Type |
Pattern |
Example |
| Access Token |
sq0atp-[A-Za-z0-9_-]{22} |
|
| OAuth Secret |
sq0csp-[A-Za-z0-9_-]{43} |
|
Other Services
SendGrid
| Secret Type |
Pattern |
Example |
| API Key |
SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43} |
|
Mailchimp
| Secret Type |
Pattern |
Example |
| API Key |
[a-f0-9]{32}-us[0-9]{1,2} |
|
NPM
| Secret Type |
Pattern |
Example |
| Token |
npm_[A-Za-z0-9]{36} |
|
PyPI
| Secret Type |
Pattern |
Example |
| Token |
pypi-[A-Za-z0-9_-]{50,} |
|
Heroku
| Secret Type |
Pattern |
Example |
| API Key |
[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12} (in Heroku context) |
|
Generic Patterns
High-Entropy Strings
Strings matching these patterns warrant investigation:
| Description |
Pattern |
| API Key Generic |
[Aa]pi[_-]?[Kk]ey\s*[=:]\s*['"]?[A-Za-z0-9_\-]{20,} |
| Secret Generic |
[Ss]ecret\s*[=:]\s*['"]?[A-Za-z0-9_\-]{20,} |
| Token Generic |
[Tt]oken\s*[=:]\s*['"]?[A-Za-z0-9_\-]{20,} |
| Credential |
[Cc]redential\s*[=:]\s*['"]?[A-Za-z0-9_\-]{20,} |
Environment Variable Values
| Description |
Pattern |
| Inline assignment |
[A-Z_]+_KEY=[^\\s]+ |
| Export statement |
export\s+[A-Z_]+(KEY|SECRET|TOKEN|PASSWORD)=[^\\s]+ |
Search Commands
Comprehensive grep search
# Search for common secret indicators
grep -rniE '(api[_-]?key|secret|token|password|credential|auth)\s*[=:]\s*['''"][^'''"]{8,}['''"]' .
# Search for AWS keys
grep -rniE 'AKIA[0-9A-Z]{16}' .
# Search for private keys
grep -rl '-----BEGIN.*PRIVATE KEY-----' .
# Search for connection strings
grep -rniE '(postgres|mysql|mongodb|redis)://[^:]+:[^@]+@' .
Using git to search history
# Search all commits for pattern
git log -p --all -S 'AKIA' --source
# Search for pattern in specific branch
git log -p -S 'secret_value' branch_name
Files to Prioritize
Always check these files first:
.env, .env.*, .env.local, .env.production
config/*.json, config/*.yaml, config/*.yml
secrets.*, credentials.*
*.pem, *.key, *.p12, *.pfx
docker-compose*.yml, Dockerfile*
.github/workflows/*.yml, .gitlab-ci.yml
terraform.tfvars, *.tfstate
application.properties, application.yml (Java/Spring)
settings.py, local_settings.py (Django)
wp-config.php (WordPress)
1---2name: 261-secret-patterns-d16fd4513description: Secret Detection Patterns4---5# Secret Detection Patterns67This reference provides regex patterns and search strategies for detecting secrets in repositories.89## Cloud Provider Credentials1011### AWS1213| Secret Type | Pattern | Example |14|-------------|---------|---------|15| Access Key ID | `AKIA[0-9A-Z]{16}` | `AKIAIOSFODNN7EXAMPLE` |16| Secret Access Key | `[A-Za-z0-9/+=]{40}` (near AWS context) | 40-char base64 string |17| MWS Auth Token | `amzn\.mws\.[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}` | |1819### Google Cloud Platform2021| Secret Type | Pattern | Example |22|-------------|---------|---------|23| API Key | `AIza[0-9A-Za-z\\-_]{35}` | `AIzaSyDaGmWKa4JsXZ-example` |24| OAuth Client ID | `[0-9]+-[0-9A-Za-z_]{32}\.apps\.googleusercontent\.com` | |25| Service Account | `"type":\s*"service_account"` (in JSON) | |2627### Azure2829| Secret Type | Pattern | Example |30|-------------|---------|---------|31| Storage Account Key | `[A-Za-z0-9+/]{86}==` | 88-char base64 string |32| Connection String | `DefaultEndpointsProtocol=https;AccountName=` | |33| SAS Token | `sv=\d{4}-\d{2}-\d{2}&s[a-z]=` | |3435## Version Control Platforms3637### GitHub3839| Secret Type | Pattern | Example |40|-------------|---------|---------|41| Personal Access Token (new) | `ghp_[A-Za-z0-9]{36}` | `ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` |42| Personal Access Token (old) | `[0-9a-f]{40}` (in GitHub context) | 40-char hex string |43| OAuth Access Token | `gho_[A-Za-z0-9]{36}` | |44| App Token | `ghu_[A-Za-z0-9]{36}` | |45| App Refresh Token | `ghr_[A-Za-z0-9]{76}` | |46| Fine-grained PAT | `github_pat_[A-Za-z0-9]{22}_[A-Za-z0-9]{59}` | |4748### GitLab4950| Secret Type | Pattern | Example |51|-------------|---------|---------|52| Personal Access Token | `glpat-[A-Za-z0-9\-]{20}` | |53| Pipeline Token | `glpt-[A-Za-z0-9\-]{20}` | |54| Runner Token | `GR1348941[A-Za-z0-9\-]{20}` | |5556### Bitbucket5758| Secret Type | Pattern | Example |59|-------------|---------|---------|60| App Password | `ATBB[A-Za-z0-9]{32}` | |6162## AI/ML Services6364### OpenAI6566| Secret Type | Pattern | Example |67|-------------|---------|---------|68| API Key | `sk-[A-Za-z0-9]{48}` | `sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` |69| Project Key | `sk-proj-[A-Za-z0-9]{48}` | |7071### Anthropic7273| Secret Type | Pattern | Example |74|-------------|---------|---------|75| API Key | `sk-ant-[A-Za-z0-9\-]{95}` | |7677### Hugging Face7879| Secret Type | Pattern | Example |80|-------------|---------|---------|81| Token | `hf_[A-Za-z0-9]{34}` | `hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx` |8283### Cohere8485| Secret Type | Pattern | Example |86|-------------|---------|---------|87| API Key | `[A-Za-z0-9]{40}` (near Cohere context) | |8889## Authentication Tokens9091### JWT9293| Secret Type | Pattern | Example |94|-------------|---------|---------|95| JWT Token | `eyJ[A-Za-z0-9_-]*\.eyJ[A-Za-z0-9_-]*\.[A-Za-z0-9_-]*` | Base64 encoded JSON |9697### OAuth/Bearer9899| Secret Type | Pattern | Example |100|-------------|---------|---------|101| Bearer Token | `[Bb]earer\s+[A-Za-z0-9\-_\.]+` | |102| OAuth Token | `ya29\.[0-9A-Za-z\-_]+` | Google OAuth |103104## Database Credentials105106### Connection Strings107108| Secret Type | Pattern | Example |109|-------------|---------|---------|110| PostgreSQL | `postgres(ql)?://[^:]+:[^@]+@` | `postgres://user:pass@host` |111| MySQL | `mysql://[^:]+:[^@]+@` | `mysql://user:pass@host` |112| MongoDB | `mongodb(\+srv)?://[^:]+:[^@]+@` | `mongodb://user:pass@host` |113| Redis | `redis://:[^@]+@` | `redis://:password@host` |114| JDBC | `jdbc:[a-z]+://[^:]+:[^@]+@` | |115116### Password Fields117118| Secret Type | Pattern | Example |119|-------------|---------|---------|120| Password assignment | `[Pp]assword\s*[=:]\s*['"][^'"]+['"]` | `password = "secret"` |121| DB Password | `DB_PASSWORD\s*=\s*['"]?[^'"\\s]+` | |122123## Private Keys124125### SSH/RSA Keys126127| Secret Type | Pattern | Example |128|-------------|---------|---------|129| RSA Private Key | `-----BEGIN RSA PRIVATE KEY-----` | |130| OpenSSH Private Key | `-----BEGIN OPENSSH PRIVATE KEY-----` | |131| DSA Private Key | `-----BEGIN DSA PRIVATE KEY-----` | |132| EC Private Key | `-----BEGIN EC PRIVATE KEY-----` | |133| PGP Private Key | `-----BEGIN PGP PRIVATE KEY BLOCK-----` | |134| Generic Private Key | `-----BEGIN PRIVATE KEY-----` | |135| Encrypted Private Key | `-----BEGIN ENCRYPTED PRIVATE KEY-----` | |136137## Communication Services138139### Slack140141| Secret Type | Pattern | Example |142|-------------|---------|---------|143| Bot Token | `xoxb-[0-9]{10,13}-[0-9]{10,13}-[A-Za-z0-9]{24}` | |144| User Token | `xoxp-[0-9]{10,13}-[0-9]{10,13}-[A-Za-z0-9]{24}` | |145| Webhook URL | `https://hooks\.slack\.com/services/T[A-Z0-9]+/B[A-Z0-9]+/[A-Za-z0-9]+` | |146147### Discord148149| Secret Type | Pattern | Example |150|-------------|---------|---------|151| Bot Token | `[MN][A-Za-z\d]{23,}\.[\w-]{6}\.[\w-]{27}` | |152| Webhook URL | `https://discord(app)?\.com/api/webhooks/[0-9]+/[A-Za-z0-9_-]+` | |153154### Twilio155156| Secret Type | Pattern | Example |157|-------------|---------|---------|158| Account SID | `AC[a-z0-9]{32}` | |159| Auth Token | `[a-f0-9]{32}` (near Twilio context) | |160161## Payment Services162163### Stripe164165| Secret Type | Pattern | Example |166|-------------|---------|---------|167| Secret Key (Live) | `sk_live_[A-Za-z0-9]{24,}` | |168| Secret Key (Test) | `sk_test_[A-Za-z0-9]{24,}` | |169| Publishable Key | `pk_(live\|test)_[A-Za-z0-9]{24,}` | |170171### PayPal172173| Secret Type | Pattern | Example |174|-------------|---------|---------|175| Client ID | `A[A-Za-z0-9_-]{79}` | |176177### Square178179| Secret Type | Pattern | Example |180|-------------|---------|---------|181| Access Token | `sq0atp-[A-Za-z0-9_-]{22}` | |182| OAuth Secret | `sq0csp-[A-Za-z0-9_-]{43}` | |183184## Other Services185186### SendGrid187188| Secret Type | Pattern | Example |189|-------------|---------|---------|190| API Key | `SG\.[A-Za-z0-9_-]{22}\.[A-Za-z0-9_-]{43}` | |191192### Mailchimp193194| Secret Type | Pattern | Example |195|-------------|---------|---------|196| API Key | `[a-f0-9]{32}-us[0-9]{1,2}` | |197198### NPM199200| Secret Type | Pattern | Example |201|-------------|---------|---------|202| Token | `npm_[A-Za-z0-9]{36}` | |203204### PyPI205206| Secret Type | Pattern | Example |207|-------------|---------|---------|208| Token | `pypi-[A-Za-z0-9_-]{50,}` | |209210### Heroku211212| Secret Type | Pattern | Example |213|-------------|---------|---------|214| API Key | `[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}` (in Heroku context) | |215216## Generic Patterns217218### High-Entropy Strings219220Strings matching these patterns warrant investigation:221222| Description | Pattern |223|-------------|---------|224| API Key Generic | `[Aa]pi[_-]?[Kk]ey\s*[=:]\s*['"]?[A-Za-z0-9_\-]{20,}` |225| Secret Generic | `[Ss]ecret\s*[=:]\s*['"]?[A-Za-z0-9_\-]{20,}` |226| Token Generic | `[Tt]oken\s*[=:]\s*['"]?[A-Za-z0-9_\-]{20,}` |227| Credential | `[Cc]redential\s*[=:]\s*['"]?[A-Za-z0-9_\-]{20,}` |228229### Environment Variable Values230231| Description | Pattern |232|-------------|---------|233| Inline assignment | `[A-Z_]+_KEY=[^\\s]+` |234| Export statement | `export\s+[A-Z_]+(KEY\|SECRET\|TOKEN\|PASSWORD)=[^\\s]+` |235236## Search Commands237238### Comprehensive grep search239240```bash241# Search for common secret indicators242grep -rniE '(api[_-]?key|secret|token|password|credential|auth)\s*[=:]\s*['''"][^'''"]{8,}['''"]' .243244# Search for AWS keys245grep -rniE 'AKIA[0-9A-Z]{16}' .246247# Search for private keys248grep -rl '-----BEGIN.*PRIVATE KEY-----' .249250# Search for connection strings251grep -rniE '(postgres|mysql|mongodb|redis)://[^:]+:[^@]+@' .252```253254### Using git to search history255256```bash257# Search all commits for pattern258git log -p --all -S 'AKIA' --source259260# Search for pattern in specific branch261git log -p -S 'secret_value' branch_name262```263264## Files to Prioritize265266Always check these files first:2672681. `.env`, `.env.*`, `.env.local`, `.env.production`2692. `config/*.json`, `config/*.yaml`, `config/*.yml`2703. `secrets.*`, `credentials.*`2714. `*.pem`, `*.key`, `*.p12`, `*.pfx`2725. `docker-compose*.yml`, `Dockerfile*`2736. `.github/workflows/*.yml`, `.gitlab-ci.yml`2747. `terraform.tfvars`, `*.tfstate`2758. `application.properties`, `application.yml` (Java/Spring)2769. `settings.py`, `local_settings.py` (Django)27710. `wp-config.php` (WordPress)