Repository navigation
Conversation
Motivation:
RFC 6265 defines cookie-name as a token, which needs at least one
character. The cookie model only checked that every character of the
name was a token character, which is vacuously true for an empty name,
so HttpCookie("", "dark") was accepted and rendered as
`Set-Cookie: =dark`. The header parser already requires a non-empty
name, so only programmatically created cookies were affected.
Modification:
Share the name check between HttpCookiePair.validate and validateRaw
and require a non-empty name there. This covers HttpCookiePair,
HttpCookie and Cookie in both the Scala and Java DSLs.
Result:
Creating a cookie or cookie pair with an empty name throws
IllegalArgumentException("cookie name must not be empty").
Tests:
- sbt "http-core / Test / testOnly org.apache.pekko.http.scaladsl.model.headers.HeaderSpec org.apache.pekko.http.javadsl.model.headers.HttpCookieSpec" - 40 passed; the 2 new tests fail without the fix
- scalafmt --mode diff-ref=upstream/main - no changes
- git diff --check - clean
- Left to CI: full test suites, MiMa, docs build
References:
Refs apache#1676 - found while reviewing that PR
He-Pin
approved these changes
Nov 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
RFC 6265 defines
cookie-nameas a token, which needs at least one character. The cookie model only checked that every character of the name was a token character, which is vacuously true for an empty name. SoHttpCookie("", "dark")was accepted and rendered asSet-Cookie: =dark.The header parser already requires a non-empty name (
cookie-nameistoken), so only programmatically created cookies were affected.Modification
Share the name check between
HttpCookiePair.validateandvalidateRaw, and require a non-empty name there. This coversHttpCookiePair,HttpCookieandCookiein both the Scala and Java DSLs.Result
Creating a cookie or cookie pair with an empty name throws
IllegalArgumentException("cookie name must not be empty"). This is a behaviour change for any caller that was creating such cookies.Tests
sbt "http-core / Test / testOnly org.apache.pekko.http.scaladsl.model.headers.HeaderSpec org.apache.pekko.http.javadsl.model.headers.HttpCookieSpec"- 40 passed; the 2 new tests fail without the fixscalafmt --mode diff-ref=upstream/main- no changesgit diff --check- cleanReferences
Refs #1676 - found while reviewing that PR