fix(backend): auth _next/data requests when __client_uat is missing#7923
fix(backend): auth _next/data requests when __client_uat is missing#7923arthurgeron wants to merge 1 commit intoclerk:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 4b11b50 The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 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 |
|
@arthurgeron is attempting to deploy a commit to the Clerk Production Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Disabled knowledge base sources:
📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR makes handshake initiation conditional by invoking it only when the request is eligible, and guards the IAT vs 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
91dc54f to
79bb92e
Compare
79bb92e to
4b11b50
Compare
|
There's already no JSDocs for these methods, only a few in that module have it. Should I create docs for it anyway? |
Description
Problem
authenticateRequestreturnssignedOutfor_next/datarequests (Next.js Pages Router client-side navigations) when the__client_uatcookie is missing but a valid__sessiontoken exists. The__client_uatcookie is not always sent with fetch requests because it is set withSameSite=Strict(e.g., during development). As a result,getAuth()returns a fully null auth object during client-side navigations, even though the user remains authenticated, and no errors are thrown.Fix
In
backend/src/tokens/request.tson the!hasActiveClient && hasSessionTokenassertion,handleMaybeHandshakeStatusis now only called whenisRequestEligibleForHandshake()returnstrue(document/iframe navigations). For non-handshake-eligible requests (fetch,_next/data), the code falls through to the full token verification pipeline instead of short-circuiting tosignedOut.The
iat < clientUatfreshness comparison is now guarded withauthenticateContext.clientUat &&, so it is skipped whenclientUatis missing, avoiding a incorrect comparison.Handshake-eligible requests (document navigations) are unchanged. This change only affects requests where handshake was already impossible.
Observations
__client_uatwere returned as signedOut without verifying__session. Now, those requests go through the same token verification pipeline used by all other authenticated requests. No verification steps are skipped or weakened.Related issues
handleMaybeHandshakeStatusfails tosignedOut)Testing the fix
@clerk/nextjsuserIdshould be present<Link>userIdis nulluserIdis presentChecklist
pnpm testruns as expected.pnpm buildruns as expected.(If applicable) JSDoc comments have been added or updated for any package exports(If applicable) Documentation has been updatedType of change
Summary by CodeRabbit
Bug Fixes
Tests