Repository navigation
Fix session-restoration window: anchor on last_activity_at, not login_at - #146
Conversation
The restoration check updates last_activity_at to keep an active session fresh, but it looked the session up by login_at. Once the original login_at aged past session_restoration_window_minutes, a continuously-active session was no longer matched and a brand-new log entry was created — then again every window thereafter, for as long as the user (or a crawler) stayed active. This produced large chains of duplicate login rows spaced exactly one window apart. Look the active session up by last_activity_at (the value the restoration path actually maintains) so an active session keeps extending the same row. Updated two tests that aged login_at to age last_activity_at instead, and added a regression test covering a session active past its original window.
|
@rappasoft take a look at this please. |
…tests The factory randomizes last_activity_at anywhere between login_at and now for active sessions. With the restoration window now anchored on last_activity_at, a randomly recent value made the dispatched Login count as a session restoration, which skips suspicious-activity detection and intermittently failed the notification assertions (and let the negative variants pass vacuously). Pinning last activity to the fixture's login_at keeps these logins real re-logins under either anchor.
|
The earlier CI failures were caused by this PR interacting with randomized factory data, not by the environment: Fixed by pinning Note: the |
Problem
The session-restoration prevention added in v6.0.0 keeps an active session from creating duplicate log entries by updating
last_activity_atinstead of inserting a new row. However, it looks the active session up bylogin_at:Because the lookup is anchored on
login_at, thelast_activity_atit maintains is never actually used to decide whether the session is still active. Once a session's originallogin_atis older thansession_restoration_window_minutes, a continuously active session (page refreshes, polling, remember-me, crawlers hitting authenticated URLs) is no longer matched, so a brand-new log entry is created — and then another every window after that, for as long as activity continues.The result is long chains of duplicate login rows spaced exactly one restoration window apart for a single real session.
Fix
Look the active session up by
last_activity_at— the value the restoration path already maintains — so an active session keeps extending the same row no matter how long it runs:last_activity_atis always populated on creation ('last_activity_at' => now()), so this is a safe swap.Tests
login_atwindow stays a single row.login_atto agelast_activity_atinstead (the value the check now uses).All
SessionRestorationTestcases pass; the new regression test fails on the previouslogin_at-anchored logic and passes on the fix.