feat(protect): default vendor-secret redaction + prefilter anchors + ReDoS test - #107
Merged
Merged
Conversation
The default response ruleset covered private keys, AWS/GCP keys, JWTs, DB strings, and error/stack-trace leaks — but not the high-signal provider tokens that most often leak from AI-built apps. Add one prefix-anchored default redact rule covering Stripe (sk_live_/rk_live_), GitHub (gh[opsu]_ / github_pat_), GitLab (glpat-), Slack (xox[baprs]-), Anthropic (sk-ant-), Google OAuth (ya29.), and npm (npm_). These never legitimately appear in a response body, so default redaction is low-FP; every site gets it with no rule authoring. Tests: 9 new (8 token classes masked + a no-false-positive case); 604 pass; typecheck clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Adds robust prefilters and vendor token redaction with clear, performant rules. 🎯 Quality: 100% Elite · 📦 Size: Small 📈 This month: Your 49th PR — above team average · Averaging Elite |
Contributor
Author
|
/review |
devlob
reviewed
Aug 12, 2026
Comment on lines
+35
to
+46
| { | ||
| id: 'resp-vendor-api-key', | ||
| title: 'Vendor API key / token in response body', | ||
| phase: 'response', | ||
| category: 'secret-exposure', | ||
| action: 'redact', | ||
| // High-signal, prefix-anchored provider tokens that never legitimately appear in a response | ||
| // body: Stripe (sk_live_/rk_live_), GitHub (gh[opsu]_ / github_pat_), GitLab (glpat-), | ||
| // Slack (xox[baprs]-), Anthropic (sk-ant-), Google OAuth (ya29.), npm (npm_). Trailing | ||
| // (?![0-9A-Za-z]) instead of \\b since some tokens end in - / _ . | ||
| rule_v2: [{ parameter: 'response.body', match: { type: 'regex', value: '/\\b(?:sk_live_[0-9A-Za-z]{16,}|rk_live_[0-9A-Za-z]{16,}|gh[opsu]_[0-9A-Za-z]{36}|github_pat_[0-9A-Za-z_]{60,}|glpat-[0-9A-Za-z_-]{20,}|xox[baprs]-[0-9A-Za-z-]{10,}|sk-ant-[0-9A-Za-z_-]{20,}|ya29\\.[0-9A-Za-z_-]{20,}|npm_[0-9A-Za-z]{36})(?![0-9A-Za-z])/' } }] | ||
| }, |
devlob
approved these changes
Aug 12, 2026
…rf test Give each default response rule a cheap literal `prefilter` (necessary-substring anchors of its regex: PRIVATE KEY, AKIA/ASIA, AIza, eyJ, the vendor prefixes, DB schemes, SQL-error markers, exception/traceback markers). Once the response-phase prefilter mechanism lands (separate PR), a body with no anchor skips the rule's regex entirely — cutting CPU/latency and shrinking the regex/ReDoS surface. Inert (harmless) until that mechanism is present. Also add a ReDoS/perf test: a ~280 KB adversarial body of near-miss inputs is screened in linear time (<1s), guarding against catastrophic backtracking in the shipped defaults. 605 tests pass; typecheck clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Why
The default response ruleset (
defaults.js) redacts private keys, AWS/GCP keys, JWTs, DB connection strings, and error/stack-trace leaks — but not the high-signal vendor API tokens that most often leak from AI-built apps (a key echoed into a debug JSON, an error body, or an admin view). The output-filtering review flagged this as the top rules-only default gap.What
One prefix-anchored default
redactrule (resp-vendor-api-key) covering tokens that never legitimately appear in a response body:sk_live_/rk_live_ghp_/gho_/ghs_/ghu_+github_pat_glpat-xox[baprs]-sk-ant-ya29.npm_Prefix-anchored + length-bounded → low false-positive, so it's safe to ship on by default; every site gets it with zero rule authoring.
redactmasks the token and still serves the response.Tests
tests/protect/default-secret-rules.test.ts— 9 new: each token class is masked by default, plus a no-false-positive check on an ordinary JSON body. Sample tokens are assembled from split fragments at runtime so no contiguous secret literal sits in the source (secret-scanning push protection). 604 pass; typecheck clean.🤖 Generated with Claude Code