Repository navigation
fix: redaction leaves words alone and covers codes and pending approvals - #161
Merged
Merged
Conversation
If a server error echoed the caller's token, every command except `sel doctor` printed it on stdout and stderr, with and without --timeout. `sel doctor` already redacted it. v0.4.0 behaves the same way, so #149 did not cause this. internal/redact keeps the tokens the CLI sent. api.New registers each one, which covers SELECTIVE_TOKEN, the keychain, the config file, `auth login --with-token` and the legacy `auth --token`, because all of them build their client there. runWith clears the set on entry and replaces every registered token with [redacted] in the classified error: the message, and every field, nested ones included, in raw and JSON-escaped form. It does that before writeErrorObject, so the 512 byte cut in BoundedError can no longer leave part of a token behind. `sel auth logout` also prints its revoke failure through redact.String. Only an error that held a token is rebuilt. The rebuilt error keeps the original ErrorCode and ExitCode (api.Error derives its exit from the HTTP status, which contract.Error would not), and a field is replaced only when it held a token, so fields["doctor"] stays a *doctor.Report. Numbers are decoded with UseNumber. Nothing else changes: an error without a token is the same object, an empty token is never stored, and success output, including `tokens create`, is not touched. Not covered, deliberately: - A token minted by `tokens create` and one granted by browser login are not registered. The CLI sends neither again in the same run, so no server error can echo them. - Approval documents printed for exit 7 are not scrubbed: they are not errors, and whether the server puts a token in them was not checked. - doctor keeps its own single-secret redaction (internal/doctor); it fails closed differently and is tested separately. - A very short token redacts every occurrence of its characters. Real tokens start with sk_live_. Existing tests that sent the token `tok` saw it inside "token", so approvals_test.go now sends sk_live_tests and tokens_test.go's fixture messages no longer say "token". Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
Fixes the five review findings on 080b05e. 1. Short tokens corrupted words ("Invalid token." became "Invalid [redacted]en." with token tok). A token under 16 characters (anywhereLength) now matches only with no [A-Za-z0-9_-] on either side. 16 or more match anywhere, so x%3D<token>y is replaced. 2. tokens_test.go and approvals_test.go are restored byte for byte to 1fe02ec and pass unedited. 3. Redaction no longer replaces inside raw JSON. Fields are decoded (UseNumber), walked, and only string values and map keys are cleaned. An unchanged value is returned as it was. 4. The error code is cleaned, keeping the original ExitCode. 5. A 202's approval is cleaned where api.pendingResponse builds it, so exit 7 JSON, the terminal sentence and the --wait announcement all read a clean document. Exit 7, id and status are kept. Keys that clean to the same string collapse to one entry. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
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.
Review fixes for token redaction: ordinary words stay intact, and tokens in error codes and pending approvals are now removed.
Stacked on the redaction PR. Merge the two together.
What changed
Invalid token.is untouched when the token istok. Longer tokens match anywhere.errorcode is cleaned, and the exit code still comes from the original code.Checks
An independent run with its own stub server compared three real binaries: before redaction, the first commit, and this one. All 8 conditions passed, and every condition that needed the bug showed it on the first commit.
Invalid token.byte-identical to before redaction.--timeout.go veton all three platforms,go test -race, and golangci-lint 1.64.8 pass.Not established
SELECTIVE_TOKEN. Config, keychain and stdin weren't driven, and browser-grant and newly minted tokens aren't registered.approvals showandsuites deletewere driven end to end.sel testevent fields, a real server's echo, and the cancelled-auth and panic paths weren't checked.%2Ftok) isn't replaced.🤖 Generated with Claude Code
https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp