Skip to content

Conversation

brkalow
Copy link
Member

@brkalow brkalow commented Sep 24, 2025

Description

Ensure the clerk_active_context cookie properly sets the Secure attribute in secure contexts.

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

    • Ensures the active context cookie is set with the correct Secure attribute, improving reliability of session/context handling in secure (HTTPS) environments and modern browsers.
    • Reduces intermittent sign-in/context issues caused by improperly flagged cookies.
  • Chores

    • Prepares a patch release entry for the package to deliver the fix.

Copy link

changeset-bot bot commented Sep 24, 2025

🦋 Changeset detected

Latest commit: 77bf8ff

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 Patch
@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

Copy link

vercel bot commented Sep 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
clerk-js-sandbox Ready Ready Preview Comment Sep 24, 2025 9:45pm

Copy link
Contributor

coderabbitai bot commented Sep 24, 2025

Warning

Rate limit exceeded

@brkalow has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 1 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 37bbf87 and 77bf8ff.

📒 Files selected for processing (2)
  • packages/clerk-js/src/core/auth/AuthCookieService.ts (3 hunks)
  • packages/clerk-js/src/core/auth/cookies/activeContext.ts (1 hunks)

Walkthrough

Introduces a dedicated active context cookie module and switches AuthCookieService to use it. The new cookie setter/remove apply a Secure attribute via a utility. AuthCookieService adjusts its cookie initialization and set method signature accordingly. A changeset records a patch update for @clerk/clerk-js.

Changes

Cohort / File(s) Summary
Release notes
\.changeset/lucky-showers-guess.md
Adds a patch changeset noting the active context cookie Secure attribute fix.
Auth cookie service refactor
packages/clerk-js/src/core/auth/AuthCookieService.ts
Replaces generic cookie handler with createActiveContextCookie; updates activeCookie type and setActiveContextInStorage to pass options object to .set.
New active context cookie module
packages/clerk-js/src/core/auth/cookies/activeContext.ts
Adds createActiveContextCookie wrapper around generic cookie handler; ensures Secure attribute via getSecureAttribute('None'); exposes set(value), get(), remove().

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant AuthCookieService
  participant ActiveContextCookie
  participant CookieHandler
  participant BrowserCookies as Browser Cookies

  Client->>AuthCookieService: setActiveContextInStorage(contextValue)
  AuthCookieService->>ActiveContextCookie: set(value, {})
  ActiveContextCookie->>CookieHandler: set('clerk_active_context', value, { Secure: getSecureAttribute('None'), ... })
  CookieHandler->>BrowserCookies: Write cookie with attributes
  Note right of BrowserCookies: Secure attribute applied

  Client->>AuthCookieService: getActiveContextFromStorage()
  AuthCookieService->>ActiveContextCookie: get()
  ActiveContextCookie->>CookieHandler: get('clerk_active_context')
  CookieHandler-->>AuthCookieService: value
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A hop, a skip—secure I go,
Setting cookies with a subtle glow.
Context crumbs in jars now lock,
Safe as burrows under rock.
Patch notes squeak, “All set, all clear!”
Thump-thump—ship it, bring the cheer! 🥕🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly follows conventional commit style, clearly identifying a bug fix in clerk-js that ensures the clerk_active_context cookie includes the Secure attribute. It directly reflects the main change to the active context cookie handler and is free of unnecessary detail or noise. This makes it easy for teammates scanning history to understand the purpose of the pull request.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/clerk-js/src/core/auth/AuthCookieService.ts (1)

44-44: Align the activeCookie type with the new factory.

Now that we return the specialized active-context handler, keep the property typed to createActiveContextCookie so the method signatures stay accurate.

Apply this diff:

-  private activeCookie: ReturnType<typeof createCookieHandler>;
+  private activeCookie: ReturnType<typeof createActiveContextCookie>;
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between a39f2fc and 37bbf87.

📒 Files selected for processing (3)
  • .changeset/lucky-showers-guess.md (1 hunks)
  • packages/clerk-js/src/core/auth/AuthCookieService.ts (3 hunks)
  • packages/clerk-js/src/core/auth/cookies/activeContext.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (7)
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

**/*.{js,jsx,ts,tsx}: All code must pass ESLint checks with the project's configuration
Follow established naming conventions (PascalCase for components, camelCase for variables)
Maintain comprehensive JSDoc comments for public APIs
Use dynamic imports for optional features
All public APIs must be documented with JSDoc
Provide meaningful error messages to developers
Include error recovery suggestions where applicable
Log errors appropriately for debugging
Lazy load components and features when possible
Implement proper caching strategies
Use efficient data structures and algorithms
Profile and optimize critical paths
Validate all inputs and sanitize outputs
Implement proper logging with different levels

Files:

  • packages/clerk-js/src/core/auth/AuthCookieService.ts
  • packages/clerk-js/src/core/auth/cookies/activeContext.ts
**/*.{js,jsx,ts,tsx,json,css,scss,md,yaml,yml}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use Prettier for consistent code formatting

Files:

  • packages/clerk-js/src/core/auth/AuthCookieService.ts
  • packages/clerk-js/src/core/auth/cookies/activeContext.ts
packages/**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

TypeScript is required for all packages

Files:

  • packages/clerk-js/src/core/auth/AuthCookieService.ts
  • packages/clerk-js/src/core/auth/cookies/activeContext.ts
packages/**/*.{ts,tsx,d.ts}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Packages should export TypeScript types alongside runtime code

Files:

  • packages/clerk-js/src/core/auth/AuthCookieService.ts
  • packages/clerk-js/src/core/auth/cookies/activeContext.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/development.mdc)

Use proper TypeScript error types

**/*.{ts,tsx}: 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
Use protected for inheritance hierarchies
Use public explicitly for clarity in public APIs
Prefer readonly for properties that shouldn't change after construction
Prefer composition and interfaces over deep inheritance chains
Use mixins for shared behavior across unrelated classes
Implement dependency injection for loose coupling
Let TypeScript infer when types are obvious
Use const assertions for literal types: as const
Use satisfies operator for type checking without widening
Use mapped types for transforming object types
Use conditional types for type-level logic
Leverage template literal types for string manipulation
Use ES6 imports/exports consistently
Use default exports sparingly, prefer named exports
Use type-only imports: import type { ... } from ...
No any types without justification
Proper error handling with typed errors
Consistent use of readonly for immutable data
Proper generic constraints
No unused type parameters
Proper use of utility types instead of manual type construction
Type-only imports where possible
Proper tree-shaking friendly exports
No circular dependencies
Efficient type computations (avoid deep recursion)

Files:

  • packages/clerk-js/src/core/auth/AuthCookieService.ts
  • packages/clerk-js/src/core/auth/cookies/activeContext.ts
**/*.{js,ts,tsx,jsx}

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Support multiple Clerk environment variables (CLERK_, NEXT_PUBLIC_CLERK_, etc.) for configuration.

Files:

  • packages/clerk-js/src/core/auth/AuthCookieService.ts
  • packages/clerk-js/src/core/auth/cookies/activeContext.ts
.changeset/**

📄 CodeRabbit inference engine (.cursor/rules/monorepo.mdc)

Automated releases must use Changesets.

Files:

  • .changeset/lucky-showers-guess.md
🧬 Code graph analysis (2)
packages/clerk-js/src/core/auth/AuthCookieService.ts (1)
packages/clerk-js/src/core/auth/cookies/activeContext.ts (1)
  • createActiveContextCookie (5-20)
packages/clerk-js/src/core/auth/cookies/activeContext.ts (1)
packages/shared/src/cookie.ts (1)
  • createCookieHandler (15-36)
⏰ 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). (5)
  • GitHub Check: Build Packages
  • GitHub Check: Formatting | Dedupe | Changeset
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: semgrep-cloud-platform/scan
  • GitHub Check: semgrep-cloud-platform/scan
🔇 Additional comments (1)
.changeset/lucky-showers-guess.md (1)

1-5: Changeset entry looks good.

Patch note clearly describes the behavior change.

Copy link

pkg-pr-new bot commented Sep 24, 2025

Open in StackBlitz

@clerk/agent-toolkit

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

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

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

@clerk/elements

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

@clerk/clerk-expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/clerk-react

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

@clerk/react-router

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

@clerk/remix

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/themes

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

@clerk/types

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

@clerk/upgrade

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

@clerk/vue

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

commit: 77bf8ff

Copy link
Member

@jacekradko jacekradko left a comment

Choose a reason for hiding this comment

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

LGTM

@brkalow brkalow merged commit 33efaad into main Sep 25, 2025
63 of 64 checks passed
@brkalow brkalow deleted the brk.fix/active-context-secure-attribute branch September 25, 2025 20:07
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