Skip to content

feat(protect): default vendor-secret redaction + prefilter anchors + ReDoS test - #107

Merged
patchstackdave merged 2 commits into
mainfrom
feat/default-vendor-secret-redaction
Aug 12, 2026
Merged

feat(protect): default vendor-secret redaction + prefilter anchors + ReDoS test#107
patchstackdave merged 2 commits into
mainfrom
feat/default-vendor-secret-redaction

Conversation

@patchstackdave

Copy link
Copy Markdown
Contributor

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 redact rule (resp-vendor-api-key) covering tokens that never legitimately appear in a response body:

  • Stripe sk_live_ / rk_live_
  • GitHub ghp_/gho_/ghs_/ghu_ + github_pat_
  • GitLab glpat-
  • Slack xox[baprs]-
  • Anthropic sk-ant-
  • Google OAuth ya29.
  • npm 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. redact masks 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

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>
@coderbuds

coderbuds Bot commented Aug 12, 2026

Copy link
Copy Markdown

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

See how your team is trending →

@patchstackdave

Copy link
Copy Markdown
Contributor Author

/review

Comment thread src/protect/defaults.js
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])/' } }]
},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should those be hardcoded?

…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>
@patchstackdave patchstackdave changed the title feat(protect): ship vendor API-key redaction by default feat(protect): default vendor-secret redaction + prefilter anchors + ReDoS test Aug 12, 2026
@patchstackdave
patchstackdave merged commit 4995abf into main Aug 12, 2026
4 checks passed
@patchstackdave
patchstackdave deleted the feat/default-vendor-secret-redaction branch August 12, 2026 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants