-
-
Notifications
You must be signed in to change notification settings - Fork 750
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
Server hardening with socket message validation. #113
Comments
That is true, you just have to emit some invalid data to make the server crash. The best place is probably in the socket argument validation at https://github.com/feathersjs/feathers/blob/master/lib/providers/socket/commons.js#L31. We want to make sure that there always is the minimum of the required parameters for Socket calls. I don't think this is a problem for REST calls since they'll always look the same. |
It seems from reading the paragraph directly under Section 2.1 Resource in the RestDoc spec that REST only allows for updating a single resource at a time. So |
Here's a crack at minimum validation. // Validate number of args.
// 'find' doesn't require any.
if (method !== 'find') {
if (!args[0]) {
// ERROR
}
}
// 'update' and 'patch' have data at args[1].
if(method === 'update' || method === 'patch'){
if (!args[1]) {
// ERROR
}
}
// Validate params, create if not provided
if(!args[position] || typeof args[position] === 'function') {
args.splice(position, 0, {});
}
// Validate callback, create if not provided
if (typeof args[position + 1] !== 'function') {
// ... Send any errors back to the developer.
var callback = function(err){
if (err) {
emitter.emit('error', {
path:name,
err:err
});
}
};
args.push(callback);
}
args[position] = _.extend({ query: args[position] }, params);
if (error) {
// SEND BACK AN ERROR.
emitter.emit(name', err);
} else {
service[method].apply(service, args);
} I'm not sure it's enough. |
I'm not sure either. Here are my thoughts:
The other question is: Should this be a service mixin or part of the socket handlers? Technically it would be possible to create a mixin that does that normalization and we won't have to worry about it anymore anywhere. The problem is that it would make things like hooks way more complicated. Or should the mixin just validate the parameter list to throw a reasonable error? |
@daffl It might make sense for it to be a service mixin as I think we should also be normalizing params on the REST side as well. I know less about the socket code currently, so your call. Not sure if it was the intention, but I don't like the idea of forcing the user to pass a callback. I agree with the empty argument params, but the last param should be a callback, or they could pass nothing and internally we assign an empty callback to it. Maybe that is still too much overhead on our end but I think it will make a nicer API. |
I don't think there is a need to normalize anything on the REST side. It'll always have a callback and parameters. I was thinking for 1.1 to provide Feathers utility functions that normalize the parameters that plugins can use as well though, e.g. |
Allow hyphenated-names in services - fixes #113
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs. |
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.
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 thecallback
, I think all that's left is validatingid
anddata
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.
The text was updated successfully, but these errors were encountered: