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 revokePermissions method #24

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
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
129 changes: 129 additions & 0 deletions MIPs/mip-x.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
---
MIP: x
Title: Implement `wallet_revokePermissions` for Flexible Permission Revocation
Status: Review
Stability: n/a
discussions-to: https://github.com/MetaMask/metamask-improvement-proposals/discussions
Author(s): Julia Collins (@julesat22)
Type: Community
Created: 2023-10-06
---

## Summary
This proposal aims to add a new JSON-RPC method, `wallet_revokePermissions`, to MetaMask. This method is designed to offer a high degree of flexibility in managing permissions. Users can either revoke all permissions for a connected dApp or selectively revoke permissions for specific accounts linked to a given invoker. This streamlines the user experience by reducing the number of steps needed to manage permissions and disconnect from dApps, thereby aligning with traditional OAuth systems for enhanced user control and privacy.

## Motivation
The existing permission system lacks a streamlined way for users and dApps to manage and revoke permissions. This proposal aims to:

1. Streamline User Experience: Currently, disconnecting a dApp requires navigating through multiple UI layers. Implementing `wallet_revokePermissions` will simplify this process and align with user expectations.

2. Close an Ergonomic Gap: Being able to request permissions but not revoke them programmatically is inconsistent and poses challenges for developers. This proposal offers a holistic solution for permission management.

3. Developer Experience: Dapp developers currently might resort to mocking disconnect functionality, which is not a genuine revocation of permissions. `wallet_revokePermissions` allows for an authentic disconnect, enhancing security and user trust.

4. User Experience: Enabling users to have granular control over their permissions directly from within the dapp not only enhances UX but also aligns with best practices in data privacy and user agency.

By implementing wallet_revokePermissions, we achieve feature parity with traditional permission systems, offering a more robust, secure, and user-friendly environment.

# Usage Example
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would avoid usage examples upfront before defining the signature on line 68

```
// Request to revoke permissions for a single address (disconnect a user's account)
await window.ethereum.request({
"method": "wallet_revokePermissions",
"params": {
"permission": {
"caveatValue": [
"0x36Cad5E14C0a845500E0aDA68C642d254BE8d538"
],
"target": "eth_accounts",
"caveatType": "restrictReturnedAccounts"
}
}
});

// Request to revoke all permissions
await window.ethereum.request({
"method": "wallet_revokePermissions",
"params": {}
});
shanejonas marked this conversation as resolved.
Show resolved Hide resolved

```

In these examples, all parameters are optional, enabling the invoker to revoke all permissions by default. However, the proposal also supports revoking specific permissions. For instance, by specifying the id which is the identifier returned upon a successful `wallet_requestPermission` call, you can target individual permissions for revocation.

# Proposal

## Definitions
**Revoke**: To officially cancel or withdraw specific privileges, rights, or permissions. In the context of `wallet_revokePermissions`, revoking would entail nullifying the access granted to certain dApps or operations, such as account information retrieval via `eth_accounts`.

**Invoker**: This refers to the entity that initiates or "calls" a specific method or function. In the case of `wallet_revokePermissions`, the invoker might be the user or the user's wallet software that initiates the revocation of permissions for specific dApps.


## Proposal Specification
The `wallet_revokePermissions` method is proposed as a new JSON-RPC feature for MetaMask, aimed at giving users more granular control over permission management. With this method, users can either revoke all permissions associated with connected origins (dApps) or opt for a more targeted approach by specifying the target permission. For example, MetaMask can revoke permissions for a specific account address or for many addresses. Additionally, if all parameters are omitted, it triggers a full revocation of all permissions.

The updated method signature will be as follows:

```
await window.ethereum.request({
"method": "wallet_revokePermissions",
"params": {
"permission": {
"caveatValue": string[], // value of the caveat to be revoked from the target permission
"target": "eth_accounts" | "wallet_snap" | "snap_dialog" | "snap_notify" | "snap_manageState"
"caveatType": string // type of the caveat to update,
"id": string // id of permission to be revoked
}
}
});
```
Comment on lines +65 to +79
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could we include an example of an expected success response we'd return to the requester?

Copy link
Collaborator

Choose a reason for hiding this comment

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

this should probably be a Permission to be consistent

which looks like:
image

requestPermissions looks like it takes that as well with caveats: [] in this example:
image

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator

@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.

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


The proposed changes have been implemented in the following PR against the `MetaMask/api-specs` repo: https://github.com/MetaMask/api-specs/pull/145

## Caveats
The implementation of `wallet_revokePermissions` means more granular control over user permissions and, subsequently, more combinations of permissions that can be revoked. This increases the scope of testing to ensure that there are no edge cases that haven't been considered, or bugs.

## Implementation
The MetaMask team will be responsible for implementing the proposed changes to the `wallet_revokePermissions` method.

## Developer Adoption Considerations
1. Backward Compatibility: Dapps that currently manage permissions using custom logic will need to update their code to integrate this new method, however the method is backwards compatible.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Dapps that currently manage permissions using custom logic will need to update their code to integrate this new method

not sure what this refers to? Could you spell out what you mean here a bit more?


2. Ease of Adoption: This method has been designed with flexibility in mind, offering both broad and specific options for permission revocation. This dual capability greatly simplifies the adoption process for both users and dApp developers.
shanejonas marked this conversation as resolved.
Show resolved Hide resolved

## User Experience Considerations
shanejonas marked this conversation as resolved.
Show resolved Hide resolved

#### Enhancements:

Streamlining Disconnection: Reducing the number of clicks and steps needed to disconnect from a dApp, making the experience more user-friendly.

Consistency in Connection Management: Providing a disconnect feature directly within the dApp aligns with user expectations and creates a consistent experience.
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you elaborate on what you mean by consistent here? Consistent that the connect and disconnect can both be requested by the dapp?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Re: UX. Like on connect to a dapp, I would expect to have MetaMask notify me of disconnect. I would not necessarily trust that a dapp has disconnected itself just from the dapp ui itself


Improved User-Dapp Communication: Clear, in-app options for managing permissions improve user confidence and control.

User Empowerment: The proposed method aligns with best practices in data privacy, giving users the agency to manage their data and connections effectively.

Synchronized Actions and Security: Ensuring that the dApp is aware of a user's intent to disconnect prevents potential security loopholes and reflects the user’s action accurately in the dApp’s state.

## Security Considerations
The introduction of the `wallet_revokePermissions` method bolsters security by providing users with more control over permission revocation, reducing the potential attack surface. By allowing users to revoke permissions either partially or entirely, it minimizes the risk of unauthorized or malicious activity.

However, the security model depends on users actively managing these permissions, and there's a minor risk that poorly implemented dApps could confuse users about what they're revoking, potentially leading to unwanted outcomes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

what sorts of unwanted outcomes do you foresee?


To mitigate this risk, MetaMask could implement the following countermeasures:

**User Education**: MetaMask could inform users about the importance of managing permissions and the risks associated with not revoking outdated or unused permissions. Offer guidelines for making informed decisions about when and how to revoke permissions for different dApps.

**Warning and Consent**: Before executing a revoke operation, MetaMask could display an inormative alert message to users. This message could inform them of the consequences of revoking permissions and/or the specific permission(s) they are attempting to revoke.

## References
[wallet_revokePermissions](https://github.com/MetaMask/api-specs/pull/145)

## Feedback
Please provide feedback on this proposal by opening an issue in the MetaMask MIPs repository.

## Committed Developers
Julia Collins (@julesat22)

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