Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add EIP-5593: Restrict Web3 Provider Object API Injection #5593

Merged
merged 40 commits into from
Nov 14, 2022
Merged
Changes from 38 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0ab7f0a
add Restrict Web3 Provider Object API Injection
kdenhartog Sep 4, 2022
e44ff77
rename to EIP using PR number
kdenhartog Sep 4, 2022
7dea81e
add required EIP 1193
kdenhartog Sep 4, 2022
2d9f7c3
Update EIPS/eip-5593.md
kdenhartog Sep 5, 2022
fdfa3bc
Update EIPS/eip-5593.md
kdenhartog Sep 5, 2022
a8abbac
Update EIPS/eip-5593.md
kdenhartog Sep 5, 2022
bcf098f
Update EIPS/eip-5593.md
kdenhartog Sep 5, 2022
3ee56cb
Update EIPS/eip-5593.md
kdenhartog Sep 5, 2022
df4c5f1
Delete duplicate file
Pandapip1 Sep 6, 2022
1cdd846
Create W3 license
Pandapip1 Sep 6, 2022
19343cc
Create Media Capture and Streams.pdf
Pandapip1 Sep 6, 2022
1516510
That failed
Pandapip1 Sep 6, 2022
48e3fcc
add optional allow attribute usage for 3P iframes
kdenhartog Sep 7, 2022
b4026c2
update normative restrictions for provider objects
kdenhartog Sep 16, 2022
862c067
update test cases with better descriptions
kdenhartog Sep 16, 2022
b455cda
update link to normative definition of potentially trustworthy origin
kdenhartog Sep 18, 2022
cd97064
address subdomain test case
kdenhartog Sep 23, 2022
6ae031c
update abstract and motivation for readability and to cite a specific…
kdenhartog Sep 23, 2022
07b734f
modify normative statement about private tab usage
kdenhartog Sep 23, 2022
ab74f39
rename EIP to better reference EIP-1193 terminology
kdenhartog Sep 23, 2022
d68f2a1
update links to use anchor links
kdenhartog Sep 23, 2022
7e2876c
add @thypon as an author who contributed to intial review and impleme…
kdenhartog Sep 28, 2022
784f441
edit language to clarify when to inject ETH Provider
kdenhartog Sep 28, 2022
110b00f
update links to use markdown reference links
kdenhartog Oct 19, 2022
f7a18e3
update 3p suborigin iframe case to accurately reflect implementation
kdenhartog Oct 21, 2022
7598031
remove optional test cases
kdenhartog Oct 25, 2022
c113224
add privacy considerations section
kdenhartog Oct 25, 2022
2626ccb
editorial update about configuring potentially trustworthy origins
kdenhartog Oct 25, 2022
1c7fffb
rename 3P to third-party
kdenhartog Oct 25, 2022
4490e7b
change CAIP to EIP text
kdenhartog Oct 25, 2022
f40bcfa
remove external links
kdenhartog Nov 3, 2022
e543bc3
add authors note about linking issue
kdenhartog Nov 3, 2022
fb7bddb
add links to Github PRs about reference implementations
kdenhartog Nov 3, 2022
0d1a920
editorial updates
kdenhartog Nov 3, 2022
d6b44ea
address dictator eipw bot's commands
kdenhartog Nov 3, 2022
7809aef
remove assets folder for EIP-5593
kdenhartog Nov 3, 2022
d5696d2
Move privacy considerations to subheading of security considerations,…
Pandapip1 Nov 8, 2022
4f41f68
Oops, fix order
Pandapip1 Nov 8, 2022
7efe6c5
Fix false positive
Pandapip1 Nov 13, 2022
ab86d47
remove reference implementation links
kdenhartog Nov 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions EIPS/eip-5593.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
---
eip: 5593
title: Restrict Ethereum Provider API Injection
description: Wallet guidance for restricting Ethereum Provider API access to secure contexts for improved privacy and security for wallet users.
author: Yan Zhu (@diracdeltas), Brian R. Bondy (@bbondy), Andrea Brancaleoni (@thypon), Kyle Den Hartog (@kdenhartog)
discussions-to: https://ethereum-magicians.org/t/rfc-limiting-provider-object-injection-to-secure-contexts/10670
status: Draft
type: Standards Track
category: Interface
created: 2022-09-05
requires: 1193
---

