-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Config max request message size to fend off potential malicious attacks #1097
Comments
I know this isn't the same setting you're looking for but |
https://docs.rs/tower-http/latest/tower_http/limit/index.html should work with tonic though it wont give gRPC specific responses. |
@davidpdrsn I wonder if we can make it smart and detect grpc and reply in a grpc fashion if so? Though we could also just implement this into tonic. |
Yeah that would be nice. Already have some gRPC stuff in tower-http so makes sense to support for limited bodies as well. |
Just pulled
The client can send over an arbitrarily long string as
|
@Ajkcki you need to use https://docs.rs/tower-http/latest/tower_http/limit/index.html |
@davidpdrsn I tried, but
Here is the error message
|
Yeah, so I think we will need to implement our own length limit but I don't think its trivial since it needs to cross a couple config bounds. We will need to pass a length limit into the decode/encode part, I think we can follow a similar path to what compression did. OR rethink how we abstract config between the transport and grpc protocol. |
Hi @LucioFranco, Is there any updates about this issue, I see that there is related issues which was merged Thanks |
My comment above is still accurate, I have not had time to work on this so if someone is interested I can help mentor. |
Hi @LucioFranco, I'm interested to contribute, I did a quick look at the codebase: tonic/tonic/src/codec/decode.rs Line 154 in 8277071
Adding a control on For example if len > self.max_message_size {
return Err(Status::new(Code::OutOfRange, format!("Error, message too large: found {} bytes, maximum authorised {} bytes", len, self.max_message_size)));
} Same for the If you have a better idea, you're welcome, I'll be glad to implement It. |
Yeah, I think that should work, I think the interesting part will be with how we configure it. |
I have some questions before implementing it:
|
Yeah, I think having two configs should be fine.
Probably should be done similar to how these are setup https://github.com/hyperium/tonic/blob/master/tonic-build/src/server.rs#L71 |
* feat(codec): add max_message_size parameter resolves #1097 * refactor(client): add max size parameters * refactor(tonic-build): update server gen template * refactor(tonic-build): update client template * fix(tonic-build): update client template * fix(tonic-build): small typo in server.rs * fix(tonic-build): client.rs generator * fix(tonic): add apply max message setting size to server * fix(test): wrong message size * fix: doctest + generated rs
Feature Request
If a message size is maliciously large, blindly accept it may not be a good idea.
A quick test shows that with the current tonic server (0.8.1), a simple hello-world unary service was able to take a 1GB size request message and return a response; even though the service handler always responds "hello world" without processing the request at all, just accepting such a message significantly slow down the server. It would be more reasonable to drop the connection instead of blindly consuming system resources to decompress/parse such a large message.
This is the same request as in #264.
The text was updated successfully, but these errors were encountered: