Fix Set-Cookie name validation - #7522
Conversation
🦋 Changeset detectedLatest commit: 1d729fc The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
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 |
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
PR Change Explanation
BackgroundBackground for readers new to this areaHTTP cookies use different headers depending on the direction of communication. A server sends cookies through An Effect Cookie names are not arbitrary strings. This module represents the RFC 6265 token character set allowed in cookie names with Background specific to this changeBefore this change, only As a result, the same cookie name behaved differently depending on how it entered the system:
In other words, the input parser was more permissive than the construction and serialization paths, so the cookie-name invariant inside a IntuitionThe core idea is to apply the same cookie-name rule before a cookie enters the collection, regardless of where it came from. There is no reason for directly created cookies and cookies read from HTTP responses to use different name rules, so the parser now reuses the existing Small exampleSuppose a server sends these two headers:
The flow after this change is: When Code walkthrough1. Unifying the cookie-name invariant at the input boundaryIn With this one-line change, the response parser uses the same name rule as 2. Giving response consumers and Schema paths the same collection contract
3. The observable contract established by the regression testThe new
<!-- explain-my-pr:v1 key=#7522 head=1d729fc33ce1a9f28f9305efa86eb2e1f71d0e93 part=1/1 --> |
Type
Description
Cookies.fromSetCookievalidated parsed cookie names withfieldContentRegExp, which allowed invalid names containing characters such as spaces. This was inconsistent withCookies.makeCookie, which already validates names using the RFC 6265 token syntax.This PR:
cookieNameRegExpwhen parsingSet-Cookieheaders;effectpatch changeset.Validation
pnpm test --run packages/effect/test/unstable/http/Cookies.test.ts— 10 tests passedNODE_OPTIONS=--experimental-strip-types pnpm lint-fixpnpm checkRelated
No related issue.