-
Type:
Bug
-
Resolution: Fixed
-
Priority:
P4
-
Affects Version/s: 8
-
Component/s: core-libs
-
b07
-
generic
-
generic
HttpCookie treats cookies with an unparseable Expires attribute as immediately expired, rather than ignoring the attribute as specified by RFC 6265 section 5.2.1 and the updated getMaxAge() specification from JDK-8359343.
When expiryDate2DeltaSeconds() fails to parse the date string against all 6 formats, it returns 0. The caller assignMaxAgeAttribute() then executes (delta > 0 ? delta : 0), setting maxAge to 0. Since hasExpired() treats maxAge == 0 as immediately expired, the cookie is discarded.
The expected behavior per RFC 6265 section 5.2.1 is to ignore the unparseable expires attribute, leaving maxAge at -1 (session cookie).
This also matches step 4 of the updated getMaxAge() specification: "If previous step failed, then return -1."
Reproducer:
HttpCookie cookie = HttpCookie.parse(
"Set-Cookie: name=value; expires=GARBAGE").get(0);
System.out.println(cookie.getMaxAge()); // prints 0, expected -1
System.out.println(cookie.hasExpired()); // prints true, expected false
When expiryDate2DeltaSeconds() fails to parse the date string against all 6 formats, it returns 0. The caller assignMaxAgeAttribute() then executes (delta > 0 ? delta : 0), setting maxAge to 0. Since hasExpired() treats maxAge == 0 as immediately expired, the cookie is discarded.
The expected behavior per RFC 6265 section 5.2.1 is to ignore the unparseable expires attribute, leaving maxAge at -1 (session cookie).
This also matches step 4 of the updated getMaxAge() specification: "If previous step failed, then return -1."
Reproducer:
HttpCookie cookie = HttpCookie.parse(
"Set-Cookie: name=value; expires=GARBAGE").get(0);
System.out.println(cookie.getMaxAge()); // prints 0, expected -1
System.out.println(cookie.hasExpired()); // prints true, expected false
- links to
-
Commit(master)
openjdk/jdk/f146847c
-
Review(master)
openjdk/jdk/30341