Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit b40fa35. Configure here.
getBearerToken logs in when no valid session exists, so callers on hot paths pay for a login and wait on it. getCachedBearerToken reads the cached token synchronously and returns undefined instead of logging in.
Both auth flows inlined the 90% expiry rule. isFreshLoginResponse holds it once, and getCachedBearerToken uses it so its checks match the SRP flow, including the JWT exp check it previously skipped.
basgys
force-pushed
the
feat/auth-cached-bearer-token
branch
from
September 17, 2026 15:12
6720763 to
9a6220e
Compare
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.

Explanation
AuthenticationController:getBearerTokenlogs in when no valid session exists. Callers on hot paths therefore pay for a login, and wait on it: a nonce fetch, a snap signature,authenticateandauthorizeOIDC, with no timeout. On a failing auth API every call retries, and a 429 makes each call sleep forRetry-Afterfirst.This adds
getCachedBearerToken(), a synchronous read of the token already in state. It never logs in. It returnsundefinedwhen the wallet is locked, when the SRP has no session, and when the token is past 90% of its lifetime, which is the point wheregetBearerTokenreplaces it. Refreshing stays with whichever caller next usesgetBearerToken.The caller this is for is #9927, which presents the token on requests to built-in Infura endpoints. There, a login per RPC request is not acceptable, and the async getter also forces a
fetchwrapper just to inject the header. A synchronous getter removes both.Open as a separate PR so it can be reviewed, and closed, on its own.
References
Follows from the Bugbot finding on #9927: #9927 (comment)
Checklist
Note
Medium Risk
Changes how access tokens are read on authentication hot paths; mis-calling the sync getter vs async refresh could omit headers near expiry, though behavior is intentionally tied to existing 90% refresh rules.
Overview
Adds
getCachedBearerToken()and the messenger actionAuthenticationController:getCachedBearerTokenso hot-path callers (e.g. per-RPC Infura requests) can read the OIDC access token synchronously from controller state without triggering login. It returnsundefinedwhen the wallet is locked, there is no SRP session, the session fails freshness checks, orcanonicalProfileIdis missing—the same conditions under whichgetBearerTokenwould refresh rather than reuse the cache.Introduces shared helper
isFreshLoginResponse(validLoginResponseplus session age under 90% ofexpiresIn) and refactors SIWE/SRP#getAuthSessionto use it instead of duplicated inline TTL logic, keeping the cached getter aligned with the JWT bearer flows.Reviewed by Cursor Bugbot for commit 9a6220e. Bugbot is set up for automated code reviews on this repo. Configure here.