EIP-5593 Restricting access to the Ethereum provider (Restrict Ethereum Provider API Injection)
No call decision · Security & privacy · EIP status Stagnant · created 2022-09-05
A guideline requiring wallets to expose the Ethereum provider API, such as window.ethereum, only in a secure context like HTTPS and from first-party origins, in order to prevent attacks and fingerprinting via third-party iframes.
Why it is needed
Provider objects such as window.ethereum, injected by wallet extensions, are powerful APIs that can access user funds and sensitive data. Until now, however, this API could be injected equally into HTTP pages and even into third-party advertising iframes hidden inside otherwise legitimate dApps. An attack was actually possible in which a malicious ad accessed the wallet from within a dApp frame and requested that the user move funds. Moreover, if the provider object is exposed by default on every page, it can also be used as a means of fingerprinting which visitors are using a Web3 wallet. This document proposes applying the same secure context rules that the web platform applies to powerful APIs like the geolocation API to the Ethereum provider as well.
What changes
Today
- window.ethereum can be injected even on HTTP sites
- The provider can be exposed to third-party iframes (such as ads) as well
- In some cases it gets injected regardless of whether the sandbox attribute is set
- The mere presence of the provider can be used to fingerprint Web3 users
After EIP-5593
- window.ethereum is injected only from trustworthy origins such as HTTPS or HTTP localhost
- The provider is not injected into third-party iframes by default, but exceptions can be requested via the allow attribute and the Permissions API
- A first-party iframe with the sandbox attribute is blocked unless allow-same-origin is present
- A localhost-only developer mode toggle is allowed, defaulting to off
Who is affected
- Wallet users: The risk of unauthorized fund-request attacks via malicious ads or third-party frames is reduced.
- Wallet (extension) developers: Must implement window.isSecureContext checks, first-party/third-party iframe detection, and sandbox attribute handling logic.
- dApp developers: When developing locally over HTTP localhost, if the user agent does not treat it as a secure context, a developer mode toggle may be needed.
- Operators of third-party iframes, such as ad networks: Access to the provider API is blocked by default.
In depth
Secure context requirements
The provider object is accessible only when the origin is a potentially trustworthy origin as defined in section 3.1 of the W3C Secure Contexts specification. This includes sites served over HTTPS and HTTP localhost. This can be checked with window.isSecureContext, and the same applies inside iframes. Per section 7.2 (Development Environments) of the Secure Contexts specification, a user agent may support a feature allowing users to designate additional trusted origins via settings. For example, Chromium-based browsers support this via the chrome://flags/#unsafely-treat-insecure-origin-as-secure flag.
Third-party iframes blocked by default
The spec stipulates that by default, the Ethereum Provider API MUST NOT be exposed to third-party iframes. If an iframe is third-party relative to the top-level security origin, it SHOULD be blocked, though some implementations MAY provide a mechanism that allows access after user approval via the allow attribute and the Permissions API.
Handling the sandbox attribute
If an iframe is first-party with the top-level origin but has the sandbox attribute set, the provider object MUST be blocked. However, it MUST be injected into a first-party iframe set with sandbox="allow-same-origin". Note that allow-same-origin has no effect on third-party iframes, which remain blocked by default regardless.
Private windows are exempt
The provider object MAY be accessible in private (incognito) windows. In other words, private browsing mode itself is not included among the mandatory blocking targets of this EIP.
Developer mode toggle
For cases where the User Agent does not treat localhost as a secure context, wallet extensions SHOULD consider a developer mode toggle UX that disables the secure context check specifically for http://localhost:<any-port> origins. This toggle MUST be disabled by default. The authors note that the major User Agents they tested already treat localhost as a secure context.
Criteria shown by the test cases
The spec lays out required test cases for combinations of top-level document and iframe. For example, within a top-level https://a.com, an iframe with src=https://a.com is allowed, an iframe with src=https://b.com is blocked as third-party, and an iframe with src=https://sub.a.com is also treated as third-party (being a subdomain) and blocked. Top-level documents with the data:// or file:// scheme are also blocked since they are not secure contexts.
Privacy considerations: fingerprinting
The very practice of injecting the provider object into every page by default risks becoming a means of fingerprinting users more precisely as web3 users. Implementers of this EIP are told to weigh the privacy implications of default injection.
Status and scope limitations
This document's status is Stagnant, meaning it is not actively progressing toward final approval. The authors note that EIP-1 editorial policy prevented them from directly linking specs such as the W3C's Secure Contexts, so they spelled out the explanation inline in the body, and said they would add the link once the policy becomes clear. The provided call records contain no fork-inclusion decision.