diff --git a/.changeset/strict-cookie-names.md b/.changeset/strict-cookie-names.md new file mode 100644 index 00000000000..4795f4d71a5 --- /dev/null +++ b/.changeset/strict-cookie-names.md @@ -0,0 +1,5 @@ +--- +"effect": patch +--- + +Ignore `Set-Cookie` headers whose cookie names do not satisfy the RFC 6265 token syntax. diff --git a/packages/effect/src/unstable/http/Cookies.ts b/packages/effect/src/unstable/http/Cookies.ts index 580570471e0..453b802c4c8 100644 --- a/packages/effect/src/unstable/http/Cookies.ts +++ b/packages/effect/src/unstable/http/Cookies.ts @@ -288,7 +288,7 @@ function parseSetCookie(header: string): Cookie | undefined { return undefined } const name = parts[0].slice(0, firstEqual) - if (!fieldContentRegExp.test(name)) { + if (!cookieNameRegExp.test(name)) { return undefined } diff --git a/packages/effect/test/unstable/http/Cookies.test.ts b/packages/effect/test/unstable/http/Cookies.test.ts index 96a82fd1a49..e524d7d86e1 100644 --- a/packages/effect/test/unstable/http/Cookies.test.ts +++ b/packages/effect/test/unstable/http/Cookies.test.ts @@ -40,6 +40,18 @@ describe("Cookies", () => { }) }) + describe("fromSetCookie", () => { + it("ignores invalid cookie names", () => { + const cookies = Cookies.fromSetCookie([ + "bad name=value", + "session=abc" + ]) + + assertNone(Cookies.get(cookies, "bad name")) + assertSome(Cookies.getValue(cookies, "session"), "abc") + }) + }) + describe("toSetCookieHeaders", () => { const invalidCookie = { name: "session",