Add persistent session cookie (30-day expiry) #170
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "ui-observations"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fix users getting signed out on browser/tab close by adding a 30-day persistent session cookie. Rails default is ephemeral browser-session cookies — no
expire_aftermeans the cookie dies when the browser process exits.Changes
config/initializers/session_store.rbwithexpire_after: 30.daysTest Plan
_landscaping_assistant_sessionwith 30-day max-ageReview Checklist
Related Notes
Closes #168
Partial fix for persistent auth. The Keycloak SSO idle timeout (30 min default) still needs a pal-e-services Terraform change — that remains on the spike backlog.
PR #170 Review
DOMAIN REVIEW
Tech stack: Ruby on Rails 8.1, cookie-based session store, OmniAuth/Keycloak SSO.
Change: Adds
config/initializers/session_store.rbwith a single line settingexpire_after: 30.dayson the cookie store.Correctness:
:cookie_storewith noexpire_after, meaning ephemeral browser-session cookies. This change correctly overrides that to persist the session across browser restarts.expire_afteroption sets theMax-Ageattribute on the cookie, which is the standard mechanism for persistent cookies. This is the correct Rails API.Security analysis:
httponly: Rails sets this by default on session cookies via ActionDispatch -- no risk of JS access.secureflag: Production hasconfig.assume_ssl = true(line 29 ofproduction.rb). In Rails 8.x, this causes ActionDispatch to mark cookies assecure. The cookie will not be sent over plain HTTP in production. Confirmed safe.SameSite: Rails 8.x defaults toSameSite=Lax, which provides CSRF protection for the cookie. No concern.{username, email, roles}(persessions_controller.rb:17-21). Extending cookie lifetime to 30 days means this data persists longer. Since Rails encrypts/signs the cookie by default, the data is not exposed client-side. Acceptable.session.delete(:user)inSessionsController#destroyclears the server-side session data, and Rails will issue a new (empty) cookie. The 30-day expiry does not interfere with explicit logout.One consideration (not a blocker): The Keycloak SSO session has a separate idle timeout (30 min by default, per the PR body). After the Keycloak session expires, the Rails cookie will still keep the user "logged in" to the Rails app until either: (a) 30 days pass, or (b) the user explicitly logs out. This is acknowledged in the PR body as a known gap requiring a separate Terraform change. For this app's threat model (internal crew tool on Tailscale), this is acceptable.
BLOCKERS
None. This is a one-line declarative configuration change with no logic to test, no user input, no secrets, and correct security posture.
On test coverage: Normally new functionality without tests is a blocker. However, this is a Rails initializer setting a framework-provided option. The behavior (cookie
Max-Ageheader) is tested by Rails itself. An integration test proving "session persists after browser close" would require browser lifecycle management beyond what RSpec/Capybara provides in-process. No test gap here.NITS
The file has no trailing newline after the single line. Most editors and linters prefer files end with
\n. Minor --git diffshows\ No newline at end of fileis not present, so this is fine.Consider adding a brief comment explaining the "why" for future developers:
This is purely optional for a one-line file.
SOP COMPLIANCE
ui-observations, should be168-persistent-session-cookieper conventionPROCESS OBSERVATIONS
VERDICT: APPROVED