[Django] #37103: HttpRequest.body raises ValueError for malformed CONTENT_LENGTH

10 views
Skip to first unread message

Django

unread,
May 17, 2026, 7:10:05 AMMay 17
to django-...@googlegroups.com
#37103: HttpRequest.body raises ValueError for malformed CONTENT_LENGTH
-------------------------------------+-------------------------------------
Reporter: bankai31337 | Type: Bug
Status: new | Component: HTTP
| handling
Version: dev | Severity: Normal
Keywords: ASGI Content-Length | Triage Stage:
HttpRequest | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Accessing request.body raises an unhandled ValueError when
META["CONTENT_LENGTH"] isn't a valid integer:

ValueError: invalid literal for int() with base 10: '10,20'

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.

WSGIRequest.__init__(), MultiPartParser.__init__(), and
django.core.servers.basehttp all wrap int(CONTENT_LENGTH) in:

try:
...
except (ValueError, TypeError):
content_length = 0

HttpRequest.body is the only place that calls int(CONTENT_LENGTH) without
that guard.

Minimal reproduction:

from io import BytesIO
from django.core.handlers.asgi import ASGIRequest
from django.test import AsyncRequestFactory

scope = AsyncRequestFactory()._base_scope(method="POST", path="/")
scope["headers"] = [
(b"content-type", b"text/plain"),
(b"content-length", b"10,20"),
]

ASGIRequest(scope, BytesIO(b"hello world body")).body

Expected behavior:
request.body should handle malformed CONTENT_LENGTH consistently with
WSGIRequest and MultiPartParser, falling back to 0 instead of surfacing a
raw ValueError.

Actual behavior:
request.body raises ValueError.

I have a patch and regression test.
--
Ticket URL: <https://code.djangoproject.com/ticket/37103>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 18, 2026, 4:13:20 AMMay 18
to django-...@googlegroups.com
#37103: HttpRequest.body raises ValueError for malformed CONTENT_LENGTH
-------------------------------------+-------------------------------------
Reporter: bankai | Owner: (none)
Type: Bug | Status: new
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: ASGI Content-Length | Triage Stage:
HttpRequest | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Sarah Boyce:

Old description:
New description:
`WSGIRequest` and `MultiPartParser`, falling back to 0 instead of
surfacing a raw `ValueError`.

Actual behavior:
`request.body` raises `ValueError`.

I have a patch and regression test.

--
--
Ticket URL: <https://code.djangoproject.com/ticket/37103#comment:1>

Django

unread,
May 18, 2026, 4:50:37 AMMay 18
to django-...@googlegroups.com
#37103: HttpRequest.body raises ValueError for malformed CONTENT_LENGTH
-------------------------------------+-------------------------------------
Reporter: bankai | Owner: (none)
Type: Bug | Status: new
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: ASGI Content-Length | Triage Stage: Accepted
HttpRequest |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* stage: Unreviewed => Accepted

--
Ticket URL: <https://code.djangoproject.com/ticket/37103#comment:2>

Django

unread,
May 18, 2026, 5:04:59 AMMay 18
to django-...@googlegroups.com
#37103: HttpRequest.body raises ValueError for malformed CONTENT_LENGTH
-------------------------------------+-------------------------------------
Reporter: bankai | Owner: bankai
Type: Bug | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: ASGI Content-Length | Triage Stage: Accepted
HttpRequest |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 0 => 1
* owner: (none) => bankai
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/37103#comment:3>

Django

unread,
May 27, 2026, 4:56:42 AM (7 days ago) May 27
to django-...@googlegroups.com
#37103: HttpRequest.body raises ValueError for malformed CONTENT_LENGTH
-------------------------------------+-------------------------------------
Reporter: bankai | Owner: bankai
Type: Bug | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: ASGI Content-Length | Triage Stage: Ready for
HttpRequest | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/37103#comment:4>

Django

unread,
5:06 AM (18 hours ago) 5:06 AM
to django-...@googlegroups.com
#37103: HttpRequest.body raises ValueError for malformed CONTENT_LENGTH
-------------------------------------+-------------------------------------
Reporter: bankai | Owner: bankai
Type: Bug | Status: closed
Component: HTTP handling | Version: dev
Severity: Normal | Resolution: fixed
Keywords: ASGI Content-Length | Triage Stage: Ready for
HttpRequest | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Sarah Boyce <42296566+sarahboyce@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"ba70e1bcdd8dc879c7d5fc7a3d12b5831eb08540" ba70e1b]:
{{{#!CommitTicketReference repository=""
revision="ba70e1bcdd8dc879c7d5fc7a3d12b5831eb08540"
Fixed #37103 -- Made HttpRequest.body handle malformed CONTENT_LENGTH.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37103#comment:5>

Django

unread,
5:08 AM (18 hours ago) 5:08 AM
to django-...@googlegroups.com
#37103: HttpRequest.body raises ValueError for malformed CONTENT_LENGTH
-------------------------------------+-------------------------------------
Reporter: bankai | Owner: bankai
Type: Bug | Status: closed
Component: HTTP handling | Version: dev
Severity: Normal | Resolution: fixed
Keywords: ASGI Content-Length | Triage Stage: Ready for
HttpRequest | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce <42296566+sarahboyce@…>):

In [changeset:"1a3721a86bea753a39273ea1fa2b56824dbcddf1" 1a3721a]:
{{{#!CommitTicketReference repository=""
revision="1a3721a86bea753a39273ea1fa2b56824dbcddf1"
[6.1.x] Fixed #37103 -- Made HttpRequest.body handle malformed
CONTENT_LENGTH.

Backport of ba70e1bcdd8dc879c7d5fc7a3d12b5831eb08540 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/37103#comment:6>
Reply all
Reply to author
Forward
0 new messages