Skip to content

fix(http): keep same-name Set-Cookie headers with a different domain or path - #10470

Closed
jpowersdev wants to merge 10 commits into
Effect-TS:mainfrom
jpowersdev:fix/cookies-keep-set-cookie
Closed

jpowersdev wants to merge 10 commits into
Effect-TS:mainfrom
jpowersdev:fix/cookies-keep-set-cookie

Conversation

@jpowersdev

@jpowersdev jpowersdev commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Cookies was a record keyed by cookie name, so fromSetCookie and fromIterable kept only the last cookie per name even when its Domain or Path differed. HttpClientResponse.cookies is built with fromSetCookie, so a response setting token on / and on /api reached HttpClient.withCookiesRef with one of them missing, and a logout clearing session for both the host and Domain=example.com deleted only one. HttpServerResponse.fromWeb dropped them the same way when proxying.

Cookies now keeps every cookie in order, each under a key, and exposes them as all. The cookies record holds the last cookie per key. Keys are cookie names, except for records passed to fromReadonlyRecord (and the Schema.Cookies iso codec), whose keys are kept as given. Parsing removes nothing: scope replacement happens in mergeIntoArray, where the request URL is known and an omitted Path can be resolved, so merging a response into a jar gives the same result as processing its Set-Cookie headers one by one.

Supersedes #10471, which identified cookies by name, domain and path everywhere and changed server-side expireCookie semantics.

Behavior

  • fromSetCookie and fromIterable keep every cookie in input order, keyed by name. toSetCookieHeaders, mergeIntoArray, isEmpty and the Schema.Cookies JSON codec read all, using each cookie's own name.
  • cookies, get, getValue, toCookieHeader, toJSON and the Schema.Cookies iso codec read the record, as before. fromReadonlyRecord keeps its keys, so iso round-trips are unchanged, including keys that differ from the cookie name.
  • set, setCookie, setAll, expireCookie, merge and remove act on every cookie stored under the key, so the HttpServerResponse helpers behave as before. A replaced cookie moves to the end of all; header order is otherwise unchanged, and identical to before when each name has one cookie.
  • A server can send one name for several scopes with HttpServerResponse.mergeCookies(response, Cookies.fromSetCookie([...])).

Cookies is @stability unstable and the new all field is additive, so the changeset is a patch.

Validation

  • pnpm test --run packages/effect/test/http/ packages/effect/test/Schema* packages/platform/node/test/{NodeHttpServer,HttpApi}.test.ts packages/platform/browser/test/BrowserHttpClient.test.ts (3632 passed, 1 skipped)
  • pnpm lint-fix, pnpm check, pnpm check-tsc, pnpm jsdocs --check

Closes #10469
Closes EFF-3507

@changeset-bot

changeset-bot Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 28165ae

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

This PR includes changesets to release 33 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-cloudflare Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/ai-typesafe Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/graphql-generator Patch
@effect/openapi-generator 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

@github-actions

github-actions Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 39.61 KB 39.61 KB 0.00 KB (0.00%)
basic.ts 7.31 KB 7.31 KB 0.00 KB (0.00%)
batching.ts 11.21 KB 11.21 KB 0.00 KB (0.00%)
brand.ts 7.00 KB 7.00 KB 0.00 KB (0.00%)
cache.ts 11.73 KB 11.73 KB 0.00 KB (0.00%)
config.ts 23.06 KB 23.06 KB 0.00 KB (0.00%)
differ.ts 22.20 KB 22.20 KB 0.00 KB (0.00%)
http-client.ts 27.30 KB 27.25 KB +0.04 KB (+0.15%)
http-router.ts 37.14 KB 37.13 KB +0.01 KB (+0.02%)
logger.ts 12.19 KB 12.19 KB 0.00 KB (0.00%)
metric.ts 9.64 KB 9.64 KB 0.00 KB (0.00%)
optic.ts 7.21 KB 7.21 KB 0.00 KB (0.00%)
pubsub.ts 16.21 KB 16.21 KB 0.00 KB (0.00%)
queue.ts 13.09 KB 13.09 KB 0.00 KB (0.00%)
schedule.ts 11.99 KB 11.99 KB 0.00 KB (0.00%)
schema-bigdecimal.ts 14.29 KB 14.29 KB 0.00 KB (0.00%)
schema-binary.ts 42.38 KB 42.38 KB 0.00 KB (0.00%)
schema-class.ts 21.96 KB 21.96 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 29.89 KB 29.89 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 28.22 KB 28.22 KB 0.00 KB (0.00%)
schema-string-transformation.ts 15.54 KB 15.54 KB 0.00 KB (0.00%)
schema-string.ts 12.50 KB 12.50 KB 0.00 KB (0.00%)
schema-template-literal.ts 16.42 KB 16.42 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 39.16 KB 39.16 KB 0.00 KB (0.00%)
schema-toCodeDocument.ts 26.36 KB 26.36 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 21.11 KB 21.11 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 21.28 KB 21.28 KB 0.00 KB (0.00%)
schema-toFormatter.ts 21.37 KB 21.37 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 26.38 KB 26.38 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 21.45 KB 21.45 KB 0.00 KB (0.00%)
schema.ts 21.05 KB 21.05 KB 0.00 KB (0.00%)
stm.ts 14.40 KB 14.40 KB 0.00 KB (0.00%)
stream.ts 10.56 KB 10.56 KB 0.00 KB (0.00%)

@effect-bot
effect-bot marked this pull request as ready for review November 9, 2026 00:12
@effect-bot

Copy link
Copy Markdown
Contributor

Closing as superseded by #10471, the chosen scope-aware cookie fix targeting v4/next-minor as a minor release. That approach preserves same-name cookies consistently across domains and paths, including the public cookie representation. Thank you for providing both alternatives.

@effect-bot effect-bot closed this Nov 9, 2026

This branch is waiting to be deployed

1 waiting deployment
fork — 28165ae1 Waiting Nov 9, 2026 by effect-bot via approval-gate #25502
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.

Cookies drops same-name cookies set for a different domain or path

2 participants