-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[9678] Fix HTTP multipart parsing of chunked requests on Py3.7+ #1207
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bpo-29979's PR python/cpython#991 changed cgi.parse_multipart() to require a 'CONTENT-LENGTH' member in its `pdict` parameter (which is documented as "dictionary containing other parameters of the content type header"). The PR seems to have some issues: * The change seems to conflate `pdict` with an environment dict, probably because the test passes a dict called `env` as `pdict`. * 'CONTENT-LENGTH' isn't a customary parameter of the Content-Type header. `pdict` is intended to pass the multipart boundary [1]. * In a CGI environment the length of the request body is in the CONTENT_LENGTH variable, anyway [2]. Typo? * FieldStorage doesn't require a Content-Length header anyway! It's potionally used to enforce cgi.maxlen, which limits the requests size (because this is the layer for that, right?). #1012 dealt with bpo-29979's backward-incompatible change by passing the HTTP `Content-Length` header as the 'CONTENT-LENGTH' member of `pdict` when the header exists. When the header isn't given, Request skips parsing the request content. The problem is that in the Twisted context, unlike the CGI context (where the web server is responsible for removing any transfer encodings), that header won't necessarily exist. For example, when a chunked transfer encoding is used by the client. This commit does the simplest possible thing: synthesize the content length based on what was actually received. [1]: https://tools.ietf.org/html/rfc7578#section-4.1 [2]: https://tools.ietf.org/html/rfc3875#section-4.1.2
Also add a reference to python/cpython#8530
glyph
approved these changes
Jan 9, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating this; the fix looks correct to me.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See a562242 for a detailed explanation. This is the simplest possible fix. I do think that we should probably ditch the
cgimodule for multipart parsing eventually because it is verystr-oriented, but we wantbytes.This includes the tests from #1180. Thank you @msdemlei!
Contributor Checklist:
reviewto the keywords field in Trac, and putting a link to this PR in the comment; it shows up in https://twisted.reviews/ now.