Skip to content

Large cookie Max-Age overflows int in ServletServerHttpResponse, resulting in a session cookie or deletion #37472

Closed as not planned

Description

@padosol

Describe the bug

When the Max-Age of a ResponseCookie exceeds Integer.MAX_VALUE seconds, Servlet-based WebFlux servers emit a cookie that differs from the requested one. Depending on the value, it becomes a session cookie or the cookie is deleted. Reactor Netty and Jetty Core emit the requested Max-Age, so the behavior differs depending on the server.

To Reproduce

response.getCookies().add("remember", ResponseCookie.from("remember", "1")
                .maxAge(Duration.ofDays(36_500)).build());
Max-Age Servlet Cookie#getMaxAge() Result
Duration.ofDays(36_500) -1141367296 Session cookie
Duration.ofSeconds(1L << 32) 0 Cookie deleted

Expected: the Max-Age remains positive, resulting in a long-lived cookie.

Suspected cause

ServletServerHttpResponse#applyCookies() performs the following conversion.

cookie.setMaxAge((int) httpCookie.getMaxAge().getSeconds());

The narrowing cast to int overflows, and Servlet Cookie#setMaxAge(int) interprets a negative value as a session cookie and 0 as deletion. RestTestClientResponseAssert performs the same conversion.

This can be fixed by limiting the converted value to Integer.MAX_VALUE, as in #37427.

Related Issues

Activity

  1. bclozel commented on Oct 13, 2026

    @bclozel
    Member
  2. added
    status: supersededAn issue that has been superseded by another
    and removed on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: supersededAn issue that has been superseded by another

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions