segrep-secrets scanner
Opt-in native regex-based secret detection for API keys, tokens, and credentials
Opt-in native secret detection scanner for Segrep that uses regex pattern matching to find hardcoded credentials, API keys, tokens, and connection strings — no external binary required.
Why use segrep-secrets
- Detects 28 categories of secrets including AWS keys, GitHub tokens, Slack tokens, Stripe keys, private keys, and generic credential patterns.
- Runs locally with zero dependencies — no Gitleaks binary or Docker required.
- Scans
.env, source code, config files, and key/cert files across all common languages. - Excludes lockfiles, minified files, and common non-secret directories (
node_modules,dist,.git). - Every finding is
criticalorhighseverity with CWE references for compliance tracking.
Scanner behavior
segrep-secrets runs as an opt-in scanner.
pnpm segrep scan . --scanners segrep-secretsIt walks the scan root and applies regex rules line-by-line to detect secrets.
Secret rules
| Rule ID | Severity | What it detects |
|---|---|---|
aws-access-key | critical | AWS Access Key IDs (AKIA...) |
aws-secret-key | critical | AWS Secret Access Keys |
github-pat | critical | GitHub Personal Access Tokens (ghp_, gho_, ghu_, ghs_) |
github-fine-grained-pat | critical | GitHub Fine-Grained PATs (github_pat_) |
slack-bot-token | critical | Slack Bot Tokens (xoxb-...) |
slack-user-token | critical | Slack User Tokens (xoxp-...) |
slack-webhook-url | critical | Slack Incoming Webhook URLs |
google-api-key | critical | Google API Keys (AIza...) |
private-key | critical | PEM-encoded private keys |
generic-api-key | high | API keys assigned to variables |
generic-secret | high | Secrets/passwords/tokens in assignments |
generic-secret-env | critical | Secrets in environment variable assignments |
bearer-token | critical | Bearer authentication tokens |
jwt-token | critical | JSON Web Tokens (eyJ...) |
npm-token | critical | npm Access Tokens (npm_...) |
pypi-token | critical | PyPI API Tokens (pypi-...) |
database-url | critical | Database connection URLs with credentials |
stripe-secret-key | critical | Stripe Secret Keys (sk_live_...) |
stripe-restricted-key | critical | Stripe Restricted Keys (rk_live_...) |
sendgrid-api-key | critical | SendGrid API Keys (SG....) |
twilio-api-key | critical | Twilio API Keys (SK...) |
heroku-api-key | critical | Heroku API Keys |
telegram-bot-token | critical | Telegram Bot Tokens |
gcp-service-account-key | critical | GCP Service Account key JSON |
basic-auth-header | high | Basic Auth headers |
connection-string | critical | JDBC/ODBC connection strings with passwords |
google-oauth-client-id | high | Google OAuth Client IDs |
github-oauth-access-token | critical | GitHub OAuth Access Tokens (ghr_...) |
Finding output
Each finding includes:
ruleId— the matched rule (e.g.,aws-access-key)cweId— CWE reference (e.g.,CWE-798for hardcoded credentials)line— line number where the secret was foundsnippet— the matched line (truncated to 200 chars)
Example finding:
{
"id": "segrep-secrets:github-pat:config.js:3",
"title": "GitHub Personal Access Token detected (config.js:3)",
"severity": "critical",
"filePath": "config.js",
"scanner": "segrep-secrets",
"category": "secret",
"ruleId": "github-pat",
"cweId": "CWE-798",
"line": 3,
"snippet": "github_token: \"ghp_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef1234\","
}File coverage
Scanned extensions
.ts, .tsx, .js, .jsx, .mjs, .cjs, .go, .py, .rb, .java, .kt, .scala, .rs, .c, .cpp, .h, .hpp, .sh, .bash, .zsh, .fish, .env, .yml, .yaml, .toml, .ini, .cfg, .conf, .xml, .json, .properties, .config, .dockerfile, .tf, .hcl, .pem, .key, .crt, .cer, .sql, .graphql, .gql
Also scans extensionless files named Dockerfile, Makefile, or Rakefile.
Excluded directories
.git, node_modules, dist, build, .next, .nuxt, coverage, .nyc_output, vendor, .tox, __pycache__, .cache, .parcel-cache, tmp, .segrep
Skipped files
Lockfiles (package-lock.json, yarn.lock, pnpm-lock.yaml, go.sum, Cargo.lock, Gemfile.lock, poetry.lock, composer.lock, Pipfile.lock) and minified files (*.min.js, *.min.css).
Relationship to gitleaks
gitleaksscanner: external binary with git history analysis and rule templatingsegrep-secretsscanner: native regex-based scanner for the working tree, no external dependencies
Use both for maximum coverage, or segrep-secrets alone for fast CI scans without binary installation.
Policy integration
scanners:
- segrep-secrets
# Allowlist known-good findings by rule ID
allowlist:
- google-oauth-client-id
# Ignore test fixtures
ignore_paths:
- "fixtures/**"
- "**/*.test.*"Examples
Secrets only:
docker run --rm -v "$(pwd):/repo:ro" security-scanner:local \
scan /repo --scanners segrep-secretsCombine with dependency scanning:
docker run --rm -v "$(pwd):/repo:ro" security-scanner:local \
scan /repo --scanners segrep-vuln,segrep-secrets --format jsonFail CI on any secret detection:
docker run --rm -v "$(pwd):/repo:ro" security-scanner:local \
scan /repo --scanners segrep-secrets --fail-on critical