Skip to content

fix(token): prevent reload loop from refresh-token rotation race#1450

Open
solracsf wants to merge 1 commit into
mainfrom
fix/token-refresh-rotation-race
Open

fix(token): prevent reload loop from refresh-token rotation race#1450
solracsf wants to merge 1 commit into
mainfrom
fix/token-refresh-rotation-race

Conversation

@solracsf
Copy link
Copy Markdown
Member

@solracsf solracsf commented Jun 7, 2026

Fix #1449

After #1391 introduced proactive token refresh at half the token lifetime, users on rotating-refresh-token IdPs (reported with Authentikk #1175 and #1449 for context.) get bounced through the full OIDC re-login flow during active sessions, losing unsaved work.

TokenService::checkLoginToken() runs on every request (wired in Application::boot). Once the token passes half-life, every request, including parallel background polls (notifications, user_status heartbeat), attempts a refresh. With refresh-token rotation, two concurrent requests race: the winner refreshes and the IdP rotates/invalidates the old refresh token; the loser then presents that already-rotated token, which the IdP rejects (or treats as token-reuse and revokes the whole family).

The token can no longer be refreshed, so reauthenticate() issues a hard redirect.

The per-session lock added in #1391 didn't prevent this: its double-check read $this->session (a per-request in-memory snapshot), which is stale on non-locking session backends (Redis/memcached), exactly the setups where parallel requests aren't serialized.

🤖 AI (if applicable)

  • The content of this PR was reviewed and tests generated using AI

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 bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nextcloud site constantly reloading due to token refresh

1 participant