SC: Hardcoded Secrets & Credentials
Purpose
Detects hardcoded secrets, API keys, tokens, passwords, private keys, and credentials embedded in source code, configuration files, and environment files committed to version control. Uses pattern matching for known key formats, entropy analysis for unknown formats, and context analysis to distinguish test keys from production secrets.
Activation
Called by sc-orchestrator during Phase 2. Always runs regardless of detected languages.
Phase 1: Discovery
File Patterns to Search
**/*.ts, **/*.js, **/*.py, **/*.go, **/*.php, **/*.java, **/*.cs,
**/*.rb, **/*.yaml, **/*.yml, **/*.json, **/*.xml, **/*.toml,
**/*.env, **/*.env.*, **/*.cfg, **/*.conf, **/*.ini, **/*.properties,
**/*.config, **/config/*, **/settings/*, **/.env*, **/docker-compose*,
**/*.sh, **/*.bash, **/Dockerfile*, **/.github/workflows/*
Known API Key Patterns
| Service |
Pattern |
Example Prefix |
| AWS Access Key |
AKIA[0-9A-Z]{16} |
AKIA... |
| AWS Secret Key |
40-char base64 after aws_secret_access_key |
|
| GitHub Token |
ghp_[A-Za-z0-9]{36} |
ghp_... |
| GitHub App Token |
ghs_[A-Za-z0-9]{36} |
ghs_... |
| GitLab Token |
glpat-[A-Za-z0-9\-]{20} |
glpat-... |
| Stripe Live Key |
sk_live_[A-Za-z0-9]{24,} |
sk_live_... |
| Stripe Publishable |
pk_live_[A-Za-z0-9]{24,} |
pk_live_... |
| Twilio |
SK[0-9a-fA-F]{32} |
SK... |
| SendGrid |
SG\.[A-Za-z0-9\-_]{22}\.[A-Za-z0-9\-_]{43} |
SG.... |
| Slack Token |
xox[baprs]-[A-Za-z0-9\-]{10,} |
xoxb-... |
| Google API Key |
AIza[A-Za-z0-9\-_]{35} |
AIza... |
| Firebase Key |
AAAA[A-Za-z0-9_-]{7}:[A-Za-z0-9_-]{140} |
|
| Heroku API Key |
[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-...-[0-9a-fA-F]{12} |
UUID format |
| npm Token |
npm_[A-Za-z0-9]{36} |
npm_... |
| PyPI Token |
pypi-[A-Za-z0-9\-_]{16,} |
pypi-... |
Private Key Detection
"-----BEGIN RSA PRIVATE KEY-----"
"-----BEGIN EC PRIVATE KEY-----"
"-----BEGIN OPENSSH PRIVATE KEY-----"
"-----BEGIN PGP PRIVATE KEY BLOCK-----"
"-----BEGIN DSA PRIVATE KEY-----"
"-----BEGIN PRIVATE KEY-----"
Generic Secret Patterns
# Assignment patterns
"password\s*[=:]\s*[\"'][^\"']{8,}"
"secret\s*[=:]\s*[\"'][^\"']{8,}"
"api_key\s*[=:]\s*[\"'][^\"']{8,}"
"token\s*[=:]\s*[\"'][^\"']{8,}"
"private_key\s*[=:]\s*[\"'][^\"']{8,}"
"auth.*[=:]\s*[\"'][^\"']{8,}"
"credential.*[=:]\s*[\"'][^\"']{8,}"
# Connection strings with embedded passwords
"mongodb://.*:.*@"
"postgres://.*:.*@"
"mysql://.*:.*@"
"redis://.*:.*@"
"amqp://.*:.*@"
High-Entropy String Detection
Flag strings with Shannon entropy > 4.5 in security-sensitive variable assignments.
Phase 2: Verification
Test vs Production Key Distinction
- Does the key match a known test/example prefix? (e.g.,
sk_test_, pk_test_, AKIAIOSFODNN7EXAMPLE)
- Is the file in a test directory?
- Is the value
"changeme", "placeholder", "xxx", "your-key-here"?
- Is the value loaded from an environment variable at runtime? (
os.getenv(), process.env)
- Is the
.env file in .gitignore?
Context Analysis
# FALSE POSITIVE: Environment variable read (not hardcoded)
API_KEY = os.environ.get('API_KEY')
# TRUE POSITIVE: Hardcoded secret
API_KEY = "sk_live_EXAMPLE_KEY_REPLACE_ME"
# FALSE POSITIVE: Test key
STRIPE_KEY = "sk_test_EXAMPLE_KEY"
# TRUE POSITIVE: Production key in code
STRIPE_KEY = "sk_live_EXAMPLE_PROD_KEY"
Severity Classification
- Critical: Production API keys (AWS, Stripe live, database passwords), private keys, JWT signing secrets
- High: Service tokens (GitHub, GitLab, Slack, SendGrid) that grant significant access
- Medium: API keys with limited scope, internal service credentials, publishable keys misidentified as secret
- Low: Test/sandbox keys, example/placeholder values, keys in documentation
Output Format
Finding: SECRET-{NNN}
- Title: Hardcoded {key type} in {file}
- Severity: Critical | High | Medium | Low
- Confidence: 0-100
- File: file/path:line
- Vulnerability Type: CWE-798 (Hardcoded Credentials) | CWE-321 (Hard-coded Cryptographic Key)
- Description: {Service} {key type} found hardcoded in source code.
- Impact: Unauthorized access to {service}, data breach, financial loss, account compromise.
- Remediation: Move secret to environment variable or secrets manager. Rotate the exposed key immediately.
- References: https://cwe.mitre.org/data/definitions/798.html
Common False Positives
- Environment variable reads —
os.getenv("KEY"), process.env.KEY are runtime reads, not hardcoded
- Test/sandbox keys —
sk_test_, pk_test_, keys containing "test", "example", "demo"
- Placeholder values —
"changeme", "your-api-key", "xxx", "TODO"
- Public keys — SSH public keys, JWT public keys, certificate public keys are not secrets
- Hash outputs — bcrypt hashes, SHA hashes in migration files are not secrets
- Base64-encoded non-secrets — base64 strings that are UI assets, not credentials
- Configuration templates —
.env.example files with placeholder values
1---2name: sc-secrets3description: Hardcoded secrets, API keys, tokens, credentials, and private key detection in source code4license: MIT5metadata:6 source: https://skillmd.com/skills/aibot88/sc-secrets7 category: security8 version: "1.0.0"9---1011# SC: Hardcoded Secrets & Credentials1213## Purpose1415Detects hardcoded secrets, API keys, tokens, passwords, private keys, and credentials embedded in source code, configuration files, and environment files committed to version control. Uses pattern matching for known key formats, entropy analysis for unknown formats, and context analysis to distinguish test keys from production secrets.1617## Activation1819Called by sc-orchestrator during Phase 2. Always runs regardless of detected languages.2021## Phase 1: Discovery2223### File Patterns to Search24```25**/*.ts, **/*.js, **/*.py, **/*.go, **/*.php, **/*.java, **/*.cs,26**/*.rb, **/*.yaml, **/*.yml, **/*.json, **/*.xml, **/*.toml,27**/*.env, **/*.env.*, **/*.cfg, **/*.conf, **/*.ini, **/*.properties,28**/*.config, **/config/*, **/settings/*, **/.env*, **/docker-compose*,29**/*.sh, **/*.bash, **/Dockerfile*, **/.github/workflows/*30```3132### Known API Key Patterns3334| Service | Pattern | Example Prefix |35|---------|---------|----------------|36| AWS Access Key | `AKIA[0-9A-Z]{16}` | `AKIA...` |37| AWS Secret Key | 40-char base64 after `aws_secret_access_key` | |38| GitHub Token | `ghp_[A-Za-z0-9]{36}` | `ghp_...` |39| GitHub App Token | `ghs_[A-Za-z0-9]{36}` | `ghs_...` |40| GitLab Token | `glpat-[A-Za-z0-9\-]{20}` | `glpat-...` |41| Stripe Live Key | `sk_live_[A-Za-z0-9]{24,}` | `sk_live_...` |42| Stripe Publishable | `pk_live_[A-Za-z0-9]{24,}` | `pk_live_...` |43| Twilio | `SK[0-9a-fA-F]{32}` | `SK...` |44| SendGrid | `SG\.[A-Za-z0-9\-_]{22}\.[A-Za-z0-9\-_]{43}` | `SG....` |45| Slack Token | `xox[baprs]-[A-Za-z0-9\-]{10,}` | `xoxb-...` |46| Google API Key | `AIza[A-Za-z0-9\-_]{35}` | `AIza...` |47| Firebase Key | `AAAA[A-Za-z0-9_-]{7}:[A-Za-z0-9_-]{140}` | |48| Heroku API Key | `[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-...-[0-9a-fA-F]{12}` | UUID format |49| npm Token | `npm_[A-Za-z0-9]{36}` | `npm_...` |50| PyPI Token | `pypi-[A-Za-z0-9\-_]{16,}` | `pypi-...` |5152### Private Key Detection53```54"-----BEGIN RSA PRIVATE KEY-----"55"-----BEGIN EC PRIVATE KEY-----"56"-----BEGIN OPENSSH PRIVATE KEY-----"57"-----BEGIN PGP PRIVATE KEY BLOCK-----"58"-----BEGIN DSA PRIVATE KEY-----"59"-----BEGIN PRIVATE KEY-----"60```6162### Generic Secret Patterns63```64# Assignment patterns65"password\s*[=:]\s*[\"'][^\"']{8,}"66"secret\s*[=:]\s*[\"'][^\"']{8,}"67"api_key\s*[=:]\s*[\"'][^\"']{8,}"68"token\s*[=:]\s*[\"'][^\"']{8,}"69"private_key\s*[=:]\s*[\"'][^\"']{8,}"70"auth.*[=:]\s*[\"'][^\"']{8,}"71"credential.*[=:]\s*[\"'][^\"']{8,}"7273# Connection strings with embedded passwords74"mongodb://.*:.*@"75"postgres://.*:.*@"76"mysql://.*:.*@"77"redis://.*:.*@"78"amqp://.*:.*@"79```8081### High-Entropy String Detection82Flag strings with Shannon entropy > 4.5 in security-sensitive variable assignments.8384## Phase 2: Verification8586### Test vs Production Key Distinction871. Does the key match a known test/example prefix? (e.g., `sk_test_`, `pk_test_`, `AKIAIOSFODNN7EXAMPLE`)882. Is the file in a test directory?893. Is the value `"changeme"`, `"placeholder"`, `"xxx"`, `"your-key-here"`?904. Is the value loaded from an environment variable at runtime? (`os.getenv()`, `process.env`)915. Is the `.env` file in `.gitignore`?9293### Context Analysis94```python95# FALSE POSITIVE: Environment variable read (not hardcoded)96API_KEY = os.environ.get('API_KEY')9798# TRUE POSITIVE: Hardcoded secret99API_KEY = "sk_live_EXAMPLE_KEY_REPLACE_ME"100101# FALSE POSITIVE: Test key102STRIPE_KEY = "sk_test_EXAMPLE_KEY"103104# TRUE POSITIVE: Production key in code105STRIPE_KEY = "sk_live_EXAMPLE_PROD_KEY"106```107108## Severity Classification109110- **Critical:** Production API keys (AWS, Stripe live, database passwords), private keys, JWT signing secrets111- **High:** Service tokens (GitHub, GitLab, Slack, SendGrid) that grant significant access112- **Medium:** API keys with limited scope, internal service credentials, publishable keys misidentified as secret113- **Low:** Test/sandbox keys, example/placeholder values, keys in documentation114115## Output Format116117### Finding: SECRET-{NNN}118- **Title:** Hardcoded {key type} in {file}119- **Severity:** Critical | High | Medium | Low120- **Confidence:** 0-100121- **File:** file/path:line122- **Vulnerability Type:** CWE-798 (Hardcoded Credentials) | CWE-321 (Hard-coded Cryptographic Key)123- **Description:** {Service} {key type} found hardcoded in source code.124- **Impact:** Unauthorized access to {service}, data breach, financial loss, account compromise.125- **Remediation:** Move secret to environment variable or secrets manager. Rotate the exposed key immediately.126- **References:** https://cwe.mitre.org/data/definitions/798.html127128## Common False Positives1291301. **Environment variable reads** — `os.getenv("KEY")`, `process.env.KEY` are runtime reads, not hardcoded1312. **Test/sandbox keys** — `sk_test_`, `pk_test_`, keys containing "test", "example", "demo"1323. **Placeholder values** — `"changeme"`, `"your-api-key"`, `"xxx"`, `"TODO"`1334. **Public keys** — SSH public keys, JWT public keys, certificate public keys are not secrets1345. **Hash outputs** — bcrypt hashes, SHA hashes in migration files are not secrets1356. **Base64-encoded non-secrets** — base64 strings that are UI assets, not credentials1367. **Configuration templates** — `.env.example` files with placeholder values