Skip to content

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

Open
solracsf wants to merge 2 commits into
mainfrom
fix/token-refresh-rotation-race
Open

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

Conversation

@solracsf

@solracsf solracsf commented Jun 7, 2026

Copy link
Copy Markdown
Member

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>
@solracsf solracsf force-pushed the fix/token-refresh-rotation-race branch from 049c6d1 to 56c7353 Compare June 10, 2026 10:53
@solracsf solracsf marked this pull request as draft June 10, 2026 10:56
…bsence

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
@solracsf solracsf force-pushed the fix/token-refresh-rotation-race branch from 6aa6f52 to f97e9a4 Compare June 11, 2026 08:56
@solracsf solracsf marked this pull request as ready for review June 11, 2026 09:05
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