fix(core): decode JWT payload as UTF-8#218
Merged
cameronapak merged 2 commits intomainfrom Apr 28, 2026
Merged
Conversation
🦋 Changeset detectedLatest commit: 5b50456 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Decode base64 JWT payload bytes as UTF-8 before JSON parsing to prevent mojibake for non-ASCII claims, and remove the Latin-1 fallback path so regressions cannot silently return garbled text. Made-with: Cursor
99cad3b to
acc863a
Compare
Mark a patch release for platform-core so the JWT decoding fix ships, and let the fixed package group advance hooks and ui to the same version. Made-with: Cursor
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
YouVersionAPIUsers.decodeJWT()beforeJSON.parseto prevent mojibake for non-ASCII claims.Test plan
YVP_API_HOST=api.youversion.com pnpm --filter @youversion/platform-core test -- src/__tests__/Users.test.tsMade with Cursor
Greptile Summary
This PR fixes mojibake for non-ASCII JWT claims by converting the Latin-1 byte string returned by
atobinto aUint8Arrayand re-decoding it as UTF-8 viaTextDecoderbefore passing toJSON.parse. The change is minimal, correctly scoped, and the previousTextDecoderconditional-fallback concern from earlier review rounds has been resolved — the implementation now relies solely on the existingtry/catchto handle any decode failure gracefully.Confidence Score: 5/5
Safe to merge — no P0 or P1 findings; fix is correct, well-tested, and non-breaking.
The implementation correctly addresses the mojibake bug with a standard
atob→Uint8Array→TextDecoderpattern. All existing tests continue to pass (ASCII payloads are valid UTF-8), a dedicated regression test covers the non-ASCII case, and error paths remain unchanged. No P1 or P0 issues were identified.No files require special attention.
Important Files Changed
atobindecodeJWTusingUint8Array+TextDecoder; fix is correct and the try/catch handles any unavailability gracefully.atobreturning a Latin-1 byte string of the UTF-8 payload.@youversion/platform-core; version bump type is appropriate for a bug fix.Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[decodeJWT token] --> B{3 segments?} B -- No --> C[return empty object] B -- Yes --> D[base64url to standard base64 replace dashes and pad] D --> E{base64 truthy?} E -- No --> C E -- Yes --> F[atob base64 - Latin-1 byte string] F --> G[Uint8Array.from data via charCodeAt] G --> H[TextDecoder utf-8 .decode bytes] H --> I[JSON.parse decodedPayload] I --> J[return parsed object] I -- throws --> K[catch - return empty object]Reviews (3): Last reviewed commit: "chore: add changeset for UTF-8 JWT decod..." | Re-trigger Greptile