Skip to content

fix(auth): Keep remember-me logins working for concurrent requests - #66416

Open
DerDreschner wants to merge 3 commits into
fix/session-timeout-issuesfrom
fix/remember-me-token-rotation-grace
Open

DerDreschner wants to merge 3 commits into
fix/session-timeout-issuesfrom
fix/remember-me-token-rotation-grace

Conversation

@DerDreschner

@DerDreschner DerDreschner commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Summary

A remember-me login replaces the remember-me token and the session token on every use. When several requests arrive with the same cookies after the session is gone, for example from a browser restoring its tabs, only the first one gets in and the others are logged out.

  • The replaced tokens stay valid for 60 seconds, so those requests log in too (new column oc_authtoken.superseded_at).
  • The session tokens of one browser login share a login_id. Devices & sessions shows one entry per login, and revoking or wiping it ends all of them.
  • A request that moves its session twice (remember-me login, then unlocking a password-protected share) re-issues the remember-me cookies for the second move as well.

The migration needs a version bump, which is not part of this PR.

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

A request can move its session twice: a remember-me login moves it, and
unlocking a password-protected share in the same request moves it again.
The second move looked at the cookies the request came with, which no
longer point at the session it moves from. It did not re-issue the
remember-me cookies, so nc_session_id kept pointing at a session token
that is gone, and the next remember-me login failed.

The user session now keeps track of the remember-me cookies it set or
removed during the request and checks those instead of the ones the
request came with. The remember-me login and the end of an inactive
session read the cookies the same way, instead of from $_COOKIE and the
request.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
A browser login renews its session token on every remember-me login.
Each renewal stored a new token with a new id, so the entry in Devices &
sessions changed its id while the browser was in use, and concurrent
renewals of the same token forked the login into several session tokens
that showed up as separate devices.

Session tokens now know the login they belong to. Renewing a session
token keeps it in the new login_id column, which points at the first
token of the login. Devices & sessions shows one entry per login, and its
id stays the same while the browser renews its session token. Revoking,
wiping, renaming and logging out act on every token of the login, and so
do occ user:auth-tokens:delete and deleting a user. "Revoke all other
sessions" also ends the other session tokens of the current login, so
only the session it is used from stays. App passwords and other tokens are
logins of their own.

Renewing a session token now locks and deletes it first, so only one
request can renew it, and the new token takes the current name, scope
and password of the old one. Changing a login locks its tokens, so a
renewal stored while the login is renamed, restricted, revoked or wiped
gets the same change. When unlocking a password-protected share loses
that race to a concurrent request, its new session no longer stays logged
in without a session token, which ended the remember-me login on the next
request. It is logged out instead, so the remember-me cookies can log it
in again.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
A remember-me login replaces the remember-me token and the session token
on every use. Requests that were sent before the replacing response
arrived, for example when a browser opens several tabs after its session
is gone, still carry the replaced cookies. Their remember-me login failed,
and they were logged out or shown the login page although their cookies
were valid when they were sent.

The replaced remember-me token and the replaced session token now stay
valid for 60 seconds instead of being deleted. A request with the
replaced cookies runs the normal remember-me login during that time and
gets a session token of its own in the same login. The replaced session
token keeps the time it was replaced in the new superseded_at column. It
is refused once its grace period is over, and the daily token cleanup
deletes it. Every renewal during the grace period writes the replaced
session token, so database clusters that don't share row locks still see
a concurrent revocation as a conflict. The stored time of the replaced
remember-me token is moved back so that its lifetime ends with the grace
period, and the remember-me login now refuses tokens older than
remember_login_cookie_lifetime instead of relying on the cleanup job.
Moving the session token when unlocking a password-protected share still
deletes the old one at once.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
@DerDreschner
DerDreschner force-pushed the fix/remember-me-token-rotation-grace branch from 209bf79 to 086e1b9 Compare November 18, 2026 14:34
@DerDreschner
DerDreschner marked this pull request as ready for review November 18, 2026 14:35
@DerDreschner
DerDreschner requested review from Altahrim, CarlSchwan, come-nc, marcoambrosini and pringelmann and removed request for a team November 18, 2026 14:35
@DerDreschner DerDreschner added the 3. to review Waiting for reviews label Nov 18, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tried to log in "user" but could not verify token Having to log in twice

1 participant