Skip to content

feat(auth): Keep users signed in while they are active - #132299

Draft
cleptric wants to merge 1 commit into
masterfrom
feat/sliding-login-session
Draft

cleptric wants to merge 1 commit into
masterfrom
feat/sliding-login-session

Conversation

@cleptric

Copy link
Copy Markdown
Member

A login session ends SESSION_COOKIE_AGE (14 days) after it was last saved, which is usually when the user signed in. Someone who uses Sentry every day still has to sign in again every two weeks.

With organizations:sliding-session-expiry, a signed-in user's session is saved again when they make a request for that organization and the session is more than a day old. The 14 days then limit inactivity instead of counting from sign-in. Without the flag nothing changes.

Review notes

  • The renewal is in AuthenticationMiddleware.process_response. It only acts when the session cookie signed the user in (get_user cached a user), so token requests never get a session, and it doesn't read the session on requests that hadn't already.
  • It skips responses with a status of 500 or above, responses that may be cached, and requests that signed the user out.
  • The session records when it was last renewed in _renewed_at, so the cookie is set again at most once per interval: a day, or half of SESSION_COOKIE_AGE when that is shorter.
  • The flag is checked against the organization that organization and project endpoints put on the request, so requests for no organization don't renew. The session belongs to the user, so one organization with the flag keeps them signed in everywhere.
  • Sessions are signed cookies with no server-side record, so there is no absolute limit here: an active session lasts until the user signs out or their session nonce changes. SSO sessions keep their own limits, and sudo, superuser and staff are separate cookies with their own expiry.

Refs #43182
Refs ENG-6427

🤖 Generated with Claude Code

A session ends SESSION_COOKIE_AGE (14 days) after it was last saved,
which is usually when the user signed in. Someone who uses Sentry
every day still has to sign in again every two weeks.

Save the session again when a signed-in user makes a request for an
organization with organizations:sliding-session-expiry and the session
is more than a day old. The 14 days then limit inactivity instead.

Requests authenticated with a token, failed requests and responses
that may be cached never renew a session.

Refs #43182
Refs ENG-6427

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Nov 24, 2026

Copy link
Copy Markdown

ENG-6427

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 24, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant