-
-
Notifications
You must be signed in to change notification settings - Fork 201
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
Narrow string
allowlists in RestrictedControllerMessenger
instances
#4031
Conversation
f9451ee
to
3ae1ebe
Compare
9896a15
to
9e156c0
Compare
…ions,events unions
…exported at package-level
9e156c0
to
53582b1
Compare
@@ -91,8 +91,7 @@ export type AccountsControllerActions = | |||
| AccountsControllerUpdateAccountsAction | |||
| AccountsControllerGetAccountByAddressAction | |||
| AccountsControllerGetSelectedAccountAction | |||
| AccountsControllerGetAccountAction | |||
| AllowedAccountsControllerActions; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't want allowlists to be included in the controller actions/events unions.
- This interferes with the type narrowing base-controller does to distinguish internal/external actions/events.
- This exposes allowlists externally since actions/events unions are exported at the package-level. We generally want allowlists to be scoped to its controller.
|
||
export type AccountsControllerEvents = | ||
| AccountsControllerChangeEvent | ||
| AccountsControllerSelectedAccountChangeEvent | ||
| AllowedAccountsControllerEvents; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AccountsControllerState, | ||
AccountsControllerGetStateAction, | ||
AccountsControllerSetSelectedAccountAction, | ||
AccountsControllerSetAccountNameAction, | ||
AccountsControllerListAccountsAction, | ||
AccountsControllerUpdateAccountsAction, | ||
AccountsControllerGetSelectedAccountAction, | ||
AccountsControllerGetAccountByAddressAction, | ||
AccountsControllerGetAccountAction, | ||
AccountsControllerActions, | ||
AccountsControllerChangeEvent, | ||
AccountsControllerSelectedAccountChangeEvent, | ||
AccountsControllerEvents, | ||
AccountsControllerMessenger, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- This is not a breaking change. The list includes all preexisting exports and excludes
Allowed{Actions,Events}
. Allowed{Actions,Events}
should be exported from the module so they're available for tests and other internal files, but they should not be exported at the package level.- We want to avoid wildcard exports in general: Forbid wildcard exports eslint-config#331
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One suggestion for the changelog, but the diff LGTM!
Failing transaction-controller tests introduced by #3827 are fixed by the following changes. Merging #4013 first should take care of this. diff --git a/packages/transaction-controller/src/TransactionControllerIntegration.test.ts b/packages/transaction-controller/src/TransactionControllerIntegration.test.ts
index 72c91fa44..23bd723fa 100644
--- a/packages/transaction-controller/src/TransactionControllerIntegration.test.ts
+++ b/packages/transaction-controller/src/TransactionControllerIntegration.test.ts
@@ -114,7 +114,11 @@ const setupController = async (
const unrestrictedMessenger: UnrestrictedControllerMessenger =
new ControllerMessenger();
const networkController = new NetworkController({
- messenger: unrestrictedMessenger.getRestricted({
+ messenger: unrestrictedMessenger.getRestricted<
+ 'NetworkController',
+ never,
+ never
+ >({
name: 'NetworkController',
}),
trackMetaMetricsEvent: () => {
@@ -129,7 +133,11 @@ const setupController = async (
assert(blockTracker, 'Provider must be available');
const approvalController = new ApprovalController({
- messenger: unrestrictedMessenger.getRestricted({
+ messenger: unrestrictedMessenger.getRestricted<
+ 'ApprovalController',
+ never,
+ never
+ >({
name: 'ApprovalController',
}),
showApprovalRequest: jest.fn(),
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
… when used with `unrestrictedMessenger` pattern - TODO: open ticket for more fundamental fix for this in `getRestricted` and `RestrictedControllerMessenger`
The Omitting the A temporary fix applied here is to pass in empty arrays into But |
Motivation
Some controllers have their allowed actions or events types for their
RestrictedControllerMessenger
set tostring
. This compromises allowlist security by enabling these controllers to gain unrestricted access to any external action or event.Explanation
Fixes all instances in core of
string
being used to defineRestrictedControllerMessenger
allowlists.Includes follow-up fixes to fix: accounts controller events and actions #4021.
References
string
allowlists inRestrictedControllerMessenger
instances #4019Changelog
@metamask/approval-controller
Fixed
ApprovalControllerMessenger
generic argumentsAllowedActions
,AllowedEvents
fromstring
tonever
.@metamask/keyring-controller
Fixed
KeyringControllerMessenger
generic argumentsAllowedActions
,AllowedEvents
fromstring
tonever
.@metamask/network-controller
Fixed
NetworkControllerMessenger
generic argumentsAllowedActions
,AllowedEvents
fromstring
tonever
.@metamask/permission-controller
Fixed
SideEffectMessenger
so that it's defined with aRestrictedControllerMessenger
that has access toPermissionController
allowed actions.Actions
generic parameter is widened to include thePermissionController
actions allowlist.AllowedActions
generic parameter is narrowed fromstring
to thePermissionController
actions allowlist.Checklist