Redact compound secret key names and doubled-quote JSON - #274
Open
mostafaseyedan wants to merge 1 commit into
Open
mostafaseyedan wants to merge 1 commit into
mostafaseyedan wants to merge 1 commit into
Conversation
redactSecrets masks transcript text before it is sent to a language model, but two common shapes slipped through it unchanged. Both assignment patterns anchor the key name with \b, which does not match between an underscore and a letter. `client_secret`, `refresh_token`, `app_token` and `db_password` therefore never matched, while the bare `secret` and `token` forms did. Match an optional compound prefix so the qualified names are covered too. The quote group also accepted a single quote character only. JSON embedded in a shell command is routinely escaped by doubling its quotes, as Claude Code does when recording a curl invocation in a permission allow rule, so `""client_secret"":""…""` matched neither pattern. Accept quote runs of one or two characters. Add the Context7 key prefix alongside the other vendor tokens; its `ctx7sk-` form is not reachable by the existing `sk-` pattern because the leading digit suppresses the word boundary. Checked against a real settings file: two credential-shaped strings survived redaction before, none do now, and prose mentioning "token", "secret" or "password" is still left intact.
github-actions
Bot
requested review from
TamasBoncz,
Aymen (aymenfurter) and
Sanjay Singh (san360)
September 21, 2026 03:09
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.
Problem
redactSecretsmasks credential-shaped text before it is sent to a language model — bycallLlm/callLlmJsonviaredactMessages, so it guards every AI feature. Two common shapes pass through it unchanged.1. Compound key names. Both assignment patterns anchor the key with
\b:/\b(api[_-]?key|access[_-]?key|secret|token|password|passwd|credentials?)…/gi\bdoes not match between_and a letter, soclient_secretnever matches while baresecretdoes:2. Doubled-quote JSON. The quote group accepts exactly one quote character. JSON embedded in a shell command is routinely escaped by doubling its quotes — which is how Claude Code records a
curlinvocation in a permission allow rule:(["'])captures one", the content class then immediately hits the second", and the match fails. Neither pattern fires.These combine badly in practice. A
.claude/settings.local.jsonaccumulatesBash(curl …)allow rules verbatim, so OAuth client secrets end up stored in exactly the shape that defeats both patterns, and Context Health reads those files and sends them to the model.3. Separately, a Context7 key (
ctx7sk-…) is not reachable by the existingsk-pattern, because the preceding digit suppresses the word boundary.Fix
SECRET_KEY_NAMEwith an optional(?:[A-Za-z0-9]+[_-])*prefix, so qualified names are covered.ctx7sk-alongside the other vendor prefixes.client_idis deliberately still not redacted — it is an identifier rather than a credential, and adding it would start redacting ordinary config.Testing
Four tests added. Verified against a real 122-rule
settings.local.json: two credential-shaped strings survived redaction before, none do after, 18 redaction markers inserted.False-positive checked — these are still returned unchanged:
All 25 tests in
redact-secrets.test.tspass (21 pre-existing, unmodified).npm run typecheckandnpm run lintclean (0 errors). The 7github-app-analyticsfailures are pre-existing onmain.