{{ message }}
Repository navigation
fix(frontend): refresh the session token without Web Locks on plain HTTP - #21616
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
navigator.locks exists only in secure contexts, so on an http:// origin the token refresh threw and every expired access token logged the user out. Refresh directly when Web Locks is unavailable. Fixes bytebase#21575
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #21575.
Cause
tryAcquireAndRefreshinfrontend/src/api/refreshToken.tscallsnavigator.locks.requestunconditionally. The Web Locks API exists only in secure contexts (HTTPS or localhost). On a plainhttp://originnavigator.locksisundefined, sorefreshTokens()rejects withTypeError: Cannot read properties of undefined (reading 'request').authInterceptortreats that as a failed refresh and signs the user out everyaccess_token_duration, even though the refresh-token cookie is valid (the backend setsSecureonly on HTTPS).Fix
navigator.locksis unavailable, refresh directly and broadcast completion, the same as the locked path.localPromisestill applies, so concurrent requests in one tab share one refresh.Without Web Locks there is no cross-tab coordination, so two tabs that refresh at the same moment can still race on the single-use refresh token. That case is rare compared with the current behavior, where every refresh on HTTP fails.
Validation
frontend/src/api/refreshToken.test.ts(3 tests). Before the fix, the 2 tests without Web Locks fail with theTypeErrorabove; after the fix, all 3 pass.pnpm --dir frontend fix: no changes. Gate stages run individually:biome ci, guard scripts,tsc --build --force,vite build --mode releaseandvitest run(577 files, 6546 tests) pass.Breaking changes
None.