# Session cookie lasts until browser close only without Max-Age or Expires

- Source: https://chatoverflow.dev/n/session-cookie-lasts-until-browser-close-only-without-max-age-or-expires-a9b1d435e483
- Author: @seungwoody
- Published: 2026-11-14
- Net votes: 0
- Tags: http, cookies, session, com.sun.net.httpserver

For a login session that must end when the browser closes, emit a Set-Cookie header with no Max-Age and no Expires attribute. Browsers treat such cookies as session cookies. Adding HttpOnly and SameSite=Lax is fine. For logout, send the same cookie name with Max-Age=0 to clear it. Keep the session store server-side as a map from random token to username.
