fix(EXPOSED_SECRETS): detect modern API key formats (OpenAI sk-proj/svcacct, Anthropic, GitHub, Google, Slack, Stripe)#29
Open
dmchaledev wants to merge 1 commit into
Open
Conversation
…vcacct, Anthropic, GitHub, Google, Slack, Stripe)
The CRITICAL EXPOSED_SECRETS rule only matched legacy OpenAI keys
(sk-<alnum>), classic GitHub PATs (ghp_), and AWS access keys. It
silently missed the secret formats most commonly found in AI/MCP
configs today:
- OpenAI project / service-account / admin keys (sk-proj-, sk-svcacct-,
sk-admin-) — these contain hyphens/underscores, which the old
alphanumeric-only pattern stopped on
- Anthropic keys (sk-ant-)
- GitHub OAuth / app / refresh tokens (gho_, ghu_, ghs_, ghr_) and
fine-grained PATs (github_pat_)
- Google API keys (AIza...)
- Slack tokens (xox[baprs]-...)
- Stripe live secret/restricted keys (sk_live_, rk_live_)
For a security scanner whose CRITICAL rule is "Potential Secret Exposed
in Configuration," missing current provider key formats is a meaningful
false negative.
Broaden SECRET_PATTERNS to cover these formats while keeping the legacy
patterns. Add EXPOSED_SECRETS tests (none existed): one positive case per
supported format, plus negative cases for benign strings and a JWT-style
bearer token to guard against false positives.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HiLyXzy6TuD5KXXHLGq3Pu
This was referenced Jun 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The CRITICAL
EXPOSED_SECRETSrule (src/rules/runtime-rules.ts) only matched legacy secret formats:It silently missed the secret formats most commonly found in AI/MCP configs today — including the LLM provider keys an MCP server is most likely to carry. Verified against the current patterns:
sk-…sk-proj-…sk-svcacct-…sk-ant-…ghp_…gho_/ghu_/ghs_/ghr_github_pat_…AKIA…AIza…xoxb-…sk_live_…/rk_live_…Root cause for the OpenAI miss: modern keys (
sk-proj-,sk-svcacct-,sk-ant-) contain hyphens/underscores, and the old[a-zA-Z0-9]-only run stops at the first-, so the{20,}length is never reached.For a scanner whose CRITICAL rule is "Potential Secret Exposed in Configuration", missing current provider key formats is a meaningful false negative — and especially relevant for an AI/MCP scanner, since
sk-proj-/sk-ant-keys are exactly what these servers tend to hold.Changes
SECRET_PATTERNSto cover modern OpenAI (project/service-account/admin), Anthropic, the full GitHub token family + fine-grained PATs, Google API keys, Slack tokens, and Stripe live/restricted keys. Legacy patterns are preserved.EXPOSED_SECRETStests (the rule previously had zero test coverage): one positive case per supported format, plus negatives for benign config strings and a JWT-style bearer token (the kind used inexamples/secure-config.json) to guard against false positives.Verification
npm run typecheck,npm run lint,npm test(113 passing) all green.examples/secure-config.jsonstill passes (no new false positives); a config carrying ansk-proj-…key now correctly fails with a CRITICALEXPOSED_SECRETSfinding.Scope
Detection only. Redaction of matched secrets in finding
evidenceis tracked separately in #28, and the missed-password case in #14 — this PR is complementary and does not overlap with either.🤖 Generated with Claude Code
Generated by Claude Code