Stale host-only auth cookies survive a Domain migration and shadow the new session
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
- Domain
- authentication
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 (
Domainnot 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
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from supabase/ssr
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
cookies.setAll loses its receiver for stateful cookie adaptersPossibly taken @PhuocOng claimed this 71 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 3/5 Half a day Newbie friendliness 56/100
-
Difficulty 3/5 1-2 days Newbie friendliness 48/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 66/100
-
Difficulty 1/5 Under an hour Newbie friendliness 65/100
prometheus/docs#3198 ·
Maintainers usually reply within 3 days
-
[Bug]: OpenCode v2 skips an assistant message that gains text after an earlier capturePossibly taken @jianyx1 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
volcengine/OpenViking#8354 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ARTPARK-SAHAI-ORG/calibrate-frontend#842 ·
Maintainers usually reply within 1 day
-
Chat: Copying a selection that includes the end of a message also copies the actions menu labelsOpen
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
suitenumerique/hub#176 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day