Repository navigation
[UNDERTOW-2738][UNDERTOW-2739][UNDERTOW-2740][UNDERTOW-2741] Fixes for Cookie header parsing - #1938
Merged
Merged
Conversation
fl4via
force-pushed
the
UNDERTOW-2740_2.4.x
branch
3 times, most recently
from
March 17, 2026 23:01
a509b60 to
8835526
Compare
fl4via
force-pushed
the
UNDERTOW-2740_2.4.x
branch
2 times, most recently
from
March 18, 2026 00:00
f42caca to
6016427
Compare
jamezp
reviewed
Mar 18, 2026
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(); | ||
| } |
Member
There was a problem hiding this comment.
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.
Member
Author
There was a problem hiding this comment.
We don't. That's a very good catch! I'm updating the PR.
| @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); |
Member
There was a problem hiding this comment.
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.
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
force-pushed
the
UNDERTOW-2740_2.4.x
branch
from
March 18, 2026 01:31
6016427 to
6690fdc
Compare
jamezp
approved these changes
Mar 18, 2026
This was referenced May 14, 2026
Merged
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.
Jiras:
https://redhat.atlassian.net/browse/UNDERTOW-2738
https://redhat.atlassian.net/browse/UNDERTOW-2739
https://redhat.atlassian.net/browse/UNDERTOW-2740
https://redhat.atlassian.net/browse/UNDERTOW-2741
Main PR: #1956