Skip to content

fix: decode JWT claims as UTF-8 - #145

Merged
nicknisi merged 1 commit into
mainfrom
riker/119-fix-workos-authkit-js-issue-144-https-gi
Oct 9, 2026
Merged

nicknisi merged 1 commit into
mainfrom
riker/119-fix-workos-authkit-js-issue-144-https-gi

Conversation

@nicknisi

@nicknisi nicknisi commented Oct 9, 2026

Copy link
Copy Markdown
Member

Fix workos/authkit-js issue #144 (#144): getClaims / decodeJwt in src/utils/jwt.ts garble non-ASCII claim values. decodeBase64Url returns atob(...), which yields one character per byte, and the result goes straight to JSON.parse, so a claim like Acme Café comes out as Acme Café. Decode the bytes as UTF-8 before parsing, for both the header and the payload. The issue suggests new TextDecoder().decode(Uint8Array.from(binary, c => c.charCodeAt(0))). Add regression tests in src/utils/jwt.test.ts: a payload with a multi-byte claim (Acme Café), plus a claim using a 4-byte character such as an emoji, round-tripped through decodeJwt and getClaims. Each test must fail on the old code and pass on the new. Plain-ASCII behaviour and error handling must stay unchanged.

Riker's check npx jest src/utils/jwt.test.ts && npm run format:check && npm run build passed.

Opened as a draft by Riker (job 119).

decodeBase64Url returned atob()'s byte-per-char string directly, so
non-ASCII claim values (e.g. "Acme Café") were garbled by decodeJwt and
getClaims. Decode the bytes as UTF-8 with TextDecoder before parsing.

Suggested by @mwhnrt in #144.

Fixes #144
@nicknisi
nicknisi marked this pull request as ready for review October 9, 2026 17:54
@greptile-apps

greptile-apps Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Critical impact] This PR appears safe to merge.

Summary

Fixes garbled non-ASCII JWT values by decoding header and payload bytes as UTF-8 before parsing.

  • JWT headers and claims now keep their UTF-8 text.

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

@nicknisi
nicknisi merged commit b797256 into main Oct 9, 2026
6 checks passed
@nicknisi
nicknisi deleted the riker/119-fix-workos-authkit-js-issue-144-https-gi branch October 9, 2026 18:34
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