Conversation
…itioned cookie reads When `partitionedCookies` is enabled via Environment, the browser treats partitioned and non-partitioned cookies with the same name as distinct. Before this fix, `getDevBrowser()` read directly from `document.cookie`, which could return a stale non-partitioned duplicate instead of the correct partitioned value. This change introduces an in-memory cache for the dev browser token so that FAPI interceptors always use the authoritative value — whether it came from the URL query param, a cookie, or a FAPI response header — regardless of cookie read ordering. Made-with: Cursor
🦋 Changeset detectedLatest commit: fe8f025 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
@clerk/agent-toolkit
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
Made-with: Cursor
Made-with: Cursor
| // Hold the dev browser token in memory so it's always available to FAPI | ||
| // interceptors, even before Environment resolves and cookies can be written | ||
| // with the correct Partitioned attribute. | ||
| let devBrowserInMemory: string | undefined; |
There was a problem hiding this comment.
I can't think of a reason why this wouldn't be safe. Potentially if there are already multiple dev browser cookies and a different value would have been read from cookies, but that would be a separate issue for us.
- Dev browser should be unique per device per instance
- Using this in-memory value should actually be more efficient and avoid unnecessary cookie reads
- Any time the dev browser cooke is mutated on the client this value is updated accordingly
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis pull request introduces an in-memory cache mechanism for the dev browser token in 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/clerk-js/src/core/auth/devBrowser.ts`:
- Around line 91-94: In setup(), avoid seeding devBrowserInMemory from
devBrowserCookie.get() before legacy cleanup: run the same legacy
non-partitioned cookie removal logic that set() performs (i.e., remove the
legacy/non-partitioned cookie) or otherwise detect whether a partitioned cookie
exists and skip adopting a stale value; in practice update setup() to invoke the
legacy-cookie cleanup routine used by set() (or inline the removal of the old
non-partitioned cookie) before reading devBrowserCookie.get() so
devBrowserInMemory never caches a stale legacy token.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: ASSERTIVE
Plan: Pro
Run ID: fb661217-ba4c-4b4b-8159-bc56705d2b93
📒 Files selected for processing (3)
integration/tests/dev-browser-partitioned-cookies.test.tspackages/clerk-js/src/core/auth/__tests__/devBrowser.test.tspackages/clerk-js/src/core/auth/devBrowser.ts
…itioned cookie reads (#8161)
Summary
createDevBrowsersogetDevBrowser()always returns the authoritative value, regardless ofdocument.cookieread ordering__clerk_db_jwtcookie whenpartitionedCookiesis enabled, since the browser treats partitioned and non-partitioned cookies with the same name as distinct entriesTest plan
__clerk_db_jwtin the URL, all FAPI requests use the URL tokenMade with Cursor
Summary by CodeRabbit
Bug Fixes
Tests