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

fix: Fix/1723 add permission middleware #9521

Merged
merged 32 commits into from
May 7, 2024
Merged

Conversation

Cal-L
Copy link
Contributor

@Cal-L Cal-L commented May 3, 2024

Description

This PR changes the following:

  • Adds the missing permission middleware to the JsonRpcEngine stack. All RPC methods will now be validated by the PermissionController before it can reach the RPCMethodMiddleware (user facing RPC method handlers)
  • Removes metadata from the permitted accounts in the PermissionController subject state. The result returned by eth_accounts handler should contain a list of permitted addresses. A migration is included in the changes to migrate the data.

Related issues

Fixes:

#9492 & #1723

Manual testing steps

PermissionController state should be successfully migrated

  • GIVEN I have a previous version of the app installed
  • AND I have accounts 1 and 2 connected to uniswap.org
  • AND Account 1 is active on the dapp
  • WHEN I upgrade the app to the version with this PR's changes
  • AND I log in, access the browser tab, see uniswap tab opened
  • THEN I should see accounts 1 and 2 are connected with Account 1 being active
  • AND I should be able to freely connect or disconnect accounts without any issues

Un-permitted restricted RPC method should be blocked by permission middleware

  • GIVEN I have no accounts connected to the dapp metamask.github.io/test-dapp
  • WHEN I tap ETH_ACCOUNTS button
  • THEN I should see an unauthorized error

Permitted restricted RPC method should be allowed by permission middleware

  • GIVEN I have no accounts connected to the dapp metamask.github.io/test-dapp
  • AND I connect Account 1 to the dapp
  • WHEN I tap ETH_ACCOUNTS button
  • THEN I should see my active+permitted account address

WC should still work and be able to trigger transaction

  • GIVEN I select WC option from uniswap.org
  • AND I use the QR reader to scan
  • THEN I should receive the connect account prompt
  • WHEN my account is connected the the dapp
  • THEN I submit a transaction in the dapp
  • THEN I should see the transaction prompt in the mobile app

Screenshots/Recordings

Before

After

When upgrading with PermissionController state migration

upgrade.mov

When calling restricted+un-permitted RPC method

unauthorized.mov

When calling restricted+permitted RPC method

authorized.mov

Interaction using WC to connect and prompt transaction

RPReplay_Final1714770943.MP4

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've completed the PR template to the best of my ability
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.

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.

@Cal-L Cal-L requested a review from a team as a code owner May 3, 2024 05:57
Copy link
Contributor

github-actions bot commented May 3, 2024

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

Copy link

sentry-io bot commented May 3, 2024

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: app/core/Permissions/specifications.js

Function Unhandled Issue
validateCaveatAccounts Error: eth_accounts error: Received unrecognized address: "".** accounts.forEach$argument_0(app/core/Permissions/...
Event Count: 14 Affected Users: 11

Did you find this useful? React with a 👍 or 👎

@Cal-L Cal-L added team-mobile-platform needs-qa Any New Features that needs a full manual QA prior to being added to a release. Run Smoke E2E Triggers smoke e2e on Bitrise needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) labels May 3, 2024
Copy link
Contributor

github-actions bot commented May 3, 2024

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 316fd36
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/d9c5e7eb-0e71-4736-9b46-5e9d8b36f1ad

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@Cal-L Cal-L added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels May 3, 2024
Copy link
Contributor

github-actions bot commented May 3, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 26b28cb
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/dc6fa483-60c7-4d86-a1a9-6ec08160e3c9

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@Cal-L Cal-L added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels May 3, 2024
@Cal-L Cal-L added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels May 3, 2024
Copy link
Contributor

github-actions bot commented May 3, 2024

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 367eb4f
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/302a93c7-7a7f-48b9-94de-b19b6e95db0d

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@rekmarks rekmarks self-requested a review May 5, 2024 00:59
app/util/general/index.js Show resolved Hide resolved
app/util/general/index.js Outdated Show resolved Hide resolved
app/util/general/index.js Outdated Show resolved Hide resolved
app/util/general/index.test.ts Outdated Show resolved Hide resolved
app/util/general/index.js Outdated Show resolved Hide resolved
app/core/Permissions/index.ts Outdated Show resolved Hide resolved
app/core/Permissions/specifications.js Outdated Show resolved Hide resolved
@Cal-L Cal-L added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels May 7, 2024
Copy link
Contributor

github-actions bot commented May 7, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: ae2ecab
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/508144f5-cc96-4b5c-af9b-35c5016b3511

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link

sonarcloud bot commented May 7, 2024

@Cal-L
Copy link
Contributor Author

Cal-L commented May 7, 2024

Also successfully pr_regression_e2e_pipeline - https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/08cea1fe-b7be-4331-9d83-47fcb67b7934

@Cal-L
Copy link
Contributor Author

Cal-L commented May 7, 2024

E2E passed from non-JSdoc change

@christopherferreira9
Copy link
Contributor

SDK & WC remain untouched ✅

@Cal-L Cal-L added No QA Needed Apply this label when your PR does not need any QA effort. and removed needs-qa Any New Features that needs a full manual QA prior to being added to a release. labels May 7, 2024
@Cal-L Cal-L merged commit 58c9145 into main May 7, 2024
33 of 35 checks passed
@Cal-L Cal-L deleted the fix/1723-add-permission-middleware branch May 7, 2024 21:18
@github-actions github-actions bot locked and limited conversation to collaborators May 7, 2024
@github-actions github-actions bot removed the needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) label May 7, 2024
@metamaskbot metamaskbot added the release-7.23.0 Issue or pull request that will be included in release 7.23.0 label May 7, 2024
@cortisiko cortisiko added QA Passed A successful QA run through has been done and removed No QA Needed Apply this label when your PR does not need any QA effort. labels May 7, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
QA Passed A successful QA run through has been done release-7.23.0 Issue or pull request that will be included in release 7.23.0 Run Smoke E2E Triggers smoke e2e on Bitrise team-mobile-platform
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

6 participants