Stale host-only auth cookies survive a Domain migration and shadow the new session

Open
#308 0 comments 0 reactions 0 assignees View on GitHub

@RaphaelFakhri is already working on this.

Since Oct 24, 2026.

  • #309 by @RaphaelFakhri — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
25/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
typescript

Research direction

The issue identifies setItem and applyServerStorage as the relevant entry points; start by reading how they clear host-only cookies for removed chunks. Use the reproduction with cookieOptions.domain set to check the emitted calls. Done means overwritten existing chunks also get a host-only clear before the domain-scoped write; linked PR #309 is already open.

Written by the indexing model from the issue text.

Description

After you switch cookieOptions.domain from unset (host-only) to a parent domain such as .example.com, the browser keeps the old host-only auth cookies until sign-out. They shadow the new domain-scoped cookies, so the client reads the old session.

#240 added a host-only clear when domain is set, but setItem and applyServerStorage only emit it for chunks they remove. Chunks that are overwritten keep the same names (sb-<ref>-auth-token.0, .1, ...), so they never get a host-only clear. After the first write with the new domain, the browser holds two cookies per name:

  • the old host-only cookie (Domain not set)
  • the new cookie with Domain=.example.com

Browsers list the older cookie first in document.cookie and the Cookie header, and cookie.parse keeps the first value for a name:

require("cookie").parse("sb-auth.0=OLD; sb-auth.0=NEW"); // { 'sb-auth.0': 'OLD' }

The client then reads the old session. Its refresh token has already been rotated, so the next refresh fails and the user gets signed out.

Reproduction

@supabase/ssr 0.12.7 (main 5064794).

const calls = [];
const { storage } = createStorageFromOptions(
  {
    cookieEncoding: "raw",
    cookieOptions: { domain: ".example.com" },
    cookies: {
      getAll: async () => [{ name: "storage-key", value: "old" }],
      setAll: async (c) => calls.push(...c),
    },
  },
  false,
);
await storage.setItem("storage-key", "new");
// calls: only { name: "storage-key", value: "new", options: { domain: ".example.com", ... } }
// expected: a host-only clear for "storage-key" before the set

Expected

When domain is set, the write also clears the host-only copy of every existing chunk it overwrites, as it already does for the chunks it removes.

Dominant language
TypeScript
Stars
216
Forks
35
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from supabase/ssr

All issues in supabase/ssr

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.