Draft: Stop ETag-cached polls from extending the session

What does this MR do and why?

Any authenticated background poll currently refreshes the Rails session TTL, even when the tab has no human interaction. Session renewal happens upstream of the controller (Rack::Attack runs auth, which fires the Warden fetch hook), so even an ETag 304 response commits the session on the way out and refreshes its store TTL. The practical effect is that a browser tab that only polls never idle-times-out, silently defeating activity-based inactivity logout.

This MR fixes that in the ETag caching Rack middleware (Gitlab::EtagCaching::Middleware). Once the ETag router matches a route, the middleware sets request.session_options[:skip] = true, which tells Rack not to commit the session. This covers both GraphQL and REST ETag-cached polling endpoints, on both the 304 cache-hit and the cache-miss paths, in one place. There is no frontend change.

This is fail-closed: skipping the session commit can only ever forgo a session extension, it can never extend a session beyond its normal lifetime, and it can never shorten it below normal. Only ETag-cached (read-only polling) routes are affected.

The fix deliberately does not stop the separate ActiveSession metadata write, which also refreshes on a poll. That write is metadata only: normal HTTP authentication loads the user from the Rails session key, not from ActiveSession, so leaving it untouched does not gate login. Keeping it in place also keeps the ActionCable connection working for poll-only tabs.

The change is behind a feature flag, etag_caching_skip_session_extension (type gitlab_com_derisk, group group::authentication, default disabled).

This is a sibling of the telemetry beacon fix in !254940 (merged), which used the same request.session_options[:skip] idiom for the /-/collect_events endpoint.

References

How to set up and validate locally

  1. Enable the flag in the Rails console:
    Feature.enable(:etag_caching_skip_session_extension)
  2. Shorten the session lifetime so expiry is observable quickly, in the Rails console (value is in minutes):
    ApplicationSetting.current.update!(session_expire_delay: 5)
  3. Sign in, then open a page that polls an ETag-cached endpoint, for example a project's Pipelines page (polls pipelines.json) or a merge request (polls cached_widget.json). Leave the tab idle with no clicks or navigation.
  4. Observe that the Rails session key TTL in the sessions Redis is no longer reset by the polls (it keeps decaying). With the flag disabled, the polls reset it and the session stays alive.
  5. After the session lifetime elapses while idle, trigger a real navigation: you are redirected to the sign-in page because the session expired.

Note: the flag is checked per request, but the middleware code change requires running this branch (checkout plus the usual GDK reload/restart if the app was already running).

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.

Merge request reports

Loading
Loading