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 wallet_revokePermissions RPC method #1889

Merged
merged 8 commits into from
Nov 21, 2023

Conversation

FrederikBolding
Copy link
Member

@FrederikBolding FrederikBolding commented Oct 23, 2023

Explanation

Adds a wallet_revokePermissions RPC method that can be used to revoke permissions that a subject has been granted in the PermissionController. This initial version does not support revoking caveats and will revoke the entire requested permission key.

References

Changelog

@metamask/permission-controller

  • Added: Added wallet_revokePermissions RPC method

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

jsonrpc: '2.0',
id: 1,
method: 'wallet_revokePermissions',
params: { snap_dialog: { caveats: [{ type: 'foo', value: 'bar' }] } },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does adding the caveats here only remove that particular caveat?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this implementation no, but the idea is that we can add that down the line without breaking the API.

So we allow passing in caveats now, but they are effectively ignored until we know how to handle them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the previous PR to extension used permissionController.updateCaveat, is there anything wrong with that approach? https://github.com/MetaMask/metamask-extension/pull/21216/files#diff-6fbff2cfe97ac01b77296ef2122c7e0a5b3ff6a84b584b4d1a87482f35eea3d6R3779

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it is a flawed approach. Caveat values can be arbitrary JSON and are not standardized: https://github.com/MetaMask/core/blob/main/packages/permission-controller/src/Caveat.ts#L31C19-L31C23

Therefore it is not safe to assume we can modify them in this way.

We need to standardize the caveat format (effectively allowing for caveat merging, easy removal etc) before we implement this. That would be the next iteration of this API, but we have yet to discuss making that change in the PermissionController.

jsonrpc: '2.0',
id: 1,
method: 'wallet_revokePermissions',
params: [],
Copy link
Contributor

@shanejonas shanejonas Nov 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldnt empty just revoke all permissions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems like it could be a bit confusing to me, but not sure

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the MIP says it should revoke all permissions. but that probably should say to revoke all per domain not all permissions.

https://github.com/MetaMask/metamask-improvement-proposals/pull/24/files#diff-b9e4917cc96e9807875c63b66f48695f929d4e346175ad78546148cc40404a01R52

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that is a dangerous API to expose by default. From my perspective a saner default is to have dapps specify the exact permissions they wish to revoke.

@FrederikBolding FrederikBolding marked this pull request as ready for review November 15, 2023 15:25
@FrederikBolding FrederikBolding requested a review from a team as a code owner November 15, 2023 15:25
shanejonas and others added 2 commits November 20, 2023 09:37
This changes the `revokePermissions` rpc method params to be by-position
similar to `requestPermissions`
Comment on lines 73 to 75
revokePermissionsForOrigin(
permissionKeys as NonEmptyArray<PermissionConstraint['parentCapability']>,
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need pass along origin here? Or will the hook have that context somehow?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Normally the hooks are bound to the requesting origin and thus not needed to be passed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh hmm looks like we pass it as an arg for many other hooks. see setNetworkClientIdForDomain and handleWatchAssetRequest for example

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@adonesky1 adonesky1 Nov 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah ok we can do that. We should go and use this pattern for the other handlers that need origin .

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on how the RPC method is implemented. The origin cannot currently be bound in a restricted RPC method handler for instance.

adonesky1
adonesky1 previously approved these changes Nov 20, 2023
Copy link
Contributor

@adonesky1 adonesky1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

adonesky1
adonesky1 previously approved these changes Nov 20, 2023
jiexi
jiexi previously approved these changes Nov 20, 2023
Mrtenz
Mrtenz previously approved these changes Nov 21, 2023
@FrederikBolding FrederikBolding merged commit 77a7e38 into main Nov 21, 2023
128 checks passed
@FrederikBolding FrederikBolding deleted the fb/wallet-revoke-permissions branch November 21, 2023 10:55
adonesky1 added a commit to MetaMask/metamask-extension that referenced this pull request Nov 23, 2023
## **Description**
This PR adds `wallet_revokePermissions` rpc method support that was
added in `permission-controller/rpc-methods` that went in this PR
MetaMask/core#1889.

All that is needed is to add the hook as the rpc-method gets
automatically added
[here](https://github.com/MetaMask/metamask-extension/blob/develop/app/scripts/lib/rpc-method-middleware/createMethodMiddleware.js#L13).

## **Related issues**

Fixes: MetaMask/MetaMask-planning#1681

## **Manual testing steps**

1. Go to this page
https://docs.metamask.io/wallet/reference/wallet_requestpermissions/
2. Hit `Send Request` to request permissions
3. Click Next, Click Connect
4. Go to this page
https://docs.metamask.io/wallet/reference/wallet_getpermissions/
5. Click `Send Request` to get the permissions
6. See that there is permissions
7. paste this in the console:
```js
await window.ethereum.request({
  "method": "wallet_revokePermissions",
  "params": [
    {
      "eth_accounts": {}
    }
  ]
});
```
8. Click `Send Request` to get the permissions
9. see that there is no permissions and they have been revoked.

## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've clearly explained what problem this PR is solving and how it
is solved.
- [x] I've linked related issues
- [x] I've included manual testing steps
- [x] I've included screenshots/recordings if applicable
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [ ] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [ ] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **Pre-merge reviewer checklist**

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: Alex Donesky <adonesky@gmail.com>
adonesky1 added a commit to MetaMask/metamask-extension that referenced this pull request Nov 23, 2023
This PR adds `wallet_revokePermissions` rpc method support that was
added in `permission-controller/rpc-methods` that went in this PR
MetaMask/core#1889.

All that is needed is to add the hook as the rpc-method gets
automatically added
[here](https://github.com/MetaMask/metamask-extension/blob/develop/app/scripts/lib/rpc-method-middleware/createMethodMiddleware.js#L13).

Fixes: MetaMask/MetaMask-planning#1681

1. Go to this page
https://docs.metamask.io/wallet/reference/wallet_requestpermissions/
2. Hit `Send Request` to request permissions
3. Click Next, Click Connect
4. Go to this page
https://docs.metamask.io/wallet/reference/wallet_getpermissions/
5. Click `Send Request` to get the permissions
6. See that there is permissions
7. paste this in the console:
```js
await window.ethereum.request({
  "method": "wallet_revokePermissions",
  "params": [
    {
      "eth_accounts": {}
    }
  ]
});
```
8. Click `Send Request` to get the permissions
9. see that there is no permissions and they have been revoked.

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've clearly explained what problem this PR is solving and how it
is solved.
- [x] I've linked related issues
- [x] I've included manual testing steps
- [x] I've included screenshots/recordings if applicable
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.
- [ ] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [ ] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

- [ ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [ ] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: Alex Donesky <adonesky@gmail.com>
adonesky1 added a commit to MetaMask/metamask-extension that referenced this pull request Nov 23, 2023
This PR adds `wallet_revokePermissions` rpc method support that was
added in `permission-controller/rpc-methods` that went in this PR
MetaMask/core#1889.

All that is needed is to add the hook as the rpc-method gets
automatically added
[here](https://github.com/MetaMask/metamask-extension/blob/develop/app/scripts/lib/rpc-method-middleware/createMethodMiddleware.js#L13).

---------

Co-authored-by: Alex Donesky <adonesky@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants