Skip to content

fix: close review findings on verification, flags, and output - #31

Merged
bsg62 merged 1 commit into
mainfrom
fix/review-findings
Sep 5, 2026
Merged

bsg62 merged 1 commit into
mainfrom
fix/review-findings

Conversation

@bsg62

@bsg62 bsg62 commented Sep 4, 2026

Copy link
Copy Markdown
Member

Summary

Fixes the five findings from a codebase review. No behavior changes for well-formed inputs; each fix tightens an edge.

  • Allowlist fails closed. validMethodsForKey returns an empty list for unknown key types and verifyJWTSignature rejects such a key outright ("key type cannot verify a JWS"). Previously an X25519 key (a valid JWE key, parseable via PKCS#8 or JWK) skipped the allowlist and relied on each Verify implementation's type assertion to refuse it. AGENTS.md documents the rule.
  • --color is validated before --json is applied, so --json --color=bogus errors like the non-JSON path does.
  • An empty stdin pipe reports "no token provided", sharing a sentinel with the interactive prompt, instead of "token contains an invalid number of segments".
  • JWE resolves the key before printing, so an unusable key yields the error alone rather than a partial Protected Header on stdout.
  • writeFormattedJSON scans the buffer once, delegating the fast-path decision to the escaper.

Test plan

  • New tests: TestVerifyJWTSignature_RejectsKeyTypeWithoutJWSAlgorithms, TestReadToken_EmptyStdinPipe, TestDecodeAndPrintJWE_UnusableKeyPrintsNothing, plus a --json case in TestApplyColorMode
  • go vet ./..., gofmt -l ., go test ./... pass
  • Built binary checked by hand: --json --color=bogus and an empty pipe both exit 1 with the intended message

🤖 Generated with Claude Code

https://claude.ai/code/session_01GzPGnho3TkRuJx4sDpjajK

- Reject JWS verification keys with no JWS algorithms (e.g. X25519)
  explicitly, so the alg allowlist fails closed instead of being skipped
- Validate --color before --json forces color off, so a bad value errors
  under both output modes
- Report an empty stdin pipe as "no token provided", matching the
  interactive prompt, instead of a malformed-token parse error
- Resolve the JWE decryption key before printing any section, so an
  unusable key produces the error alone
- Scan formatted JSON once in writeFormattedJSON

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GzPGnho3TkRuJx4sDpjajK
@bsg62
bsg62 force-pushed the fix/review-findings branch from f182584 to 743c59a Compare September 5, 2026 16:04
@bsg62
bsg62 merged commit 2df5fca into main Sep 5, 2026
8 checks passed
@bsg62
bsg62 deleted the fix/review-findings branch September 8, 2026 20:26
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.

1 participant