feat: Add support for using the messenger in preinstalled Snaps#4055
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4055 +/- ##
=======================================
Coverage 98.59% 98.59%
=======================================
Files 425 428 +3
Lines 12413 12484 +71
Branches 1969 1975 +6
=======================================
+ Hits 12238 12309 +71
Misses 175 175 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
endowment:messenger|
bugbot run |
| /** | ||
| * Caveat specifying the required messenger actions and events by a Snap. | ||
| */ | ||
| MessengerScopes = 'messengerScopes', |
There was a problem hiding this comment.
Open to suggestions for a better name here
| method: 'snap_messengerCall', | ||
| params: { action, params }, | ||
| }), | ||
| } as AsyncMessenger<Action>; |
There was a problem hiding this comment.
Type 'Promise<Json>' is not assignable to type 'Promise<Awaited<ExtractActionResponse<Action, ActionType>>>'.
Type 'Json' is not assignable to type 'Awaited<ExtractActionResponse<Action, ActionType>>'.
Type 'null' is not assignable to type 'Awaited<ExtractActionResponse<Action, ActionType>>'
There was a problem hiding this comment.
Maybe cast the return type rather than the whole object. Slightly cleaner imo.
There was a problem hiding this comment.
I couldn't find a clean way to do that in c8e95fb 🤔
|
@metamaskbot update-pr |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e07f47a. Configure here.
e07f47a to
61fb96e
Compare

Add support for using the messenger in preinstalled Snaps. To access the messenger a Snap must specify a list of actions in
endowment:messenger. Then, it can usegetMessengerto get a messenger object for use inside the Snap. The actions used must return JSON-serializable values.https://consensyssoftware.atlassian.net/browse/WPC-1021
Note
Medium Risk
Introduces a new path from Snap execution into client controller messengers; risk is mitigated by preinstall-only gating, manifest-scoped actions, and a blocklist of high-privilege controllers, but incorrect hook/delegation behavior could still widen access.
Overview
Adds
endowment:messengerso preinstalled Snaps can declare allowed controller actions via amessengerScopescaveat (manifest-validatedactionslist). Snap code uses SDKgetMessenger(), which forwardsmessenger.call(...)to the new permitted RPCsnap_messengerCall.The platform handler only exposes the method when the Snap is preinstalled and holds the messenger endowment; it builds a scoped messenger from a
getMessengerhook, rejects calls into a fixed set of sensitive controller namespaces, and returns JSON-serializable results.snaps-simulationwires the same hook by delegating declared actions to the root controller messenger.The preinstalled example Snap and test-snaps UI exercise
PhishingController:testOrigin; LavaMoat policies now allow@metamask/messengerthrough@metamask/snaps-sdk.Reviewed by Cursor Bugbot for commit 61fb96e. Bugbot is set up for automated code reviews on this repo. Configure here.