Changes between Initial Version and Version 1 of Ticket #37103


Ignore:
Timestamp:
May 18, 2026, 3:13:12 AM (3 weeks ago)
Author:
Sarah Boyce
Comment:

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:
     1Accessing request.body raises an unhandled `ValueError` when `META["CONTENT_LENGTH"]` isn't a valid integer:
    32
    4     ValueError: invalid literal for int() with base 10: '10,20'
     3{{{
     4ValueError: invalid literal for int() with base 10: '10,20'
     5}}}
    56
    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.
     7This 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.
    108
     9
     10{{{
    1111WSGIRequest.__init__(), MultiPartParser.__init__(), and
    1212django.core.servers.basehttp all wrap int(CONTENT_LENGTH) in:
     
    1717        content_length = 0
    1818
    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
    2022that guard.
    2123
    2224Minimal reproduction:
    2325
     26{{{
    2427    from io import BytesIO
    2528    from django.core.handlers.asgi import ASGIRequest
     
    3336
    3437    ASGIRequest(scope, BytesIO(b"hello world body")).body
     38}}}
    3539
    3640Expected 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`.
    4042
    4143Actual behavior:
    42 request.body raises ValueError.
     44`request.body` raises `ValueError`.
    4345
    4446I have a patch and regression test.
Back to Top