Skip to content

Conversation

tmilewski
Copy link
Member

@tmilewski tmilewski commented Jun 25, 2025

Description

The redirect to a primary domain would include would include __clerk_synced in the redirect_url when a page protected via middleware was called directly resulting in it, incorrectly, being passed back to the satellite.

This ensures that __clerk_synced is removed from the redirect_url before navigating to the primary domain.

USER-2138

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 security and privacy by removing the __clerk_synced parameter from cross-origin return-back URLs during redirects.
  • Tests

    • Added new test cases to ensure the __clerk_synced parameter is properly removed from redirect URLs in various session scenarios.

@tmilewski tmilewski self-assigned this Jun 25, 2025
Copy link

changeset-bot bot commented Jun 25, 2025

🦋 Changeset detected

Latest commit: 996d104

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

This PR includes changesets to release 11 packages
Name Type
@clerk/backend Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/tanstack-react-start Patch
@clerk/testing 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

Copy link

vercel bot commented Jun 25, 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 Jun 25, 2025 8:26pm

Copy link
Contributor

coderabbitai bot commented Jun 25, 2025

📝 Walkthrough

Walkthrough

This change updates the backend logic to ensure that the __clerk_synced query parameter is removed from returnBackUrl values during cross-origin redirects. The implementation introduces a new variable to robustly determine cross-origin scenarios by comparing both hostname and port. The removal of the parameter is now explicitly handled in these cases. Corresponding unit tests have been added to verify that the parameter is stripped from the redirect URLs as expected in both active and pending session states. No changes were made to the declarations of exported or public entities.

Assessment against linked issues

Objective Addressed Explanation
Ensure __clerk_synced is cleared from returnBackUrl during cross-origin redirects (USER-2138)

Suggested reviewers

  • dstaley
  • aeliox
  • wobsoriano

📜 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 58e9a2f and 996d104.

📒 Files selected for processing (3)
  • .changeset/witty-hotels-add.md (1 hunks)
  • packages/backend/src/__tests__/createRedirect.test.ts (2 hunks)
  • packages/backend/src/createRedirect.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
`**/*.{js,ts,tsx,jsx}`: All code must pass ESLint checks with the project's configuration. Use Prettier for consistent code formatting.

**/*.{js,ts,tsx,jsx}: All code must pass ESLint checks with the project's configuration.
Use Prettier for consistent code formatting.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)

List of files the instruction was applied to:

  • packages/backend/src/createRedirect.ts
  • packages/backend/src/__tests__/createRedirect.test.ts
`**/*.{ts,tsx}`: Maintain comprehensive JSDoc comments for public APIs.

**/*.{ts,tsx}: Maintain comprehensive JSDoc comments for public APIs.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)

List of files the instruction was applied to:

  • packages/backend/src/createRedirect.ts
  • packages/backend/src/__tests__/createRedirect.test.ts
`packages/**`: All publishable packages under the @clerk namespace must be located in the packages/ directory.

packages/**: All publishable packages under the @clerk namespace must be located in the packages/ directory.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/global.mdc)

List of files the instruction was applied to:

  • packages/backend/src/createRedirect.ts
  • packages/backend/src/__tests__/createRedirect.test.ts
`**/*.ts`: Always define explicit return types for functions, especially public ...

**/*.ts: Always define explicit return types for functions, especially public APIs.
Use proper type annotations for variables and parameters where inference isn't clear.
Avoid any type; prefer unknown when type is uncertain, then narrow with type guards.
Use interface for object shapes that might be extended; use type for unions, primitives, and computed types.
Prefer readonly properties for immutable data structures.
Use private for internal implementation details, protected for inheritance, and public explicitly for clarity in public APIs.
Prefer composition and interfaces over deep inheritance chains; use mixins for shared behavior.
Use ES6 imports/exports consistently; avoid barrel files (index.ts re-exports) to prevent circular dependencies.
Use type-only imports (import type { ... }) where possible.
Use as const for literal types and the satisfies operator for type checking without widening.
Enable --incremental and --tsBuildInfoFile for faster builds.
Use ESLint with @typescript-eslint/recommended rules and Prettier for formatting.
Use lint-staged and Husky for pre-commit checks.
Use type-coverage to measure type safety.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/typescript.mdc)

List of files the instruction was applied to:

  • packages/backend/src/createRedirect.ts
  • packages/backend/src/__tests__/createRedirect.test.ts
`**/*.{test,spec}.{js,ts,tsx,jsx}`: Unit tests are required for all new functionality.

**/*.{test,spec}.{js,ts,tsx,jsx}: Unit tests are required for all new functionality.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)

List of files the instruction was applied to:

  • packages/backend/src/__tests__/createRedirect.test.ts
`**/__tests__/**/*.{js,ts,tsx,jsx}`: Test files should be co-located with source files or in `__tests__` directories.

**/__tests__/**/*.{js,ts,tsx,jsx}: Test files should be co-located with source files or in __tests__ directories.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/development.mdc)

List of files the instruction was applied to:

  • packages/backend/src/__tests__/createRedirect.test.ts
🧬 Code Graph Analysis (1)
packages/backend/src/__tests__/createRedirect.test.ts (1)
packages/backend/src/createRedirect.ts (1)
  • createRedirect (85-141)
🪛 Gitleaks (8.26.0)
packages/backend/src/__tests__/createRedirect.test.ts

112-112: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


355-355: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Build Packages
  • GitHub Check: semgrep/ci
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (7)
.changeset/witty-hotels-add.md (1)

1-6: LGTM: Changeset documentation is clear and follows proper format.

The changeset properly documents the patch-level change to ensure __clerk_synced parameter removal from cross-origin return-back URLs.

packages/backend/src/createRedirect.ts (3)

20-20: Robust cross-origin detection implementation.

The cross-origin detection logic correctly compares both hostname and port, which is more comprehensive than hostname-only comparisons and handles edge cases like different ports on the same domain.


23-26: Secure parameter sanitization for cross-origin redirects.

The implementation correctly removes the __clerk_synced parameter only when both conditions are met: a returnBackUrl exists and the redirect is cross-origin. This prevents sensitive synchronization state from leaking to external domains while preserving functionality for same-origin redirects.


30-30: Consistent cross-origin logic integration.

Good refactoring to use the centralized isCrossOriginRedirect variable instead of duplicating the cross-origin detection logic. This maintains consistency and reduces code duplication.

packages/backend/src/__tests__/createRedirect.test.ts (3)

102-122: Comprehensive test coverage for active session cross-origin parameter removal.

The test correctly verifies that __clerk_synced=true is removed from the returnBackUrl during cross-origin redirects with active session status. The test setup, URL encoding verification, and expected results are all accurate.


346-364: Complete test coverage for pending session cross-origin parameter removal.

The test appropriately verifies the same parameter removal behavior for pending session status, ensuring the fix works consistently across different session states. The test correctly validates that the cleaned URL is passed to the tasks endpoint.


112-112: Static analysis false positives for test publishable keys.

The flagged "API keys" are actually base64-encoded test publishable keys used specifically for testing purposes (note the pk_test_ prefix). These are not real API keys and are safe to use in tests.

Also applies to: 355-355


🪧 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 Jun 25, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: 996d104

@tmilewski tmilewski merged commit 084e7cc into main Jun 26, 2025
40 checks passed
@tmilewski tmilewski deleted the tm/user-2138-clerk-synced branch June 26, 2025 03:03
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