-
-
Notifications
You must be signed in to change notification settings - Fork 796
Description
Working on #112 & #96, I realized that it is really easy to take the server down by sending a malformed message. It's not very resilient. (and we don't want to test the limits of the forever module )
Really, Feathers shouldn't be responsible for a lot of validation, but it should do anything it can to keep itself running. It seems to me like we ought to at least validate the number of arguments as well as the presence (& maybe lightly the type) of each argument.
// Service methods arranged by number of arguments
var myService = {
find: function(params, callback) {},
get: function(id, params, callback) {},
remove: function(id, params, callback) {},
create: function(data, params, callback) {},
update: function(id, data, params, callback) {},
patch: function(id, data, params, callback) {}
};If we do validate the type of each argument, is there any case where id would be anything other than a string or number? MongoDB usually uses ObjectIDs, but that's something that the MongoDB service would need to validate. I can't imagine a need for using an object as an id, but maybe I need a better imagination. I think we're already checking for the presence of at least id in other places. We do it in utils.js feathers-hooks and it seems like I've seen something like this elsewhere.
The right place to be handling this is probably in commons.js. We are already creating a params object if it's not provided. Combined with #112, which does the same for the callback, I think all that's left is validating id and data as well as the number of arguments.
I think that, ideally, if the request is malformed, we would immediately send back an error 400 / Bad Request. Developers making services wouldn't have to worry about handling the same basic validation, but can focus on validation unique to the module they're developing.
@feathersjs/contributors While we're on the topic, maybe you've run into other places that the server could be hardened a bit. Let me know what you think.