Skip to content

fix(config): show only last 4 characters of API key in config show#78

Merged
electather merged 1 commit intomainfrom
feat/mask-api-key-config-show
Mar 16, 2026
Merged

fix(config): show only last 4 characters of API key in config show#78
electather merged 1 commit intomainfrom
feat/mask-api-key-config-show

Conversation

@electather
Copy link
Owner

Summary

Replace the first4****last4 masking format with ********last4 so the API key prefix is never shown in plain text. This prevents accidental exposure when screenshots or logs of config show output are shared.

Closes #67

Changes

  • cmd/config/show.go: new masking logic — keys longer than 4 chars get "********" + last4; keys of 4 chars or fewer get "****"; absent keys still show <not set>
  • tests/config_test.go: update existing assertion to expect the new ********2345 format and verify the prefix is not visible on the API Key: line
  • tests/config_show_mask_test.go: new table-driven tests covering long keys, exactly-5-char keys, 4-char keys, 2-char keys, and absent keys

Test plan

  • go test -v ./... passes
  • go fmt ./... produces no diff
  • go build succeeds

Checklist

  • New tests added for new behaviour
  • Documentation updated (README, command --help, comments)
  • No unrelated changes included

Replace the prefix-exposing mask (first4****last4) with ********last4
so the key prefix is never revealed in output. Short keys (≤ 4 chars)
remain fully masked as ****, and absent keys continue to show <not set>.

Closes #67
@electather electather merged commit b84920b into main Mar 16, 2026
2 checks passed
@electather electather deleted the feat/mask-api-key-config-show branch March 16, 2026 13:12
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.

security: Reduce API key exposure in config show output

1 participant