Repository navigation
fix: don't print the API token in error output - #160
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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp
natevick
marked this pull request as ready for review
November 22, 2026 21:56
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.
selno longer prints the active API token when a server echoes it back in an error.Merge this together with the stacked fix PR. On its own, this PR mangles ordinary words when the token is very short. No Linear ticket, because the workspace is at its free issue limit.
What changed
internal/redactpackage. The API client registers the token it's using.Checks
Results are on the stacked PR, which is the code that should ship. This PR had one grok and one Opus pass. The fix had one grok pass and an independent verifier.
🤖 Generated with Claude Code
https://claude.ai/code/session_0186m4FrY9RHAiNN1uxztLCp