Fix ASGI callback parser EOF handling and header validation#3560
Merged
Conversation
Add security checks to PythonProtocol per RFC 9110/9112: - Reject duplicate Content-Length headers - Reject CL + TE combinations - Reject chunked in HTTP/1.0 - Reject stacked chunked encoding - Validate Transfer-Encoding values - Strict chunk size validation Add PROXY protocol v1/v2 support to callback parser. Add treq-based test infrastructure for ASGI parser.
Handle chunked encoding edge case where connection closes before final CRLF after zero-chunk. Skip WSGI-specific tests (casefold, underscore headers) that don't apply to ASGI.
Update minimum version requirement for the fast HTTP parser to 0.6.0 which includes the finish() method for EOF handling in chunked encoding.
pajod
reviewed
Mar 26, 2026
| # identity after chunked is invalid | ||
| if chunked: | ||
| raise InvalidHeader("Invalid Transfer-Encoding after chunked") | ||
| elif val_lower in (b'compress', b'deflate', b'gzip'): |
Contributor
There was a problem hiding this comment.
Why accept compress/deflate/gzip?
The application has no way to reliably know which hop-by-hop headers have been processed, and which still alter the meaning of the body. Since Gunicorn does not (and arguably, should not) decode that, any (in practice, nonexisting) request with such encoding specified should be rejected with UnsupportedTransferCoding as well. See also #3368
This file contains hidden or 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
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.
Summary
finish()method to PythonProtocol for EOF handling in chunked encodingfinish()support in fast parserChanges