Skip to content

Commit 6016427

Browse files
committed
[UNDERTOW-2740] Make the parsing of client Cookie header at server fully 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>
1 parent ec96261 commit 6016427

2 files changed

Lines changed: 5 additions & 9 deletions

File tree

‎core/src/main/java/io/undertow/util/Cookies.java‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,6 @@ static Map<String, Cookie> parseRequestCookies(List<String> cookies, CookieStore
276276
private static void parseCookie(final String cookie, final CookieStore parsedCookies, final int maxCookies, final boolean allowEqualInValue, final boolean commaIsSeperator, final boolean allowHttpSeparatorsV0, final boolean rfc6265CookieValidationEnabled) {
277277

278278
CookieJar cookieJar = new CookieJar();
279-
cookieJar.rfc6265ParsingEnabled = rfc6265CookieValidationEnabled;
280279
cookieJar.parsedCookies = parsedCookies;
281280
cookieJar.maxCookies = maxCookies;
282281
for (int i = 0; i < cookie.length(); ++i) {
@@ -468,11 +467,9 @@ private static void createCookie(final String value, final CookieJar cookieJar)
468467

469468
private static void applyAdditional( final CookieJar cookieJar, final String name, final String value) {
470469
// RFC 6265 treats the domain, path and version attributes of an RFC 2109 cookie as a separate cookies
471-
if (!name.isEmpty() && name.charAt(0) == '$') {
472-
if (!OBSOLETE_COOKIE_PATTERN.matcher(name).find() || cookieJar.rfc6265ParsingEnabled) {
473-
Cookie c = new CookieImpl(name, value);
474-
cookieJar.parsedCookies.add(c);
475-
}
470+
if (!name.isEmpty() && name.charAt(0) == '$' && OBSOLETE_COOKIE_PATTERN.matcher(name).find()) {
471+
Cookie c = new CookieImpl(name, value);
472+
cookieJar.parsedCookies.add(c);
476473
}
477474
if (cookieJar.version == 1) {
478475
// rfc2109 - add metadata to
@@ -592,7 +589,6 @@ private Cookies() {
592589
}
593590

594591
private static class CookieJar {
595-
public boolean rfc6265ParsingEnabled;
596592
//Currently parsed cookie, if V1, all $ will be applied to it, until
597593
CookieImpl currentCookie;
598594
int maxCookies;

‎core/src/test/java/io/undertow/util/CookiesTestCase.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ public void testQuotedEscapedStringInRequestCookie() {
451451
public void testSimpleJSONObjectInRequestCookies() {
452452
// allowEqualInValue and allowHttpSepartorsV0 needs to be enabled to handle this cookie
453453
// Also, commaIsSeperator needs to be set to false
454-
OptionMap options = OptionMap.builder().set(UndertowOptions.MAX_COOKIES, 2)
454+
OptionMap options = OptionMap.builder().set(UndertowOptions.MAX_COOKIES, 5)
455455
.set(UndertowOptions.ALLOW_EQUALS_IN_COOKIE_VALUE, true)
456456
.set(UndertowOptions.ENABLE_RFC6265_COOKIE_VALIDATION, false).getMap();
457457
Map<String, Cookie> cookies = parseRequestCookies(Arrays.asList(
@@ -653,7 +653,7 @@ public void testMultipleRFC2109() {
653653
.set(UndertowOptions.ALLOW_EQUALS_IN_COOKIE_VALUE, false)
654654
.set(UndertowOptions.ENABLE_RFC6265_COOKIE_VALIDATION, false).getMap();
655655
Cookies.parseRequestCookies(toParse, parsedCookies, options);
656-
Assert.assertEquals(""+parsedCookies,3, parsedCookies.size());
656+
Assert.assertEquals(""+parsedCookies,6, parsedCookies.size());
657657
List<Cookie> lst = parsedCookies.get("CUSTOMER");
658658
Assert.assertEquals(2, lst.size());
659659
Cookie cookie = lst.get(0);

0 commit comments

Comments
 (0)