Skip to content

fix(client): decode JWT claims as UTF-8 - #141

Open
pcbeingused33 wants to merge 1 commit into
workos:mainfrom
pcbeingused33:fix/jwt-utf8-claims
Open

pcbeingused33 wants to merge 1 commit into
workos:mainfrom
pcbeingused33:fix/jwt-utf8-claims

Conversation

@pcbeingused33

Copy link
Copy Markdown
Contributor

Summary

useTokenClaims() (and anything else that goes through the client-side decodeJwt) 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

decodeBase64Url in src/client/jwt.ts returned the output of atob() 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 before JSON.parse saw it.

Fix

Convert the atob() output to a Uint8Array and decode it with TextDecoder (UTF-8). ASCII-only tokens decode exactly as before. The change is limited to decodeBase64Url; decodeJwt and its callers (useTokenClaims, tokenStore) are untouched.

Test

Added a case to src/client/jwt.spec.ts that builds a token whose payload contains accented, CJK and emoji characters and asserts the claim round-trips. It fails on main (expected 'José Muñoz …' to be 'José Muñoz 日本語 🚀') and passes with the fix.

  • pnpm exec vitest run src/client/jwt.spec.ts: 4 passed
  • pnpm exec vitest run: 313 passed
  • oxfmt --check, oxlint and tsc --noEmit are clean

This PR was prepared with the help of an AI coding assistant (Claude Code).

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>
@greptile-apps

greptile-apps Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Fixes non-ASCII JWT claims by decoding their bytes as UTF-8 before reading the JSON.

  • JWT decoding preserves non-ASCII text in token claims.

Reviews (1) · Last reviewed commit: "fix(client): decode JWT claims as UTF-8" · Reviewed by Greptile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant