MetaMask / MetaMask/metamask-extension

Re-assess removing the clipboardWrite permission from manifest file

Open
#30,394 0 comments 1 reaction 1 assignee Claimed by @HowardBraham View on GitHub
for-migration INVALID-ISSUE-TEMPLATE team-extension-platform
Dominant language
TypeScript
Stars
13.2k
Forks
5.6k
Avg merge
2d 5h
Merged PRs (30d)
451

Description

### What is this about?

RAPID: https://docs.google.com/document/d/1Vd4D1I_ERUOY_9DOjiNMR54-QtK13uQSlFcxiK8E5Us

## Issue Context
Currently relying on the `clipboardWrite` permission does not pose any issues or causes any bugs. In fact it is the recommended way for extensions to interact with the clipboard. See MDN and Chrome documentation below:
* [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API)
* [Chrome](https://developer.chrome.com/docs/extensions/reference/permissions-list) - `Lets the extension cut and copy items to the clipboard using the web platform [Clipboard API](https://developer.mozilla.org/docs/Web/API/Clipboard_API).
Warning displayed: Modify data you copy and paste.`

The main reason to evaluate the usage of the `clipboardWrite` permission is the warning that Chrome presents the users (and adds to Extension details page - see image below) stating that the Extension will be able to `Modify data you copy and paste.`.
![Image](https://github.com/user-attachments/assets/c5c4e63a-0ee7-49e3-99bc-38d26c57f49d)

This has caused some users to overreact ([see this thread on X](https://x.com/ZunXBT/status/1879490825354363052)) and believe that they are trusting MetaMask to not access their clipboard (which would only be possible in the context of the Extension as the clipboard API is only available in secure contexts).
These over reactions are exacerbated because some popular Wallets like Rabby or Phantom do not require that permission (Rainbow does require the same permission). And although the main reason for these wallets to not require the same permission, is because they are relying on the old `documment.execCommand(copy)` command (which has been deprecated and should not be used anymore).

## Code Context
It seems that the `clipboardWrite` permssion was introduced a long long time ago for Opera support - https://github.com/MetaMask/metamask-extension/pull/700
After it we tried to [remove it once](https://github.com/MetaMask/metamask-extension/pull/6654), but ended up [reverting that change](https://github.com/MetaMask/metamask-extension/pull/6678).

We need it to use the navigator ClipboardAPI, but the [package](https://github.com/sudodoki/copy-to-clipboard/blob/main/index.js#L79) that we are using pretty much everywhere relies on the `execCommand('copy')`.
The only place (besides tests) where we are using the clipboard API is for clearing up the clipboard after SRP paste.

## Goal
Re-assess if the `clipboardWrite` permission is actually required or not.

As pointed out by @Gudahtt, MDN is suggests that for Firefox extensions this permission is only required if there is no transient activation - `Writing text is available in secure context and with transient activation. With the Web Extension [clipboardWrite](https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/permissions#clipboardwrite) permission transient activation is not required.`.
Although it does not specify how it does work for Chrome extensions and Chrome docs, posted above, just provide a generic explanation - `Lets the extension cut and copy items to the clipboard using the web platform [Clipboard API](https://developer.mozilla.org/docs/Web/API/Clipboard_API).`

Finally there are two actions that can be taken into improving the clipboard usage:
1. re-assess if we really need the `clipboardWrite` permission - lest test removing it and see if everything works as expected.
2. replace all `execCommand(`copy`)` by the clipboard API

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.