Skip to content

Conversation

@FrederikBolding
Copy link
Member

@FrederikBolding FrederikBolding commented Dec 11, 2025

Due to a bug in the mobile client, some users may have preinstalled Snaps with out-of-sync permissions (or no permissions at all). This PR implements mitigation that checks the permissions for every preinstalled Snap during initialization and re-grants / re-revokes any out-of-sync permissions.


Note

Validates and automatically restores out-of-sync permissions for preinstalled Snaps at init, updating subject metadata and adding targeted tests.

  • Snaps Controller:
    • After handling preinstalled snaps, validates each preinstalled snap’s expected permissions and calculates diffs.
    • Restores missing/extra permissions via PermissionController:grantPermissions/revokePermissions and refreshes metadata with SubjectMetadataController:addSubjectMetadata (icon recovered from preinstalled files when available).
    • Logs a warning and captures an exception when restoration occurs.
  • Tests:
    • Added recovery tests for out-of-sync preinstalled permissions (with and without icon).
    • Updated preinstalled snap tests to stub grantPermissions and adjusted expectations (call orders, lifecycle hooks indices).
    • Enhanced clearState flow tests to revoke all permissions and verify re-grant on reinstallation of preinstalled snaps.

Written by Cursor Bugbot for commit a37a0ce. This will update automatically on new commits. Configure here.

@codecov
Copy link

codecov bot commented Dec 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.29%. Comparing base (08cf90f) to head (a37a0ce).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3775      +/-   ##
==========================================
+ Coverage   98.28%   98.29%   +0.01%     
==========================================
  Files         420      420              
  Lines       12211    12232      +21     
  Branches     1889     1897       +8     
==========================================
+ Hits        12002    12024      +22     
+ Misses        209      208       -1     

☔ View full report in Codecov by Sentry.
📢 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 marked this pull request as ready for review December 12, 2025 09:11
@FrederikBolding FrederikBolding requested a review from a team as a code owner December 12, 2025 09:11
() => ({}),
);

rootMessenger.registerActionHandler(
Copy link
Member Author

Choose a reason for hiding this comment

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

Made changes to some tests that were improperly emulating the PermissionController and would cause the permissions re-sync when unnecessary

Mrtenz
Mrtenz previously approved these changes Dec 12, 2025
Mrtenz
Mrtenz previously approved these changes Dec 12, 2025
@FrederikBolding FrederikBolding added this pull request to the merge queue Dec 12, 2025
Merged via the queue into main with commit 7d0e247 Dec 12, 2025
121 checks passed
@FrederikBolding FrederikBolding deleted the fb/recover-preinstalled-permissions branch December 12, 2025 10:27
joaoloureirop pushed a commit to MetaMask/metamask-mobile that referenced this pull request Dec 12, 2025
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

Patch to bring in the changes from:
#23976 /
MetaMask/snaps#3775 to the RC, which fixes a
production issue preventing Snaps from executing properly due to a
persistence bug. The patch was created by building the main Snaps branch
locally and copying over the SnapController files.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Switches @metamask/snaps-controllers to a Yarn patch and updates
yarn.lock accordingly.
> 
> - **Dependencies**:
> - Switch `@metamask/[email protected]` to a Yarn patch
reference in `package.json`.
> - Update `yarn.lock` to resolve the patched package (new
entries/resolutions and checksums).
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
8a44c10. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: sethkfman <[email protected]>
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.

4 participants