Keep remembered sessions alive instead of prompting

What does this MR do and why?

The session-expiry modal (!257367 (merged)) warns a user before an inactive session expires, then prompts them to sign in again. The page renders the same deadline the session commit stores (!257368 (merged)).

That prompt is wrong for a user who signed in with "Remember me". Once the Rails session expires, the remember-me cookie signs them back in silently, so a reload just works. Worse, an open page keeps the expired session's CSRF token, so writes fail. GraphQL mutations get a 422, and REST writes run as anonymous. Reads keep working.

This MR keeps the session alive from the remember-me cookie instead of prompting.

Backend:

  • Gitlab::Sessions::RememberMe.expires_at(user, cookies) returns when the remember-me cookie stops signing the user back in.
  • It returns nil when the cookie is missing, revoked, older than the 2-week remember period, or when the admin disabled remember me. It uses Devise's own remember_me? check.
  • SessionsHelper renders the value as a data-remember-me-expires-at attribute (in ms) on the modal element.
  • The attribute is left out when sessions expire from sign-in (session_expire_from_init), because that deadline cannot be extended.

Frontend:

  • Two minutes before the session deadline, if the cookie outlasts the deadline, the modal sends one fetch to /api/v4/version. That saves and extends the session.
  • The modal then rebroadcasts the new deadline, read from the X-Gitlab-Session-Expires-At response header, to all tabs.
  • It is a plain fetch, not axios, so idle tagging (!259914 (merged)) never marks it as a background request. It uses cache: 'no-store', so it always reaches the server.
  • The modal sends one request at a time. If it fails on the network, the next check retries it. HTTP errors do not retry.
  • If every attempt fails, or the deadline has already passed, the modal shows as before.

Docs: a paragraph under "Sign-in prompt on SAML instances" in doc/administration/settings/account_and_limit_settings.md.

Known limits:

  • If an admin turns off Allow users to extend their session, open pages pick that up only after a reload.
  • Background tabs throttle timers. The 2-minute lead covers that.
  • A tab that gets no timer check in the 2 minutes before the deadline (computer asleep, or a tab the browser froze) shows the modal when it wakes, even though the remember-me cookie would sign the user back in. Reloading or selecting Sign in signs them in without a password.
  • The cookie expiry is read when the page renders. If the cookie is re-issued later, for example by a sign-in in another tab, an open page keeps the old expiry and can stop keeping the session alive early. Another open tab with the newer value still keeps every tab alive.

This needs AppSec review, because it keeps a session alive from the remember-me cookie.

Dependencies

  • Stacked on and targets MR3: !257368 (merged). GitLab retargets this MR once MR3 merges.

References

Related to #607513 (closed)

Screenshots or screen recordings

No visual change: the modal is unchanged; it simply does not appear for remembered users.

How to set up and validate locally

  1. Configure instance SAML. The modal only renders when an instance saml omniauth provider is configured.
  2. Enable the feature flag: Feature.enable(:session_expire_modal_on_saml_instances).
  3. Set Admin > Settings > General > Account and limit > Session duration (minutes) to 5, then restart GDK. The activity deadline reads the boot-time value.
  4. Make sure Allow users to extend their session (remember_me_enabled) is on. Sign in with Remember me checked.
  5. Open any page and wait. About 2 minutes before expiry, DevTools Network shows one GET /api/v4/version. Its response carries X-Gitlab-Session-Expires-At, about 5 minutes later. The modal does not appear.
  6. Sign out, then sign in without Remember me. The modal appears at expiry as in MR2.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Eduardo Sanz García

Merge request reports

Loading
Loading