-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Clarifications on request size limits and setting max request body size #1659
Comments
|
Use case: Running AWS Why to limit body max size at all? To reduce attack surface in case someone wants to try to kill my app with 1GB uploads or something like that. |
There's documentation available from Werkzeug on limited the content length. I think it probably applies to Flask, too: http://werkzeug.pocoo.org/docs/0.13/request_data/ I'm not opposed to the idea of letting Gunicorn limit the input size, but I'm always interested to understand how necessary a feature is before implementing it. The argument from symmetry is not bad. |
I think you just want to use |
And it seems you can set |
Thanks for the pointers! Though I need to study WSGI a bit to understand what the werkzeug docs mean in practice 😃.
If handling chunked requests needs reading If I got it right servers will interpret requests without |
Good questions. Reading into the werkzeug code it seems that the limiting only works when the content length is specified. When When It looks like Werkzeug will limit the input stream to the length of the content [1]. So, it seems like you could trust the Content-Length, if it's present. If it's not present and the WSGI server does not indicate that it marks the end of the input stream, then it seems the default for werkzeug is to throw it away for safety. There is a recent open issue for the |
@tuukkamustonen mind if I close this issue and just continue the work in #1653? |
By that I assume you refer to werkzeug's
Hmm, that would actually provide a nice attack vector - send in 1000 requests with
That's an interesting thought. Any idea what gunicorn does in that case - does it just drop the connection? (I believe to really understand this we would need to go deeper into TCP comms... let's not.)
Yeah, and with But I don't know, it sounds like when WSGI server sets
Yeah, let's do so. Funny coincidence that the ticket is just 10 days older - convenient! |
That's more or less the Slowloris. If you need to protect against that, use async workers or put a good reverse proxy in front.
If Gunicorn can't parse a request, it will drop the connection.
Not necessary. It just means that the server guarantees that eventually reading from the input object will return EOF. That could be because the server has cut off at some maximum request size, the remote client indicated the end of the request (such as with a zero length chunk in chunked transfer encoding), or because the Thanks for pulling on all these threads. These discussions are often helpful for others wondering the same thing. |
Good point, it's practically the same.
That's a nice way to put it. I used bad wording earlier:
I was just wondering if the WSGI server actually buffers a chunked request, before passing it on. But if I'm getting this right, the body is rather streamed with a So maximum size limit (with a default) is a requirement for
Humble thanks for taking the time to explain and educate on these. |
Looking at http://docs.gunicorn.org/en/stable/settings.html:
limit_request_field_size
allows restricting header sizes.819 000 bytes
of headers (defaults oflimit_request_fields: 100
*limit_request_field_size: 8190
bytes)?The text was updated successfully, but these errors were encountered: