feat: send the MetaMask auth token to built-in Infura endpoints - #9927
Open
basgys wants to merge 1 commit into
Open
feat: send the MetaMask auth token to built-in Infura endpoints#9927basgys wants to merge 1 commit into
basgys wants to merge 1 commit into
Conversation
Gudahtt
reviewed
Aug 24, 2026
| * endpoints are unaffected either way, as are requests that already carry an | ||
| * `Authorization` header. | ||
| */ | ||
| getInfuraAuthToken?: () => Promise<string | undefined>; |
Member
There was a problem hiding this comment.
Is this token the same as the one returned by AuthenticationController:getBearerToken? If so, can we use that action instead of a constructor param?
basgys
force-pushed
the
feat/network-controller-infura-auth-token
branch
2 times, most recently
from
August 25, 2026 15:01
0905232 to
ad065ed
Compare
basgys
force-pushed
the
feat/network-controller-infura-auth-token
branch
from
August 25, 2026 15:17
ad065ed to
9272c5d
Compare
`NetworkController` gains an optional `getInfuraAuthToken` option. It is called once per request to the primary endpoint of a network client of type `infura` (the ones built from `infuraProjectId`), and the token it returns is sent as a bearer credential in the `Authorization` header alongside the v3 project ID in the URL. Custom endpoints and failover endpoints never carry the token, so a user-supplied Infura key is never paired with it. When the token is unavailable or retrieval throws, the request is made unauthenticated. `@metamask/wallet` wires the option to `AuthenticationController:getBearerToken` over the network controller messenger, and only while `AnalyticsController` state has `optedIn: true`, since the token identifies the user.
basgys
force-pushed
the
feat/network-controller-infura-auth-token
branch
from
August 25, 2026 15:37
9272c5d to
ef7260c
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
Infura accepts the MetaMask auth token as
Authorization: Beareralongside the v3 project ID in the URL. This adds an optionalgetInfuraAuthTokenoption toNetworkControllerand wires it in@metamask/wallettoAuthenticationController:getBearerToken, gated on analytics opt-in.Built-in Infura endpoints only. The token goes on the primary endpoint of
infura-type network clients, the ones built frominfuraProjectId. Custom endpoints never carry it, even on aninfura.iohost: that is someone else's key. Failover endpoints never carry it: other providers. The gate is client type plus position in the chain, not URL matching, sorpcFailoverMode: 'forced'sends the token nowhere.Read per request. A refreshed token is used on the next request. If the function returns
undefinedor throws, the request is made without the header. In the wallet that covers the locked state (getBearerTokenthrows until unlock) and clients that do not registerAuthenticationController, such aswallet-cli.Analytics opt-in only. The token identifies the user, which is only allowed for analytics opt-ins. The wallet returns it only while
AnalyticsControllerstate hasoptedIn: true, otherwiseundefined.NetworkControllerstays policy-free: the option is the seam, and clients that construct the controller directly own the gate in their owngetInfuraAuthToken.Wallet wiring.
AuthenticationController:getBearerTokenis delegated to the network controller messenger, as it already is forShieldApiService,ClaimsService, andSubscriptionService, and passed throughgetInfuraAuthToken.AnalyticsController:getStatewas already delegated. No new instance option.@metamask/profile-sync-controlleris added as a dependency for the action type.Not supported: Infura-issued JWTs. Same header, mutually exclusive. MetaMask clients use v3 keys and the UI has no JWT input.
Open question: the extension's
FEATURED_RPCSnetworks (Linea, Base, ...) areRpcEndpointType.Customwith our project ID, so the type gate excludes them. Include them by also matching/v3/<infuraProjectId>, or keep the type gate?References
None.
Checklist
Note
Medium Risk
Changes outbound RPC auth on default Infura traffic and ties it to analytics opt-in and bearer retrieval; mis-gating could leak identifiers or break RPC when tokens fail.
Overview
Adds optional
getInfuraAuthTokenonNetworkController, threaded through auto-managed network clients into RPCfetch. AwithInfuraAuthTokenwrapper setsAuthorization: Bearer …once per request; missing or failed token lookup still sends the RPC without the header.The credential applies only to the primary endpoint of
infura-type clients (built frominfuraProjectId), not custom RPC URLs or failover endpoints—even on Infura hosts—so user keys are never paired with the MetaMask token.@metamask/walletwires the hook toAuthenticationController:getBearerTokenwhenAnalyticsControllerreportsoptedIn, delegates that action on the network messenger, and adds@metamask/profile-sync-controllerfor the action type. Tests cover bearer behavior, per-request refresh, endpoint scoping, and wallet opt-in gating.Reviewed by Cursor Bugbot for commit ef7260c. Bugbot is set up for automated code reviews on this repo. Configure here.