Skip to content

fix: update session token refresh logic to trigger with less than 60 seconds remaining - #383

Open
H-LK wants to merge 1 commit into
owncloud:masterfrom
H-LK:fix/session-refresh-window-60s
Open

H-LK wants to merge 1 commit into
owncloud:masterfrom
H-LK:fix/session-refresh-window-60s

Conversation

@H-LK

@H-LK H-LK commented Nov 16, 2026

Copy link
Copy Markdown

The current refresh trigger in SessionVerifier::refreshToken() refreshes the browser session's access token when less than 5 minutes remain. For the common case of 5-minute access tokens this means a refresh-token request is sent to the identity provider on virtually every request, because a token is almost always within its last 5 minutes right after it was refreshed — most of those refresh calls are redundant.

This PR:

  • refreshes only when less than 60 seconds remain on the access token, so a standard 5-minute token is refreshed exactly once per lifetime instead of on every request; refresh at the 60-second mark is still comfortably inside the token validity
  • exposes the wall clock through a protected getTime() helper so unit tests can freeze time

Tests

  • testRefreshWindow — data provider covering 32 remaining-expiry values (from far future to expired) × 3 token sources (cached-expiry, JWT payload, token introspection): no refresh at 60 s or more remaining, refresh below 60 s
  • testRepeatedRequestsDoNotImmediatelyRefreshRotatedTokens — 600-request simulation over 10 minutes with token rotation: refreshes happen exactly when the (rotated) token enters its final 60 s, and the very next requests (a few seconds later, on the fresh token) do not refresh again

Background

Split out of #377 as requested in the review there: this PR contains only the SessionVerifier refresh-window change and no other parts of that PR.

…seconds remaining

The previous refresh trigger refreshed the browser-session access token on
every request as soon as less than five minutes were left on a five-minute
token, causing a high volume of redundant refresh-token calls to the
identity provider.

Only refresh with less than 60 seconds remaining instead, and expose the
clock via a protected getTime() helper so tests can freeze time.

Signed-off-by: Hendrik Linka <[email protected]>
@H-LK
H-LK requested a review from a team as a code owner November 16, 2026 13:15
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants