Conversation
This branch has not been deployed
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.
What and why
Closes #87
decodeJwtonly checked whetherJSON.parsethrew, not what it returned.JSON.parse("null"),JSON.parse("[]")andJSON.parse("123")all succeed, so a token with anull, array or primitive header or payload came back asok: truecarrying a value that was not actually aRecord<string, unknown>. Every reader downstream then threw on it —securityAudit,computeHealth,verifyJwt,verifyWithJwksandJwtDecoderClientall read.algor.expoff that value.The guard is now applied to both parsed halves. RFC 7519 defines the JOSE header and the claims set as JSON objects, so a non-object result is rejected with a message that names which half was wrong, in the same voice as the existing decode errors.
Type of change
Checklist
npm run lint && npm run test && npm run buildpasses locallylib/and have a test inlib/__tests__/page.tsx, client component,opengraph-image.tsx, and the bug report dropdown are all done — not a new toolTests
Added 7 cases to
lib/__tests__/jwt-utils.test.tscovering anullheader, an array header, anullpayload, an array payload, a primitive payload, the issue'sbnVsbA.e30.xtoken, and a guard that a well-formed token still decodes.npx vitest run lib/__tests__/jwt-utils.test.tsnpm test(full suite)npm run lintlib/useLocalStorage.ts)npm run buildThe new cases fail on the base commit and pass with the fix: with
lib/jwt-utils.tsreverted, 6 of them fail; restored, all 13 pass.A direct probe of the base behaviour also showed
verifyJwt("bnVsbA.e30.x", ...)rejecting withTypeError: Cannot read properties of null (reading 'alg')— including as an unhandled promise rejection. That path is now unreachable from the UI:decodeJwtreturnsok: false, soJwtDecoderClientkeepsdecodednull and never renders the verify panel.Notes for reviewers
verifyJwt/verifyWithJwks, which the issue marks as optional.decodeJwtnow rejects the token first,VerifyPanelis only rendered whendecodedis truthy, andrunVerifyis wrapped in atry/catchanyway. Adding it would change code the issue did not ask for. Happy to include it if you would rather have the defence in depth.bnVsbA.e30.xshows the normal "Decoding failed" banner) was verified by reading the code path, not by clicking through the browser.Record<string, unknown>cast only after the shape check, so the declared type is now actually true.🤖 Generated with Claude Code