Repository navigation
fix(errors): redact direct stream and normalized overflow messages - #155
Merged
patlux merged 1 commit intoOct 15, 2026
Merged
Conversation
karaaslanz
marked this pull request as ready for review
October 14, 2026 09:04
pierreraby
approved these changes
Oct 14, 2026
pierreraby
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed at exact head b78d21ab993f70e5b352716858f7074d68a065d4 against base b61093de3f866fc533f827a25a27bc342e9d678d.
Verification (isolated worktree, npm ci)
npm run typecheckPASS,npm run test:overflow10/10 PASS,npm run test:unitexit 0 (392 checks, 0 failures),npm run test:pi-localPASS (the e2e that assertscontext_length_exceeded:prefixing and the no-secrets remnant), Prettier check on both changed files PASS,git diff --checkPASS.- RED proven on base: the two new tests applied to
b61093dfail (8/10, exactly the two new ones), GREEN at this head. - An independent fresh-context review confirms: the guards in
normalizeCommandCodeErrorMessageall run on the raw text before redaction, so classification cannot change; thecontext_length_exceeded:prefix is prepended after redaction; and the redactor is a fixed point (redact(redact(x)) === redact(x)), which matters because production stacks it (commandCodeErrorMessage→src/core.tsdetail assembly). - The genuinely reachable case fixed here is the normalize boundary:
message_endcan receive anerrorMessageproduced by the native/compat path that was never redacted (src/transport.tsbuilds its terminal error from the raw message), and base prefixing exposed it verbatim. The string branch ofcommandCodeErrorMessageis defense-in-depth for its current callers, matching the author's framing.
Notes
- (P2, tradeoff) The shared redactor masks some non-secret diagnostics on these two surfaces:
USER_TOKEN_PATTERNcatchesuser_*/cc_*snake_case codes (user_not_found,cc_request_timeout), andCREDENTIAL_PATTERNcatchestoken: 5000-style values. Classification is unaffected, and the dominant final-error path already redacted on base, so this is an acceptable defense-in-depth tradeoff — worth a conscious sign-off (and a line in the release changelog). - (P3, pre-existing) Redactor format gaps unchanged by this PR, now reachable at two more boundaries:
BEARER_PATTERN's character class omits_(Bearer user_secret), andCREDENTIAL_PATTERNdoes not match JSON-quoted keys ("api_key":"value"). Optional follow-up. - (P3, tests) A classify-before-redact assertion (e.g. a message whose keywords would be destroyed by redaction still detected) and an idempotence test would pin the two properties production relies on.
No P0/P1 findings; residual risk is low. Approving.
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
Two exported Command Code error helpers apply inconsistent credential redaction:
commandCodeErrorMessage(...)redacts extracted object fields, but returns a direct string unmodified.normalizeCommandCodeErrorMessage(...)adds thecontext_length_exceededprefix to raw upstream error text without redacting embedded credentials.normalizeCommandCodeMessage(...)inherits that behavior.This is a defense-in-depth consistency issue in helper outputs; existing production callers also perform downstream redaction in some paths. This PR does not claim an observed external credential leak.
Fix
Reuse the existing
redactCommandCodeErrorText()helper at those two return boundaries; preserve existing overflow classification and non-overflow rejection logic. No regex or broader API changes.Tests
Two new focused tests using synthetic strings only:
api_key=direct_secret_valueis redacted;api_key=overflow_secretare redacted.RED: new tests fail on unchanged upstream
b61093d(8/10 passing).GREEN: all 10/10 overflow tests pass on
b78d21a;npm run typecheckPASS, Prettier check for both edited files PASS,git diff --checkPASS.Exactly two files changed:
src/overflow.tsandtests/test-overflow.ts. Full suite not run locally. Exact-head upstream GitHub Actions CI completed SUCCESS (9/9 CI jobs: format, typecheck, Semgrep, CodeQL, Gitleaks, dependency review, npm audit, lifecycle and Oh My Pi). The separate memory benchmark is pending and excluded from this CI result.