Repository navigation
fix(backend): reject non-object JWT header or payload in decodeJwt - #11013
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 5f8f1fb The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 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 |
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/electron
@clerk/electron-passkeys
@clerk/eslint-plugin
@clerk/expo
@clerk/expo-biometrics
@clerk/expo-google-signin
@clerk/expo-native-components
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/mosaic
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
API Changes Report
Summary
No API Changes DetectedAll packages have stable APIs with no detected changes. Report generated by Break Check Last ran on |


Description
authenticateRequest()throwsTypeError: Cannot read properties of null (reading 'iss')when the__sessioncookie holds a three-part token whose payload decodes to the JSON literalnull. In Next.js,clerkMiddleware()callsauthenticateRequest()before the route handler, so every route that the middleware covers returns a 500 until the user clears the cookie. That includes the sign-in page.The cause is in
decodeJwt(). It returned a decoded token whenever the header and the payload parsed as JSON, so values such asnull,42, or[]reached callers that expect objects. #9268 fixed segments that fail to parse, but not segments that parse to a value other than an object. A JWT header and a JWT claims set must both be JSON objects (RFC 7515 and RFC 7519).decodeJwt()now returns aTokenVerificationErrorwith reasontoken-invalidwhen the header or the payload is not a JSON object. Every caller already handles that error, so one check covers all of them:authenticateRequest()returns a signed-out state with reasontoken-invalidwhen__client_uatis set, and a handshake when it is not.__session_<suffix>cookie with anullpayload, which threw onpayload.iat. The other is a machine token in theAuthorizationheader with anullheader, which threw onheader.cat.decodeJwt(),verifyJwt(), andverifyToken()exports throw aTokenVerificationErrorfor these tokens. Before,decodeJwt()returned the token, andverifyJwt()andverifyToken()threw aTypeErrorfor anullheader.Fixes #11010
Fixes CORE-4503
Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change
✎