Skip to content

Loosen allowlist requirements #1672

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

Merged
merged 4 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/snaps-controllers/coverage.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"branches": 91.4,
"functions": 96.92,
"lines": 98,
"functions": 96.93,
"lines": 98.01,
"statements": 97.73
}
24 changes: 20 additions & 4 deletions packages/snaps-controllers/src/snaps/SnapController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,11 @@ describe('SnapController', () => {
);

expect(messenger.call).toHaveBeenNthCalledWith(2, 'SnapsRegistry:get', {
[MOCK_SNAP_ID]: { version: '1.0.0', checksum: DEFAULT_SNAP_SHASUM },
[MOCK_SNAP_ID]: {
version: '1.0.0',
checksum: DEFAULT_SNAP_SHASUM,
permissions: getSnapManifest().initialPermissions,
},
});

expect(messenger.call).toHaveBeenNthCalledWith(
Expand Down Expand Up @@ -769,11 +773,23 @@ describe('SnapController', () => {
});

it('throws an error if snap is not on allowlist and allowlisting is required', async () => {
const { manifest, sourceCode, svgIcon } =
await getMockSnapFilesWithUpdatedChecksum({
manifest: getSnapManifest({
initialPermissions: {
// eslint-disable-next-line @typescript-eslint/naming-convention
snap_getBip44Entropy: [{ coinType: 1 }],
},
}),
});

const controller = getSnapController(
getSnapControllerOptions({
featureFlags: { requireAllowlist: true },
detectSnapLocation: (_location, options) =>
new LoopbackLocation(options),
detectSnapLocation: loopbackDetect({
manifest: manifest.result,
files: [sourceCode, svgIcon as VirtualFile],
}),
}),
);

Expand All @@ -782,7 +798,7 @@ describe('SnapController', () => {
[MOCK_SNAP_ID]: { version: DEFAULT_REQUESTED_SNAP_VERSION },
}),
).rejects.toThrow(
'Failed to fetch snap "npm:@metamask/example-snap": The snap is not on the allowlist.',
'Cannot install version "1.0.0" of snap "npm:@metamask/example-snap": The snap is not on the allowlist.',
);

controller.destroy();
Expand Down
18 changes: 16 additions & 2 deletions packages/snaps-controllers/src/snaps/SnapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import type {
PersistedSnap,
Snap,
SnapManifest,
SnapPermissions,
SnapRpcHookArgs,
StatusContext,
StatusEvents,
Expand Down Expand Up @@ -103,6 +104,7 @@ import type {
TerminateSnapAction,
} from '../services';
import { fetchSnap, hasTimedOut, setDiff, withTimeout } from '../utils';
import { ALLOWED_PERMISSIONS } from './constants';
import {
getMaxRequestTimeCaveat,
handlerEndowments,
Expand Down Expand Up @@ -1193,7 +1195,10 @@ export class SnapController extends BaseController<
this.messagingSystem.publish(`${controllerName}:snapUnblocked`, snapId);
}

async #assertIsInstallAllowed(snapId: SnapId, snapInfo: SnapsRegistryInfo) {
async #assertIsInstallAllowed(
snapId: SnapId,
snapInfo: SnapsRegistryInfo & { permissions: SnapPermissions },
) {
const results = await this.messagingSystem.call('SnapsRegistry:get', {
[snapId]: snapInfo,
});
Expand All @@ -1206,8 +1211,15 @@ export class SnapController extends BaseController<
result.reason?.explanation ?? ''
}`,
);
} else if (
}

const isAllowlistingRequired = Object.keys(snapInfo.permissions).some(
(permission) => !ALLOWED_PERMISSIONS.includes(permission),
);

if (
this.#featureFlags.requireAllowlist &&
isAllowlistingRequired &&
result.status !== SnapsRegistryStatus.Verified
) {
throw new Error(
Expand Down Expand Up @@ -2190,6 +2202,7 @@ export class SnapController extends BaseController<
await this.#assertIsInstallAllowed(snapId, {
version: newVersion,
checksum: manifest.source.shasum,
permissions: manifest.initialPermissions,
});

const processedPermissions = processSnapPermissions(
Expand Down Expand Up @@ -2363,6 +2376,7 @@ export class SnapController extends BaseController<
await this.#assertIsInstallAllowed(snapId, {
version: manifest.version,
checksum: manifest.source.shasum,
permissions: manifest.initialPermissions,
});

return this.#set({
Expand Down
15 changes: 15 additions & 0 deletions packages/snaps-controllers/src/snaps/constants.ts
Copy link
Collaborator

Choose a reason for hiding this comment

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

🤩

Copy link
Member Author

Choose a reason for hiding this comment

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

It's happening! 🎉

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { SnapEndowments } from './endowments';

// These permissions are allowed without being on the allowlist.
export const ALLOWED_PERMISSIONS = Object.freeze([
'snap_dialog',
'snap_manageState',
'snap_notify',
'snap_getLocale',
SnapEndowments.Cronjob,
SnapEndowments.HomePage,
SnapEndowments.LifecycleHooks,
SnapEndowments.EthereumProvider,
SnapEndowments.TransactionInsight,
SnapEndowments.SignatureInsight,
]);