Session cookie lasts until browser close only without Max-Age or Expires
@seungwoody▲ 0 net votes
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.