Repository navigation
Let users set their session lifetime in account settings - #2612
Merged
Merged
Conversation
four-random-common-words
force-pushed
the
2518-session-lifetime
branch
from
November 5, 2026 09:09
59701f9 to
b17650a
Compare
four-random-common-words
marked this pull request as ready for review
November 10, 2026 09:20
four-random-common-words
requested review from
s3inlc
and
a balanced review from Copilot
November 10, 2026 09:20
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A regression test is missing to verify that rotating an existing token uses the user's updated persisted lifetime for the successor's endValid.
1 open issue
What changed in this PR
Restores user-controlled session lifetimes by applying each account’s setting to refresh tokens and cookies, supporting the account-settings feature requested in #2518.
Changes:
- Bounds refresh-token lifetimes between two hours and the configured maximum, applying changes on login or refresh.
- Adds optional session-lifetime updates to the current-user endpoint, with validation before writes.
- Updates account defaults, database migrations, API documentation, and regression tests.
| File | Description |
|---|---|
src/migrations/postgres/20261104120000_session-lifetime-minimum.sql |
Raises existing PostgreSQL lifetimes to two hours. |
src/migrations/mysql/20261104120000_session-lifetime-minimum.sql |
Raises existing MySQL lifetimes to two hours. |
src/inc/utils/UserUtils.php |
Validates lifetimes and updates new-user defaults. |
src/inc/utils/RefreshTokenUtils.php |
Applies bounded per-user lifetimes to refresh tokens. |
src/inc/utils/ConfigUtils.php |
Enforces a two-hour configuration minimum. |
src/inc/utils/AccountUtils.php |
Centralizes session-lifetime validation. |
src/inc/startup/setup.php |
Sets the initial administrator’s lifetime to two hours. |
src/inc/apiv2/helper/CurrentUserHelperAPI.php |
Supports validated partial email and lifetime updates. |
src/inc/apiv2/auth/token.routes.php |
Passes user context when issuing tokens and cookies. |
src/inc/apiv2/auth/RefreshTokenCookie.php |
Uses the user’s bounded lifetime for cookies. |
openapi.json |
Updates the current-user PATCH description. |
ci/phpunit/inc/utils/UserUtilsTest.php |
Tests rejection of short lifetimes during creation. |
ci/phpunit/inc/utils/RefreshTokenUtilsTest.php |
Tests lifetime bounds and updates token calls. |
ci/phpunit/inc/utils/AccountUtilsTest.php |
Tests revised lifetime validation boundaries. |
ci/apiv2/utils.py |
Updates shared user fixtures to the new minimum. |
ci/apiv2/test_user.py |
Tests lifetime creation and update validation. |
ci/apiv2/test_permissions.py |
Tests self-service lifetime updates and rejected partial updates. |
ci/apiv2/test_attributes.py |
Updates attribute-test fixtures to valid lifetimes. |
Review effort: Balanced
| return [ | ||
| "user" => $user, | ||
| "token" => self::issue($token->getUserId(), $token->getFamilyId()), | ||
| "token" => self::issue($user, $token->getFamilyId()), |
s3inlc
approved these changes
Nov 10, 2026
s3inlc
left a comment
Member
There was a problem hiding this comment.
reminder to update migrations date before merge
four-random-common-words
force-pushed
the
2518-session-lifetime
branch
from
November 13, 2026 09:43
b17650a to
2b20f1c
Compare
four-random-common-words
force-pushed
the
2518-session-lifetime
branch
from
November 18, 2026 12:25
2b20f1c to
8b3a14d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Issue: #2518
Frontend: hashtopolis/web-ui#859
Users can set their own session lifetime again, and it now decides how long their refresh token is valid. Until now every refresh token got the global
maxSessionLength, and the user'ssessionLifetimewas only used by the old UI's login.A refresh token now lives for the user's session lifetime, bounded to at least 2 hours and at most
maxSessionLength. Since the token is rotated on every refresh, this bounds how long a session survives without the app renewing it (browser closed, computer asleep), not how long it may exist in total.The minimum of 2 hours matches the access token lifetime: the frontend renews shortly before the access token expires, so a shorter refresh token would already be gone by then and end even active sessions.
ACCESS_TOKEN_LIFETIMEnow refers to the same constant, andmaxSessionLengthis floored at 2 hours as well (also as a bound of the config setting).PATCH /api/v2/helper/currentUseracceptssessionLifetimenext toemail, both optional; both are validated before anything is written, so a rejected attribute leaves the user unchanged. Creating a user validates the lifetime too, and new users (including the initial admin) start with 2 hours. A migration raises stored lifetimes below 2 hours to 2 hours.A changed lifetime applies from the next refresh or login; the frontend forces a refresh right after saving. Out of range values are still answered with a 500, like the existing user PATCH. The OpenAPI spec still has no request body for the helper PATCH, which was already the case for
email.