Skip to content
This repository has been archived by the owner on Oct 7, 2024. It is now read-only.

fix: reject unsupported account methods #190

Merged
merged 5 commits into from
Dec 18, 2023

Conversation

k-g-j
Copy link
Contributor

@k-g-j k-g-j commented Dec 15, 2023

Current state: When you update an account and remove a method, the removed method still functions
Solution: Check if an account supports the method when a request is submitted to the Keyring and if not, throw an error.

Manual Testing

  1. Go to the SSK and create an account
  2. Updated the account using this JSON, replacing the address and ID fields with the new account information, and choose one or more of the methods to remove from the list
{
    "address": "you new account address",
    "id": "your new account ID",
    "options": {},
    "methods": [
        "personal_sign",
        "eth_sign",
        "eth_signTransaction",
        "eth_signTypedData_v1",
        "eth_signTypedData_v3",
        "eth_signTypedData_v4"
    ],
    "type": "eip155:eoa"
}
  1. Navigate to the E2E Test Dapp and connect the new account
  2. Attempt to perform a method you just removed
  3. You should see a message that "Method [removed method] is not supported for account [new snap account address]"

Jest

jest src/SnapKeyring.test.ts --testNamePattern="fails when the EthMethod is not supported"
jest src/SnapKeyring.test.ts

Copy link
Contributor

@danroc danroc left a comment

Choose a reason for hiding this comment

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

LGTM!

image

Can you just replace Fix/ with fix: in the PR title, please? (conventional commit)

@owencraston owencraston changed the title Fix/reject unsupported account methods fix: reject unsupported account methods Dec 18, 2023
@owencraston owencraston marked this pull request as ready for review December 18, 2023 16:35
@owencraston owencraston requested a review from a team as a code owner December 18, 2023 16:35
Copy link
Contributor

@owencraston owencraston left a comment

Choose a reason for hiding this comment

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

Tested with this PR on extension and it worked as expected.

Screenshot 2023-12-18 at 11 34 02 AM Screenshot 2023-12-18 at 11 35 06 AM

@k-g-j k-g-j added this pull request to the merge queue Dec 18, 2023
Merged via the queue into main with commit 7ef8c33 Dec 18, 2023
17 checks passed
@k-g-j k-g-j deleted the fix/reject-unsupported-account-methods branch December 18, 2023 16:41
owencraston added a commit to MetaMask/metamask-extension that referenced this pull request Dec 19, 2023
## **Description**

<!--
Write a short description of the changes included in this pull request,
also include relevant motivation and context. Have in mind the following
questions:
1. What is the reason for the change?
2. What is the improvement/solution?
-->

Includes the latest fixes in the eth-snap-keyring. This blocks non
permitted methods from being called by an account snap. The changes in
the eth-snap-keyring can be found
[here](MetaMask/eth-snap-keyring#190).

## **Related issues**

Fixes: MetaMask/accounts-planning#181
Fixes: MetaMask/accounts-planning#121

## **Screenshots/Recordings**

<img width="354" alt="Screenshot 2023-12-18 at 3 41 18 PM"
src="https://github.com/MetaMask/metamask-extension/assets/22918444/9bdcdd6b-a283-4b9c-be23-359fe96a90e7">


<img width="586" alt="Screenshot 2023-12-18 at 3 40 36 PM"
src="https://github.com/MetaMask/metamask-extension/assets/22918444/35841117-4451-4933-baf4-502cf5919764">


## **Manual testing steps**


1. Go to the
[SSK](https://metamask.github.io/snap-simple-keyring/latest/) and create
an account
2. Updated the account using this JSON, replacing the address and ID
fields with the new account information, and choose one or more of the
methods to remove from the list
```json
{
    "address": "you new account address",
    "id": "your new account ID",
    "options": {},
    "methods": [
        "personal_sign",
        "eth_sign",
        "eth_signTransaction",
        "eth_signTypedData_v1",
        "eth_signTypedData_v3",
        "eth_signTypedData_v4"
    ],
    "type": "eip155:eoa"
}
```
3. Navigate to the [E2E Test
Dapp](https://metamask.github.io/test-dapp/) and connect the new account
4. Attempt to perform a method you just removed
5. You should see a message that "Method [removed method] is not
supported for account [new snap account address]"


### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **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.
- [x] I’ve properly set the pull request status:
  - [x] 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**

- [x] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [x] 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: MetaMask Bot <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants