Skip to content

Conversation

@WilberC
Copy link

@WilberC WilberC commented Aug 10, 2025

Session cookie persistence

Overview

  • server.sessionCookieMaxAgeMinutes controls the browser persistence of the JSESSIONID cookie.
  • Default is 0 → session-only cookie (no persistent Max-Age) [Currently is working like this].
  • Set to a positive number (minutes) to make the cookie persistent.

Configure

Edit your server.conf:

server.sessionCookieMaxAgeMinutes = 0
  • Keep at 0 for session-only cookies.
  • Example for 30 days persistence:
server.sessionCookieMaxAgeMinutes = 43200

Restart the server to apply changes.

What changes

  • When > 0: Jetty issues Set-Cookie: JSESSIONID; Max-Age=<minutes*60>; HttpOnly.
  • When 0: No Max-Age is set (session cookie).
  • Server-side session inactivity timeout after login remains 30 days; this setting only affects browser persistence.

Verify

  1. Set desired value in server.conf, restart.
  2. Login via WebUI.
  3. Check response headers or browser devtools:
    • With 0: Set-Cookie: JSESSIONID has no Max-Age.
    • With 5: header includes Max-Age=300.

Notes

  • Use session-only (0) for stricter security/privacy.
  • Use persistence for convenience on trusted devices/hosts.

- Added configuration for Jetty session cookie handling, allowing for persistent cookies based on the new `server.sessionCookieMaxAgeMinutes` setting.
- Updated session inactivity timeout to extend from ~30 minutes to 30 days.
- Simplified Jetty session cookie handling by directly using the `sessionCookieMaxAgeMinutes` from the server configuration.

# Sessions
# 0 = default session cookie behavior (no persistent Max-Age); >0 = persistent JSESSIONID with given max-age in minutes
server.sessionCookieMaxAgeMinutes = 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say put it under authentication and name it simpleAuthSessionCookieMaxAge, add a comment after it similar to the other comments

val sessionHandler = context.sessionHandler ?: SessionHandler()
sessionHandler.sessionCookieConfig.apply {
val cookieMaxAgeMinutes: Int = serverConfig.sessionCookieMaxAgeMinutes.value
if (cookieMaxAgeMinutes > 0) maxAge = (cookieMaxAgeMinutes * 60)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (cookieMaxAgeMinutes > 0) maxAge = (cookieMaxAgeMinutes * 60)
if (cookieMaxAgeMinutes > 0) maxAge = cookieMaxAgeMinutes.minutes.inWholeSeconds.toInt()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants