Skip to content

Make Set-Cookie attribute parsing case-insensitive#14

Merged
hellerve merged 1 commit into
masterfrom
claude/set-cookie-case-insensitive
Jul 13, 2026
Merged

Make Set-Cookie attribute parsing case-insensitive#14
hellerve merged 1 commit into
masterfrom
claude/set-cookie-case-insensitive

Conversation

@carpentry-agent

Copy link
Copy Markdown

What

Cookie.parse-set-prop compared every Set-Cookie attribute name and the SameSite value exact-case, which is a conformance/robustness bug in a widely-used header path:

  • Lowercase or mixed attribute names were silently dropped. RFC 6265 §5.2 defines attribute names as case-insensitive. A header like Set-Cookie: id=1; secure (or path=/, httponly, max-age=60, samesite=Lax) matched no cond branch, fell through to the default, and returned the cookie with the flag unset — so id=1; secure parsed with secure=false.
  • A lowercase SameSite value aborted the whole response parse. RFC 6265bis §5.4.7 defines the SameSite value as case-insensitive. SameSite=lax matched the attribute name but missed the value case, returned Result.Error, and that error short-circuits Cookie.parse-set — failing the entire Response.parse.

Fix

Case-fold the attribute name (via String.ascii-to-lower, already used for case-insensitive handling elsewhere in this module) and the SameSite value before matching. Attribute values keep their original case (e.g. Path=/Foo still yields /Foo), and genuinely unknown attributes (Partitioned, Priority=High) still fall through and are ignored. Serialization (Cookie.set) is untouched and still emits canonical case.

Tests

Added coverage for: lowercase/mixed attribute names (secure, httponly, path, domain, max-age, expires) being honored with value case preserved; lowercase SameSite values (lax/strict/none) parsing to the correct variant; a lowercase SameSite value no longer aborting Response.parse; and a genuinely-unknown attribute still being ignored.

carp -x test/http.carp passes all cookie tests (131 passed; the single failure is the pre-existing, unrelated armhf form-data on empty body case that also fails on master and is green on CI). carp-fmt -c, angler, and carp -x gendocs.carp are all clean.


Opened by the carpentry-org heartbeat agent (Claude). Veit has not reviewed this yet.

RFC 6265 §5.2 defines Set-Cookie attribute names as case-insensitive, and
RFC 6265bis §5.4.7 does the same for the SameSite value. parse-set-prop
matched both exact-case, so a lowercase or mixed attribute name (secure,
path=/, samesite=Lax, …) matched no branch and was silently dropped, and a
lowercase SameSite value (SameSite=lax) returned an error that aborted the
whole Response.parse.

Case-fold the attribute name and the SameSite value before matching.
Attribute values keep their original case, and genuinely unknown
attributes are still ignored.
@hellerve
hellerve merged commit 9b27ff1 into master Jul 13, 2026
2 checks passed
@hellerve
hellerve deleted the claude/set-cookie-case-insensitive branch July 13, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant