Properly handle negative Max-Age in RFC6265SetCookieParser#14311
Properly handle negative Max-Age in RFC6265SetCookieParser#14311Petersoj wants to merge 1 commit intojetty:jetty-12.1.xfrom
Max-Age in RFC6265SetCookieParser#14311Conversation
|
The spec at https://datatracker.ietf.org/doc/html/rfc6265#section-5.2.2 also says ...
I think this is where that (bad) logic came from. |
|
An alternative fix would be in HttpCookie.java: case "max-age" -> maxAge(StringUtil.isBlank(value) ? -1 : Math.max(0, Long.parseLong(value))); |
|
@afarber my initial goal was to not modify the existing behavior of |
|
I think the matter is more complicated. JDK's
Jakarta's Jetty's Jetty's Jetty's Jetty's There are other cases where we do not treat a negative value as significant, so I'll rework those as well. @Petersoj thanks for raising this issue! I'm going to close this PR and rework max-age handling across the code. The point is that the cookie max-age value must be preserved in any case. Is it the client that interprets it, and only the client must eventually take action following the cookie max-age value. Also, the Java/Jakarta javadocs are in contrast with RFC 6265, which also contradits itself. However, section 5.2.2 mentions the MDN follows the RFC: https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Set-Cookie#max-agenumber I will check what browsers actually do, but I suspect they will follow the RFC. If that's the case, we have a problem because the Java/Jakarta javadocs say one thing, but RFC another. |
|
Parsing a
Set-Cookieheader with a negativeMax-Ageshould be treated as the cookie expiring immediately, which is the same asMax-Age=0.RFC6265SetCookieParserandHttpCookiecurrently treat a negativeMax-Ageattribute the same as removing theMax-Ageattribute, which is incorrect according to rfc6265#section-5.2.2: