As the title says, I am trying to pass a function as a parameter to a Meteor method. When I print out the parameter, which should be the function, it’s as if the parameter doesn’t exist. Has anyone run into this before? Is it possible to pass functions as a parameter?
Edit: This method call is on the client side.
Methods are meant to run on the DDP protocol, which is Meteor’s way to do remote procedure calls over the network. Passing functions makes no sense in this case, so they are dropped.
However, there is a way to “type” arguments (and return values) of methods using EJSON. In this case, the values will be auto-wrapped in model objects matching that type.
For instance, if you pass an object from a “Message” class on the client to the server, it will be re-instantiated as a Message object on server-side as well and vice versa. You could use this to call specific methods on these objects.
More on EJSON here: EJSON | Meteor API Docs
Passing a bare function as code is not possible, though, since this would require serializing code into network messages. This might also cause security issues.
This would be a big security issue. Any client would be able to provide any function that gets run on the server. That’s a remote code execution exploit (RCE).