Skip to content

Fix ASGI callback parser EOF handling and header validation#3560

Merged
benoitc merged 3 commits into
masterfrom
fix/asgi-callback-parser-eof-handling
Mar 26, 2026
Merged

Fix ASGI callback parser EOF handling and header validation#3560
benoitc merged 3 commits into
masterfrom
fix/asgi-callback-parser-eof-handling

Conversation

@benoitc
Copy link
Copy Markdown
Owner

@benoitc benoitc commented Mar 26, 2026

Summary

  • Add finish() method to PythonProtocol for EOF handling in chunked encoding
  • Fix header validation in ASGI callback parser
  • Require gunicorn_h1c >= 0.6.0 for matching finish() support in fast parser

Changes

  • Handle edge case where chunked encoding ends at EOF without final CRLF
  • Skip WSGI-specific tests (casefold_http_method, header_map) that don't apply to ASGI
  • Update minimum gunicorn_h1c version requirement

benoitc added 3 commits March 26, 2026 06:32
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.
@benoitc benoitc merged commit 3b763dd into master Mar 26, 2026
23 of 25 checks passed
Comment thread gunicorn/asgi/parser.py
# identity after chunked is invalid
if chunked:
raise InvalidHeader("Invalid Transfer-Encoding after chunked")
elif val_lower in (b'compress', b'deflate', b'gzip'):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants