Skip to content

fix(shared): Add Netlify-Vary header to prevent CDN caching of auth responses#8028

Draft
wobsoriano wants to merge 4 commits intomainfrom
rob/netlify-next-prod
Draft

fix(shared): Add Netlify-Vary header to prevent CDN caching of auth responses#8028
wobsoriano wants to merge 4 commits intomainfrom
rob/netlify-next-prod

Conversation

@wobsoriano
Copy link
Member

Consolidate Netlify cache handling into a single handleNetlifyCacheHeaders function that sets Netlify-Vary: cookie=__client_uat,cookie=__session on all auth responses when running on Netlify. This prevents the CDN from serving stale session state across different users/sessions.

The function is called once per request in each framework SDK middleware, right after authenticateRequest returns, replacing the previous dev-only cache-bust approach with proper CDN cache isolation for both dev and prod.

Description

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:

…esponses

Consolidate Netlify cache handling into a single `handleNetlifyCacheHeaders`
function that sets `Netlify-Vary: cookie=__client_uat,cookie=__session` on all
auth responses when running on Netlify. This prevents the CDN from serving
stale session state across different users/sessions.

The function is called once per request in each framework SDK middleware,
right after `authenticateRequest` returns, replacing the previous dev-only
cache-bust approach with proper CDN cache isolation for both dev and prod.
@changeset-bot
Copy link

changeset-bot bot commented Mar 10, 2026

🦋 Changeset detected

Latest commit: 3453259

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

This PR includes changesets to release 21 packages
Name Type
@clerk/shared Patch
@clerk/nextjs Patch
@clerk/astro Patch
@clerk/react-router Patch
@clerk/nuxt Patch
@clerk/tanstack-react-start Patch
@clerk/agent-toolkit Patch
@clerk/backend Patch
@clerk/chrome-extension Patch
@clerk/clerk-js Patch
@clerk/expo-passkeys Patch
@clerk/expo Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/hono Patch
@clerk/localizations Patch
@clerk/msw Patch
@clerk/react Patch
@clerk/testing Patch
@clerk/ui Patch
@clerk/vue 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

@vercel
Copy link

vercel bot commented Mar 10, 2026

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

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment Mar 10, 2026 5:47pm

Request Review

@wobsoriano
Copy link
Member Author

!snapshot

@github-actions
Copy link
Contributor

Hey @wobsoriano - the snapshot version command generated the following package versions:

Package Version
@clerk/agent-toolkit 0.3.4-snapshot.v20260310165744
@clerk/astro 3.0.4-snapshot.v20260310165744
@clerk/backend 3.2.0-snapshot.v20260310165744
@clerk/chrome-extension 3.1.2-snapshot.v20260310165744
@clerk/clerk-js 6.2.1-snapshot.v20260310165744
@clerk/dev-cli 0.1.1-snapshot.v20260310165744
@clerk/expo 3.1.2-snapshot.v20260310165744
@clerk/expo-passkeys 1.0.4-snapshot.v20260310165744
@clerk/express 2.0.4-snapshot.v20260310165744
@clerk/fastify 3.1.2-snapshot.v20260310165744
@clerk/hono 0.1.2-snapshot.v20260310165744
@clerk/localizations 4.2.1-snapshot.v20260310165744
@clerk/msw 0.0.4-snapshot.v20260310165744
@clerk/nextjs 7.0.4-snapshot.v20260310165744
@clerk/nuxt 2.0.4-snapshot.v20260310165744
@clerk/react 6.1.0-snapshot.v20260310165744
@clerk/react-router 3.0.4-snapshot.v20260310165744
@clerk/shared 4.2.1-snapshot.v20260310165744
@clerk/tanstack-react-start 1.0.4-snapshot.v20260310165744
@clerk/testing 2.0.4-snapshot.v20260310165744
@clerk/ui 1.2.1-snapshot.v20260310165744
@clerk/upgrade 2.0.2-snapshot.v20260310165744
@clerk/vue 2.0.4-snapshot.v20260310165744

Tip: Use the snippet copy button below to quickly install the required packages.
@clerk/agent-toolkit

npm i @clerk/agent-toolkit@0.3.4-snapshot.v20260310165744 --save-exact

@clerk/astro

npm i @clerk/astro@3.0.4-snapshot.v20260310165744 --save-exact

@clerk/backend

npm i @clerk/backend@3.2.0-snapshot.v20260310165744 --save-exact

@clerk/chrome-extension

npm i @clerk/chrome-extension@3.1.2-snapshot.v20260310165744 --save-exact

@clerk/clerk-js

npm i @clerk/clerk-js@6.2.1-snapshot.v20260310165744 --save-exact

@clerk/dev-cli

npm i @clerk/dev-cli@0.1.1-snapshot.v20260310165744 --save-exact

@clerk/expo

npm i @clerk/expo@3.1.2-snapshot.v20260310165744 --save-exact

@clerk/expo-passkeys

npm i @clerk/expo-passkeys@1.0.4-snapshot.v20260310165744 --save-exact

@clerk/express

npm i @clerk/express@2.0.4-snapshot.v20260310165744 --save-exact

@clerk/fastify

npm i @clerk/fastify@3.1.2-snapshot.v20260310165744 --save-exact

@clerk/hono

npm i @clerk/hono@0.1.2-snapshot.v20260310165744 --save-exact

@clerk/localizations

npm i @clerk/localizations@4.2.1-snapshot.v20260310165744 --save-exact

@clerk/msw

npm i @clerk/msw@0.0.4-snapshot.v20260310165744 --save-exact

@clerk/nextjs

npm i @clerk/nextjs@7.0.4-snapshot.v20260310165744 --save-exact

@clerk/nuxt

npm i @clerk/nuxt@2.0.4-snapshot.v20260310165744 --save-exact

@clerk/react

npm i @clerk/react@6.1.0-snapshot.v20260310165744 --save-exact

@clerk/react-router

npm i @clerk/react-router@3.0.4-snapshot.v20260310165744 --save-exact

@clerk/shared

npm i @clerk/shared@4.2.1-snapshot.v20260310165744 --save-exact

@clerk/tanstack-react-start

npm i @clerk/tanstack-react-start@1.0.4-snapshot.v20260310165744 --save-exact

@clerk/testing

npm i @clerk/testing@2.0.4-snapshot.v20260310165744 --save-exact

@clerk/ui

npm i @clerk/ui@1.2.1-snapshot.v20260310165744 --save-exact

@clerk/upgrade

npm i @clerk/upgrade@2.0.2-snapshot.v20260310165744 --save-exact

@clerk/vue

npm i @clerk/vue@2.0.4-snapshot.v20260310165744 --save-exact

Clerk uses suffixed cookies (e.g. __client_uat_AbC12345) by default for
newer instances. The Netlify-Vary header now includes both unsuffixed and
suffixed cookie names computed from the publishable key, ensuring CDN
cache isolation works for all Clerk instances.
@wobsoriano
Copy link
Member Author

!snapshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant