Changes between Initial Version and Version 1 of Ticket #37103
- Timestamp:
- May 18, 2026, 3:13:12 AM (3 weeks ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #37103 – Description
initial v1 1 Accessing request.body raises an unhandled ValueError when 2 META["CONTENT_LENGTH"] isn't a valid integer: 1 Accessing request.body raises an unhandled `ValueError` when `META["CONTENT_LENGTH"]` isn't a valid integer: 3 2 4 ValueError: invalid literal for int() with base 10: '10,20' 3 {{{ 4 ValueError: invalid literal for int() with base 10: '10,20' 5 }}} 5 6 6 This can happen with ASGIRequest if duplicate Content-Length headers are 7 comma-joined into a single META value. Even when such requests are usually 8 rejected by common HTTP parsers, HttpRequest.body is currently inconsistent 9 with other Django code paths. 7 This can happen with `ASGIRequest` if duplicate `Content-Length` headers are comma-joined into a single META value. Even when such requests are usually rejected by common HTTP parsers, `HttpRequest.body` is currently inconsistent with other Django code paths. 10 8 9 10 {{{ 11 11 WSGIRequest.__init__(), MultiPartParser.__init__(), and 12 12 django.core.servers.basehttp all wrap int(CONTENT_LENGTH) in: … … 17 17 content_length = 0 18 18 19 HttpRequest.body is the only place that calls int(CONTENT_LENGTH) without 19 }}} 20 21 `HttpRequest.body` is the only place that calls `int(CONTENT_LENGTH)` without 20 22 that guard. 21 23 22 24 Minimal reproduction: 23 25 26 {{{ 24 27 from io import BytesIO 25 28 from django.core.handlers.asgi import ASGIRequest … … 33 36 34 37 ASGIRequest(scope, BytesIO(b"hello world body")).body 38 }}} 35 39 36 40 Expected behavior: 37 request.body should handle malformed CONTENT_LENGTH consistently with 38 WSGIRequest and MultiPartParser, falling back to 0 instead of surfacing a 39 raw ValueError. 41 `request.body` should handle malformed `CONTENT_LENGTH` consistently with `WSGIRequest` and `MultiPartParser`, falling back to 0 instead of surfacing a raw `ValueError`. 40 42 41 43 Actual behavior: 42 request.body raises ValueError.44 `request.body` raises `ValueError`. 43 45 44 46 I have a patch and regression test.