Skip to content

Keep a Remember Me session past the inactivity timeout - #2092

Merged
fog-workflows[bot] merged 2 commits into
dev-branchfrom
fix/remember-me-inactivity
Nov 11, 2026
Merged

fog-workflows[bot] merged 2 commits into
dev-branchfrom
fix/remember-me-inactivity

Conversation

@mastacontrola

Copy link
Copy Markdown
Member

Problem

A user checks Remember Me at sign-in. A few hours later, FOG shows "Session Expired" and asks for a new sign-in. Reported in forum topic 18315 on 1.6.0.14.

Cause

The idle check in User::_isLoggedIn() redirects to node=logout after FOG_INACTIVITY_TIMEOUT hours (default 1). It does not look at the remember-me cookie. logout() then clears the foguserauth* cookies, so Remember Me ends at the first idle hour.

The bug was hidden before #1306/#1307. PHP's 24-minute session GC deleted the session before the 1-hour check fired. The cookie replay in ProcessLogin::processMainLogin() then signed the user back in with no message. #1306 moved sessions to FOG's own store with gc_maxlifetime 86400. The session now outlives the timeout, so the idle branch fires first.

Fix

  • The idle branch skips the logout when the request has a valid remember-me token for the signed-in user. The lastactivity refresh then happens as on any active request.
  • UserAuth::matches() holds the token check. The row must belong to the user, must not be flagged isExpired, and must not be past its expiry. The selector and the password must both verify against the stored hashes.
  • Without a valid token, nothing changes.

ProcessLogin::processMainLogin() still has its own copy of the token check. I did not move it onto matches(): that path reads cookies through filter_input(), which the CLI suite cannot supply. An untested rewrite of a working sign-in path is the larger risk. The two copies agree except at the exact expiry second.

Test

tests/remember-me-outlives-inactivity.test.php runs isLoggedIn() on an idle session against the fake DB:

  • With no cookie, a bad selector, no token id, or another user's token, the session is logged out.
  • With a valid token, the session is not logged out, and lastactivity refreshes.
  • An active session with no cookie is not logged out.

It also runs matches() for each refusal case. Seven mutations of the fix each turn the test red on the matching check: the original bug, && changed to ||, swapped cookies, the wrong user id, no user binding, no expiry check, and no isExpired check.

Workaround on 1.6.0

Set FOG_ALWAYS_LOGGED_IN to 1, or set FOG_INACTIVITY_TIMEOUT to 24.

🤖 Generated with Claude Code

The idle check in User::_isLoggedIn() redirected to node=logout without
looking at the remember-me cookie, and logout() clears that cookie. So
Remember Me lasted only until the first idle FOG_INACTIVITY_TIMEOUT
(default 1 hour). Forum 18315.

It went unseen while PHP's 24-minute session GC deleted the session
first: ProcessLogin's cookie replay then signed the user back in. #1306
moved sessions to FOG's own 86400s store, so the session now outlives
the timeout and the idle branch fires first.

The idle branch now skips the logout when the request carries a valid,
unexpired remember-me token that belongs to the signed-in user. The
check is UserAuth::matches(). The test drives isLoggedIn() on an idle
session and fails under seven mutations of the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fog-workflows
fog-workflows Bot enabled auto-merge November 11, 2026 17:43
Review follow-up on #2092: the named helper had one caller, and a
reader of _isLoggedIn() now sees why its two cookie reads differ.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fog-workflows
fog-workflows Bot added this pull request to the merge queue Nov 11, 2026
Merged via the queue into dev-branch with commit df53759 Nov 11, 2026
11 checks passed
@fog-workflows
fog-workflows Bot deleted the fix/remember-me-inactivity branch November 11, 2026 17:56
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.

1 participant