Skip to content

feat: Add support for using the messenger in preinstalled Snaps#4055

Merged
FrederikBolding merged 19 commits into
mainfrom
fb/messenger-endowment
Jul 6, 2026
Merged

feat: Add support for using the messenger in preinstalled Snaps#4055
FrederikBolding merged 19 commits into
mainfrom
fb/messenger-endowment

Conversation

@FrederikBolding

@FrederikBolding FrederikBolding commented Jun 30, 2026

Copy link
Copy Markdown
Member

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 use getMessenger to 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:messenger so preinstalled Snaps can declare allowed controller actions via a messengerScopes caveat (manifest-validated actions list). Snap code uses SDK getMessenger(), which forwards messenger.call(...) to the new permitted RPC snap_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 getMessenger hook, rejects calls into a fixed set of sensitive controller namespaces, and returns JSON-serializable results. snaps-simulation wires 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/messenger through @metamask/snaps-sdk.

Reviewed by Cursor Bugbot for commit 61fb96e. Bugbot is set up for automated code reviews on this repo. Configure here.

@codecov

codecov Bot commented Jun 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.59%. Comparing base (324299d) to head (61fb96e).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@FrederikBolding FrederikBolding changed the title feat: Add endowment:messenger feat: Add support for using the messenger in preinstalled Snaps Jul 1, 2026
@FrederikBolding

Copy link
Copy Markdown
Member Author

bugbot run

Comment thread packages/snaps-rpc-methods/src/permitted/messengerCall.ts
/**
* Caveat specifying the required messenger actions and events by a Snap.
*/
MessengerScopes = 'messengerScopes',

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Open to suggestions for a better name here

Comment thread packages/snaps-sdk/src/messenger.ts Outdated
Comment thread packages/snaps-sdk/src/messenger.ts Outdated
method: 'snap_messengerCall',
params: { action, params },
}),
} as AsyncMessenger<Action>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why does this need a type cast?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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>>'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe cast the return type rather than the whole object. Slightly cleaner imo.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I couldn't find a clean way to do that in c8e95fb 🤔

Comment thread packages/snaps-utils/src/manifest/validation.ts Outdated
Comment thread packages/snaps-sdk/src/messenger.ts Outdated
@FrederikBolding FrederikBolding requested a review from Mrtenz July 2, 2026 09:12
@FrederikBolding

Copy link
Copy Markdown
Member Author

@metamaskbot update-pr

@FrederikBolding FrederikBolding marked this pull request as ready for review July 2, 2026 12:18
@FrederikBolding FrederikBolding requested a review from a team as a code owner July 2, 2026 12:18
Comment thread packages/snaps-rpc-methods/src/permitted/messengerCall.ts
Mrtenz
Mrtenz previously approved these changes Jul 3, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

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

Comment thread packages/snaps-utils/src/manifest/validation.ts
@FrederikBolding FrederikBolding force-pushed the fb/messenger-endowment branch from e07f47a to 61fb96e Compare July 3, 2026 09:03
@FrederikBolding FrederikBolding added this pull request to the merge queue Jul 6, 2026
Merged via the queue into main with commit 7db53bc Jul 6, 2026
132 checks passed
@FrederikBolding FrederikBolding deleted the fb/messenger-endowment branch July 6, 2026 12:10
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.

3 participants