Skip to content

[UNDERTOW-2738][UNDERTOW-2739][UNDERTOW-2740][UNDERTOW-2741] Fixes for Cookie header parsing - #1938

Merged
fl4via merged 4 commits into
undertow-io:2.4.xfrom
fl4via:UNDERTOW-2740_2.4.x
Mar 18, 2026
Merged

fl4via merged 4 commits into
undertow-io:2.4.xfrom
fl4via:UNDERTOW-2740_2.4.x

Conversation

@fl4via

@fl4via fl4via commented Mar 17, 2026 •

Copy link
Copy Markdown
Member

@fl4via fl4via added bug fix Contains bug fix(es) next release This PR will be merged before next release or has already been merged (for payload double check) waiting CI check Ready to be merged but waiting for CI check new feature / API change New feature to be introduced or a change to the API (non suitable to minor releases) labels Mar 17, 2026
@fl4via
fl4via force-pushed the UNDERTOW-2740_2.4.x branch 3 times, most recently from a509b60 to 8835526 Compare March 17, 2026 23:01
@fl4via fl4via changed the title [UNDERTOW-2738][UNDERTOW-2739][UNDERTOW-2740] Fixes for Cookie header parsing [UNDERTOW-2738][UNDERTOW-2739][UNDERTOW-2740][UNDERTOW-2741] Fixes for Cookie header parsing Mar 17, 2026
@fl4via
fl4via force-pushed the UNDERTOW-2740_2.4.x branch 2 times, most recently from f42caca to 6016427 Compare March 18, 2026 00:00
Comment on lines 249 to 274
public static Map<String, Cookie> parseRequestCookies(List<String> cookies, CookieStore requestCookieStore, OptionMap options) {
return parseRequestCookies(cookies, requestCookieStore, options, LegacyCookieSupport.COMMA_IS_SEPARATOR, LegacyCookieSupport.ALLOW_HTTP_SEPARATORS_IN_V0);
}

static Map<String, Cookie> parseRequestCookies(List<String> cookies, CookieStore requestCookieStore, OptionMap options, boolean commaIsSeparator, boolean allowHttpSeparatorsInV0) {
if (cookies == null) {
return new TreeMap<>();
}
final int maxCookies;
final boolean allowEqualInValue;
final boolean enableRfc6265CookieValidation;
if (options == null || options == OptionMap.EMPTY) {
maxCookies = UndertowOptions.DEFAULT_MAX_COOKIES;
allowEqualInValue = false;
enableRfc6265CookieValidation = UndertowOptions.DEFAULT_ENABLE_RFC6265_COOKIE_VALIDATION;
}
else {
maxCookies = options.get(UndertowOptions.MAX_COOKIES, UndertowOptions.DEFAULT_MAX_COOKIES);
allowEqualInValue = options.get(UndertowOptions.ALLOW_EQUALS_IN_COOKIE_VALUE, false);
enableRfc6265CookieValidation = options.get(UndertowOptions.ENABLE_RFC6265_COOKIE_VALIDATION, UndertowOptions.DEFAULT_ENABLE_RFC6265_COOKIE_VALIDATION);
}
for (String cookie : cookies) {
parseCookie(cookie, requestCookieStore, maxCookies, allowEqualInValue, commaIsSeparator, allowHttpSeparatorsInV0, enableRfc6265CookieValidation);
}
return requestCookieStore.asLegacyMap();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want these to return a Map? These are flat maps and aren't necessarily cheap. We call it from the HttpServerExchange which means the map will be created a lot. Granted it should get thrown away given we don't use the value, but it's a lot of small objects potentially being created.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't. That's a very good catch! I'm updating the PR.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@Deprecated(since="2.4.0", forRemoval=true)
public static void parseRequestCookies(int maxCookies, boolean allowEqualInValue, List<String> cookies, Set<Cookie> parsedCookies) {
parseRequestCookies(maxCookies, allowEqualInValue, cookies, parsedCookies, LegacyCookieSupport.COMMA_IS_SEPARATOR, LegacyCookieSupport.ALLOW_HTTP_SEPARATORS_IN_V0);
Map parsedCookiesMap = parseRequestCookies(maxCookies, allowEqualInValue, cookies, LegacyCookieSupport.COMMA_IS_SEPARATOR, LegacyCookieSupport.ALLOW_HTTP_SEPARATORS_IN_V0);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor, but this should probably be something more like:

final CookieStore cookieStore = new CookieStore();
parseRequestCookies(cookies, cookieStore, OptionMap.builder().set(UndertowOptions.MAX_COOKIES, maxCookies).set(UndertowOptions.ALLOW_EQUALS_IN_COOKIE_VALUE, allowEqualInValue).getMap());
cookieStore.forEach(parsedCookies::add);

Otherwise you end up with a flat map of cookies. Maybe that is what we want here though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

fl4via added 4 commits March 17, 2026 22:30
Signed-off-by: Flavia Rainone <frainone@redhat.com>
…value of the cookie comes after legacy attributes

Signed-off-by: Flavia Rainone <frainone@redhat.com>
…lient headers

Signed-off-by: Flavia Rainone <frainone@redhat.com>
…lly compatible with RFC6265 regardless of UndertowOptions.ENABLE_RFC6265_COOKIE_VALIDATION config

Notice that we are keeping legacy compatibility to some extent here, as long as Undertow works by default with RFC6265

Signed-off-by: Flavia Rainone <frainone@redhat.com>
@fl4via
fl4via force-pushed the UNDERTOW-2740_2.4.x branch from 6016427 to 6690fdc Compare March 18, 2026 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix Contains bug fix(es) new feature / API change New feature to be introduced or a change to the API (non suitable to minor releases) next release This PR will be merged before next release or has already been merged (for payload double check)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants