You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ensure options as passed to plugins is not modified #2582
Within our core plugins, we frequently change the this.option object to pass data around. Instead we should do that in another variable and keep this.option read only & immutable to avoid conflicts between plugins.
Further clarifications:
Passed options is CLI parameters, as resolved on sls.processedInput.options. They are passed as second argument to initialized plugin.
Freezing this object may not be great idea. As there are rare (corner case) scenarios where patching/hacking this object could be helpful, and also it's not a convention in JS to freeze such input objects (If we would to freeze that, then technically by convention we should freeze most of the internal structure, as plugins should also not interfere with it).
Still, it's definitely a valid concern, that this object should not be modified, either by internal plugins or external plugins, and indeed we repeat a quite bad pattern in internal plugins where we first assign options to this.options and then extend this.options with some useful data to be used across methods. That's quite error-prone, and collisions are likely
Proposed solution: I'd address this issue by picking up on all places where this.options.x = .. assignment happen, and ensuring that this.options is a copy of options that was passed via arguments.
Activity
[-]Make sure this.options object is read only[/-][+]Ensure options as passed to plugins is not modified[/+]medikoo commentedon Aug 20, 2020
Freezing this object may not be great idea. As there are rare (corner case) scenarios where patching/hacking this object could be helpful, and also it's not a convention in JS to freeze such input objects (If we would to freeze that, then technically by convention we should freeze most of the internal structure, as plugins should also not interfere with it).
Still, it's definitely a valid concern, that this object should not be modified, either by internal plugins or external plugins, and indeed we repeat a quite bad pattern in internal plugins where we first assign
optionstothis.optionsand then extendthis.optionswith some useful data to be used across methods. That's quite error-prone, and collisions are likelyProposed solution: I'd address this issue by picking up on all places where
this.options.x = ..assignment happen, and ensuring thatthis.optionsis a copy of options that was passed via arguments.sleepwithcoffee commentedon Mar 10, 2023
hi @medikoo
I think to avoid modifying the original
optionsobject, we need to make a clone whenever assigning it tothis.optionsmedikoo commentedon Mar 10, 2023
@duytrandev exactly, that's the way to go 👍