## Abstract

Historically the web platform has had a notion of “powerful” APIs like those defined in W3C's Geolocation specification and W3C's Mediastreams specification, which are subject to additional security restrictions such as those defined by W3C's secure contexts specification. Since the Ethereum Provider APIs allow dApp websites to request access to sensitive user data and to request use of user funds, new Ethereum Provider APIs generally should align to the security considerations defined by W3C's Secure Context specification in order to better protect the users data and users funds managed via the web.

### Author's Note

Unfortunately, because of a difference in interpretations by EIP editors of RFC 2119 terminology around linking in [EIP-1](./eip-1.md), the authors cannot directly link to other W3C specifications which this EIP builds upon. The author's attempted to provide as much context as possible within the text while complying with the editor bot in order to get this merged. If this policy is updated or further clarified before this EIP reaches final call in the future this EIP will be updated with links.

## Motivation

Wallets are oftentimes maintaining security and safety of users' funds that can be equivalent to large portions of money. For this reason, it's a good idea to restrict access to the Ethereum Provider APIs to align it with other powerful APIs on the web platform. This will assist in reducing the surface area that attacks can be conducted to access users funds or data. Additionally, by adding in restrictions we're reducing the surface area that malicious web pages could fingerprint the user via the Ethereum Provider APIs providing some additional privacy benefits. An example of a specific attack that's avoided by this is one where a malicious advertisement is loaded on a legitimate dApp that attempts to interact with a users wallet to maliciously request the user to access funds. With this EIP implemented the advertisement frame would be considered a third-party iframe and therefore would not have the Ethereum Provider API injected into it's sub frame because it's not a secure context.

## Specification

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.

### Restrictions for providers

The provider objects, e.g. `window.ethereum`, are expected to only inject the Ethereum Provider APIs in secure context when conforming with this specification. The following restrictions are REQUIRED for conformant wallets:

- Provider objects MAY be accessible in private (incognito) windows.
- The origin MUST be a "potentially trustworthy origin" (defined in W3C's Secure Contexts specification in section 3.1) to have access to `window.ethereum`. This can be checked using `window.isSecureContext`, including inside iframes.
- Secure contexts include sites that are served from HTTPS but also HTTP `localhost`.
- The User Agent implementation MAY also support configured [potentially trustworthy origins] that would normally not be considered trustworthy if the user configures their User Agent to do so. See section 7.2 titled "Development Environments" of W3C's Secure Contexts specification for additional details. For example, in Chromium based User Agents this is done via the `chrome://flags/#unsafely-treat-insecure-origin-as-secure` flag.
- By default the Ethereum Provider APIs MUST NOT be exposed to third-party iframes.
- `window.ethereum` MUST be `undefined` in an iframe where `window.isSecureContext` returns `false` in that iframe.
- If the iframe is a third party to the top-level secure origin, it SHOULD be blocked.
- If the iframe is first-party to the top-level origin AND the `sandbox` attribute is set on the iframe, the provider object MUST be blocked. If the `sandbox` attribute is set to `sandbox="allow-same-origin"` it MUST be injected for a first party frame.
- Note `"allow-same-origin"` does nothing if the iframe is third-party. The case of the third party iframe is dictated by the usage of the `allow` attribute and the Permissions API as defined in the rule above.

## Rationale

By limiting the capabilities of where the Ethereum Provider APIs are being injected we can reduce the surface area of where attacks can be executed. Given the sensitivity of data that's passed to the Ethereum Provider APIs some basic levels of authentication and confidentiality should be met in order to ensure that request data is not being intercepted or tampered with. While there have been attempts to [limit request access via the wallet](./eip-2255.md) interface itself, there have not been limitations that have been set to where these Ethereum Provider APIs are expected to be or not be injected. Since the secure contexts web platform API is a well developed boundary that's been recommended by W3C and the fact that the Ethereum Provider APIs are extending the traditional web platform APIs, no other alternative solutions have been considered in order to extend current established prior art.


## Backwards Compatibility

Wallet extensions SHOULD consider adding a "developer mode" toggle via a UX so that dApp developers have the capability to disable the insecure context (http) check for the `http://localhost:<any-port>` origin only in the event that localhost does not return `true` for secure context. See section 5.2 of W3C's Secure Context specification for more details. This will allow dApp developers to be able to continue to host dApps on the localhost origin if a User Agent has chosen to not already consider localhost a secure context. All major User Agent implementations tested do consider localhost a secure context already. This toggle MUST be set to disabled by default.

## Test Cases

### Required Test Cases

- Top level `http://a.com` -> blocked (insecure/top level)
- Top level `https://a.com` -> allowed
- Top level `https://a.com` with `<iframe src="http://a.com/">` -> blocked (insecure first party iframe)
- Top level `http://a.com` with `<iframe src="https://a.com/">` -> blocked (insecure top level window)
- Top level `https://a.com` with `<iframe src="https://a.com">` -> allowed
- Top level `https://a.com` with `<iframe src="https://b.com">` -> blocked (third-party iframe without sufficient privileges)
- Top level `https://b.com` with `<iframe src="http://a.com/">` with `<iframe src="https://b.com">` -> blocked (insecure iframe)
- Top level `https://b.com` with `<iframe src="https://a.com">` with `<iframe src="https://b.com">` -> blocked (third-party iframe without sufficient privileges)
- Top level `https://a.com` with `<iframe src="https://sub.a.com">` -> blocked (third-party iframe without sufficient privileges)
- Top level `https://a.com` with `<iframe src="https://a.com" sandbox>` -> blocked (sandbox attribuute without "allow-same-origin")
- Top level `https://a.com` with `<iframe src="https://a.com" sandbox="allow-same-origin allow-scripts">` -> allowed (Note this case is discouraged by User Agent implementer's such as Mozilla's MDN documents because it’d allow the iframe to remove its own `sandbox` attribute. See the `sandbox` attribute section of the iframes document in MDN for more details.)
- Top level `data://foo with <iframe src="data://bar">` -> blocked (insecure top level scheme)
- Top level `file://foo with <iframe src="file://bar">` -> blocked (third-party iframe)
- Top level `https://a.com` with `<iframe src="https://b.com" sandbox="allow-same-origin allow-scripts">` -> blocked (third-party iframe without sufficient privileges)

## Reference Implementation

Brave Wallet desktop and Android implementation: https://github.com/brave/brave-core/pull/13739
Brave Wallet iOS implementation: https://github.com/brave/brave-ios/pull/5522/
Metamask implementation: https://github.com/MetaMask/metamask-extension/pull/15736
kdenhartog marked this conversation as resolved.
Show resolved Hide resolved

## Security Considerations

### User Enables Developer Mode

Oftentimes developers require the ability to develop dApps locally in order to test their website and develop while hosting their dApp on http://localhost. In this case localhost would be blocked and compatibility issues would arise when developing a dApp locally. In order to increase compatibility for dApp developers a toggle to disable the check for the localhost can be considered. If this were to be extended beyond the localhost origin it could be used as a means to convince users to enable developer mode in order to subvert the guards put in place by this EIP. Therefore, implementations should be cautious when extending this developer toggle beyond the scope of the localhost origin.
kdenhartog marked this conversation as resolved.
Show resolved Hide resolved

### Privacy Considerations

#### Web3 Provider Fingerprinting

Due to the nature of how the provider object is injected by default into most webpages, there's a risk that a malicious web page could utilize the provider object to fingerprint the user more precisely as a Web3 user. Implementers of this EIP are expected to consider the risks of injecting the Ethereum provider APIs into pages by default in order to consider what privacy characteristics they wish to enable for their users.

## Copyright

Copyright and related rights waived via [CC0](../LICENSE.md).