-
-
Notifications
You must be signed in to change notification settings - Fork 208
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
Add restricted controller messenger #378
Conversation
|
159d49e
to
756e986
Compare
30751bd
to
d5cb725
Compare
My objective with this restricted messaging system was to prevent accidental use of methods beyond the intended access. I'm not protecting against access to private methods/properties, or anything sneaky like that. We have lint rules and types to protect against us doing that. This approach isn't adequate for dealing with untrusted code. I don't think we'll be using the controller messaging system for untrusted code though - at least not directly. The snaps API will likely use the messaging system, but it will use other means to prevent unintended access (e.g. an RPC layer, SES, the permission system, etc.). |
d5cb725
to
4433aa7
Compare
756e986
to
5202621
Compare
993d382
to
53cc024
Compare
4a885cc
to
626fd07
Compare
} | ||
} | ||
|
||
it('should allow messaging between controllers', () => { |
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 the most complete example so far. It demonstrates calling an action and subscribing to an event in another controller.
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.
I think I love it. 😍
c4fb8f4
to
c267a31
Compare
e8cb578
to
e7bb905
Compare
c267a31
to
1671284
Compare
e7bb905
to
a97dfe4
Compare
a97dfe4
to
be56e2b
Compare
99cd49d
to
2e7b0b6
Compare
94d73b9
to
e660361
Compare
d387679
to
47e0cab
Compare
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.
A bunch of nits, but overall I think this rules.
} | ||
} | ||
|
||
it('should allow messaging between controllers', () => { |
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.
I think I love it. 😍
A method has been added to the controller messenger that returns a _restricted_ instance of the controller messenger. This instance is restricted to registering actions and events within a particular namespace, typically being the name of the controller. Access to event subscriptions and calling actions is also restricted based on the given allowlist for each. This is meant to address feedback left on the Controller Messaging System proposal[1]. [1]: https://www.notion.so/Controller-Messaging-System-617efb02b9e54bd0a0b0e44c6f776d85
The parameters for `getRestricted` were moved into an object, to improve readability.
The "controllerName" option has been renamed to "name", so as to not assume that the name is of a controller.
All methods now have corresponding JSDoc comments.
Previously the Base Controller would not accept any action types, and it would only accept the single action it used. Now it accepts any types, so long as the required type is present.
There is now a unit test that demonstrates inter-controller communication using the controller messaging system. This is a Base Controller test because it's also testing the Base Controller's messenger integration at the same time.
This requirement was added recently in #422
Comments have been added alongside each `istanbul ignore if` statement explaining why it was required.
47e0cab
to
d25bb8e
Compare
The new tests cover restricted messenger instances with access to both internal and external events and actions.
d25bb8e
to
d028d1b
Compare
This has been rebased, and all comments have been addressed. |
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.
Let's gooo!
- Add restricted controller messenger ([#378](#378)) - **BREAKING:** Update minimum Node.js version to v12 ([#441](#441)) - **BREAKING:** Replace controller context ([#387](#387)) - Bump @metamask/contract-metadata from 1.23.0 to 1.24.0 ([#440](#440)) - Update lint rules ([#442](#442), [#426](#426)) - Don't remove collectibles during auto detection ([#439](#439))
A method has been added to the controller messenger that returns a _restricted_ instance of the controller messenger. This instance is restricted to registering actions and events within a particular namespace, typically being the name of the controller. Access to event subscriptions and calling actions is also restricted based on the given allowlist for each. This is meant to address feedback left on the Controller Messaging System proposal[1]. [1]: https://www.notion.so/Controller-Messaging-System-617efb02b9e54bd0a0b0e44c6f776d85
A method has been added to the controller messenger that returns a _restricted_ instance of the controller messenger. This instance is restricted to registering actions and events within a particular namespace, typically being the name of the controller. Access to event subscriptions and calling actions is also restricted based on the given allowlist for each. This is meant to address feedback left on the Controller Messaging System proposal[1]. [1]: https://www.notion.so/Controller-Messaging-System-617efb02b9e54bd0a0b0e44c6f776d85
A method has been added to the controller messenger that returns a restricted instance of the controller messenger. This instance is restricted to registering actions and events within a particular namespace, typically being the name of the controller. Access to event subscriptions and calling actions is also restricted based on the given allowlist for each.
This is meant to address feedback left on the Controller Messaging System proposal.