Skip to content

feat(clerk-js): Use SameSite=none by default for development instances #6374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

brkalow
Copy link
Member

@brkalow brkalow commented Jul 22, 2025

Description

In development, we want to make sure that Clerk can work across a variety of environments, one being embedded previews in Gen AI tools (or other similar flavor of builders). When setting cookies in a cross origin iframe, we need to use "SameSite=none. Additionally, we want to make sure that the previews retain session state when opened in a new window ("full-screen"), so we can't rely on something like CHIPS.

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

Summary by CodeRabbit

  • Bug Fixes

    • Improved cookie handling to ensure correct behavior in both production and development environments, particularly when the app is embedded in iframes.
    • Adjusted cookie attributes for enhanced compatibility and security based on environment.
  • Tests

    • Updated and expanded tests to verify cookie behavior across different environments and scenarios.
  • Chores

    • Internal updates to support future enhancements and maintain consistency in cookie management.

Copy link

vercel bot commented Jul 22, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
clerk-js-sandbox ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 28, 2025 8:51pm

Copy link

changeset-bot bot commented Jul 22, 2025

🦋 Changeset detected

Latest commit: 33307ee

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@clerk/clerk-js Minor
@clerk/chrome-extension Patch
@clerk/clerk-expo Patch

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

@brkalow brkalow changed the base branch from main to brk.fix/unset-cookies-on-sign-out July 22, 2025 19:56
Copy link
Contributor

coderabbitai bot commented Jul 22, 2025

📝 Walkthrough

Walkthrough

This change updates the handling of cookies within the authentication core of the codebase, focusing on environment-based cookie attribute settings. Several cookie helper functions (createClientUatCookie, createSessionCookie, createDevBrowserCookie) now accept an options object with cookieSuffix and an isProduction boolean instead of a single string. The logic for the SameSite cookie attribute was revised to use 'None' in development and 'Strict' or 'Lax' in production, depending on the cookie type. Corresponding tests were updated to reflect these changes. Additionally, the AuthCookieService was enhanced by adding an event listener for user sign-out events to remove and reset relevant cookies. A changeset documents this minor version update.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Complexity label: Moderate
Rationale:
The changes span multiple core modules and test suites, involve updates to cookie handling logic and function signatures, and require validation of environment-specific behavior. While the scope is focused and does not introduce broad architectural changes, the review demands attention to detail across interconnected files.

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 35b48cd and 33307ee.

📒 Files selected for processing (1)
  • packages/clerk-js/src/core/auth/cookies/__tests__/session.test.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/clerk-js/src/core/auth/cookies/tests/session.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Build Packages
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep/ci

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

pkg-pr-new bot commented Jul 22, 2025

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@6374

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@6374

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@6374

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@6374

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@6374

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@6374

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@6374

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@6374

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@6374

@clerk/express

npm i https://pkg.pr.new/@clerk/express@6374

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@6374

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@6374

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@6374

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@6374

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@6374

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@6374

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@6374

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@6374

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@6374

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@6374

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@6374

@clerk/types

npm i https://pkg.pr.new/@clerk/types@6374

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@6374

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@6374

commit: 33307ee

Comment on lines 53 to 54
sessionCookie.remove();
suffixedSessionCookie.remove();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we prefer remove() which also includes attributes ?

const sameSite = __BUILD_VARIANT_CHIPS__ ? 'None' : inCrossOriginIframe() ? 'None' : 'Strict';
const sameSite = __BUILD_VARIANT_CHIPS__
? 'None'
: inCrossOriginIframe()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was making inCrossOriginIframe to not detect the iframe usage inside the GenAI tools ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was working, but one issue we ran into with this approach is that the app would set SameSite=lax cookies when the preview was opened in a new tab, and so cookies would not persist between the iframe'd preview and the preview opened in its own tab. In this case, it seemed preferable to always set SameSite=None.

Base automatically changed from brk.fix/unset-cookies-on-sign-out to main July 28, 2025 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants