Repository navigation
fix(client): decode JWT claims as UTF-8 - #141
Open
pcbeingused33 wants to merge 1 commit into
Open
pcbeingused33 wants to merge 1 commit into
pcbeingused33 wants to merge 1 commit into
Conversation
decodeBase64Url returned the raw atob() output, which maps each byte to one character, so multi-byte UTF-8 sequences in access token claims came back as mojibake from useTokenClaims and the token store. Decode the bytes with TextDecoder instead. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Contributor
[Medium impact] The PR appears safe to merge. SummaryFixes non-ASCII JWT claims by decoding their bytes as UTF-8 before reading the JSON.
Reviews (1) · Last reviewed commit: "fix(client): decode JWT claims as UTF-8" · Reviewed by Greptile |
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.
Summary
useTokenClaims()(and anything else that goes through the client-sidedecodeJwt) returns mojibake for non-ASCII claims in the access token. A claim such as"name": "José Muñoz 日本語"comes back as"José Muñoz æ¥æ¬èª".Root cause
decodeBase64Urlinsrc/client/jwt.tsreturned the output ofatob()directly.atob()produces a binary string with one character per byte, so every multi-byte UTF-8 sequence in the JWT header or payload was split into separate Latin-1 characters beforeJSON.parsesaw it.Fix
Convert the
atob()output to aUint8Arrayand decode it withTextDecoder(UTF-8). ASCII-only tokens decode exactly as before. The change is limited todecodeBase64Url;decodeJwtand its callers (useTokenClaims,tokenStore) are untouched.Test
Added a case to
src/client/jwt.spec.tsthat builds a token whose payload contains accented, CJK and emoji characters and asserts the claim round-trips. It fails onmain(expected 'José Muñoz …' to be 'José Muñoz 日本語 🚀') and passes with the fix.pnpm exec vitest run src/client/jwt.spec.ts: 4 passedpnpm exec vitest run: 313 passedoxfmt --check,oxlintandtsc --noEmitare cleanThis PR was prepared with the help of an AI coding assistant (Claude Code).