Skip to content

fix(auth): keep remember-me cookies pointing at a live session token - #64572

Open
solracsf wants to merge 7 commits into
masterfrom
fix/remember-me-stale-session-token
Open

solracsf wants to merge 7 commits into
masterfrom
fix/remember-me-stale-session-token

Conversation

@solracsf

@solracsf solracsf commented Sep 19, 2026

Copy link
Copy Markdown
Member

Summary

Since 33.0.9 a stale remember-me cookie logs "Could not find the session token to renew" on every request, so affected instances end up with thousands of these. The cookie points at a session token that no longer exists. This fixes two ways that happens in core:

  • OC_User::loginWithApache() creates the session token as "do not remember" but then sets the 15 day remember-me cookies. The cleanup job deletes such tokens after session_lifetime (24h by default), so anyone away for a day hits the loop when they come back. The token is now created as REMEMBER.
  • regenerateId(true, true) (password protected share unlock, Talk password rooms) moves the token to the new session id but never updated nc_session_id. The cookie is now rewritten to the new id.

What is not covered: user_oidc has the same mismatch as the Apache login (it creates the token with the default DO_NOT_REMEMBER and then calls createRememberMeToken()), so it needs the same one line change in that app. A token that is revoked or logged out via IdP backchannel logout after the browser session already expired still leaves the cookies behind, and each request will still log the error. Tokens that are already orphaned are not repaired, those users have to log in once more.

Tested in Docker (sqlite): the new unit tests fail without the change and pass with it. tests/lib/User passes. I also checked both fixes against a live instance: the share unlock keeps cookie login working (before the change it returned 401 and logged the error), and a session created through loginWithApache() now gets remember=1 instead of 0. There is no unit test for loginWithApache(), since it needs a real PHP session.

Needs backports to stable33 (where 33.0.9 introduced the log flood) and probably stable34.

Checklist

AI (if applicable)

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

The remember-me cookie outlives the session token it refers to in two
cases, and cookie login then fails on every request.

A session token created as DO_NOT_REMEMBER (user_oidc, Apache login) is
removed by the cleanup job after session_lifetime, while the cookies last
remember_login_cookie_lifetime. createRememberMeToken() now marks the
current session token as remembered.

ISession::regenerateId(true, true) moves the token to the new session id
but left nc_session_id pointing at the old one (password protected share
unlock, Talk password rooms). The cookie is now rewritten with the new id.

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
@solracsf
solracsf requested a review from a team as a code owner September 19, 2026 18:24
@solracsf
solracsf requested review from Altahrim, come-nc, icewind1991 and provokateurin and removed request for a team September 19, 2026 18:24
@solracsf solracsf added this to the Nextcloud 36 milestone Sep 19, 2026
@solracsf solracsf added the 3. to review Waiting for reviews label Sep 19, 2026
@solracsf solracsf self-assigned this Sep 19, 2026
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
Comment thread lib/private/User/Session.php Outdated
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
Comment thread lib/private/User/Session.php Outdated
Comment thread lib/private/User/Session.php Outdated
Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
loginWithApache() sets remember-me cookies but created the session token
as DO_NOT_REMEMBER, so the cleanup job removed it after session_lifetime
while the cookie stayed valid. Fix it where the mismatch originates and
drop the workaround in createRememberMeToken().

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
…le-session-token

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
…le-session-token

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: InvalidTokenException Token does not exist: token does not exist Renewing session token failed: Token does not exist: token does not exist

3 participants