Skip to content

Commit 4f1e741

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 e632ac0 commit 4f1e741

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) {
@@ -465,11 +464,9 @@ private static void createCookie(final String value, final CookieJar cookieJar)
465464

466465
private static void applyAdditional( final CookieJar cookieJar, final String name, final String value) {
467466
// RFC 6265 treats the domain, path and version attributes of an RFC 2109 cookie as a separate cookies
468-
if(!name.isEmpty() && name.charAt(0) == '$') {
469-
if (!OBSOLETE_COOKIE_PATTERN.matcher(name).find() || cookieJar.rfc6265ParsingEnabled) {
470-
Cookie c = new CookieImpl(name, value);
471-
cookieJar.parsedCookies.add(c);
472-
}
467+
if(!name.isEmpty() && name.charAt(0) == '$' && OBSOLETE_COOKIE_PATTERN.matcher(name).find()) {
468+
Cookie c = new CookieImpl(name, value);
469+
cookieJar.parsedCookies.add(c);
473470
}
474471
if (cookieJar.version == 1) {
475472
// rfc2109 - add metadata to
@@ -589,7 +586,6 @@ private Cookies() {
589586
}
590587

591588
private static class CookieJar {
592-
public boolean rfc6265ParsingEnabled;
593589
//Currently parsed cookie, if V1, all $ will be applied to it, until
594590
CookieImpl currentCookie;
595591
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)