Opened 11 minutes ago
Last modified 7 minutes ago
#37538 assigned Bug
Malformed Accept header crashes HttpRequest.accepts()/get_preferred_type() (HTTP 500) since CVE-2026-84429 fix
| Reported by: | Kingsley1116 | Owned by: | Kingsley1116 |
|---|---|---|---|
| Component: | HTTP handling | Version: | 6.1 |
| Severity: | Release blocker | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
Since the CVE-2026-84429 fix (5.2.18 / 6.0.9 / 6.1.2), which made parse_header_parameters() use email.message.Message, short Accept media ranges with RFC 2231 extended parameters raise ValueError (or its subclass UnicodeError). HttpRequest.accepted_types calls MediaType(token) on client-supplied tokens without handling ValueError, so accepts(), get_preferred_type() and accepted_type() crash with a 500.
This affects the built-in set_language view when no next parameter is given:
GET /i18n/setlang/ HTTP/1.1 Host: example.com Accept: text/html; a*=idna''v
- 6.1.3, 6.0.10, 5.2.19, main: 500 (
UnicodeError: Unsupported error handling replace) - 6.1.1, 6.0.8, 5.2.17: 204
Other values that crash on the affected versions: text/html; a*=x-no-such-charset''v (ValueError: Invalid encoding), text/html; a*=undefined''v (UnicodeError), and text/html; a* + 4301 digits + =v (int digit limit). Percent-encoded variants such as a*=undefined''%41 already crashed before the change. The CVE fix widened what triggers it.
Other callers of parse_header_parameters() already handle ValueError (_set_content_type_params(), the multipart parser), and MediaType.quality already ignores invalid q values. A possible fix is to skip media ranges in accepted_types that fail to parse. I have a patch with a regression test in requests_tests.test_accept_header and can open a PR.
Related but distinct: #37445 (Content-Type raising during request construction). Its PR doesn't touch accepted_types.
Tested with Python 3.12.10.
AI disclosure: Claude Code (Claude Opus 5.5) was used to investigate the code, write and run the reproduction scripts across Django versions, search Trac, and draft this text. I reviewed and re-ran the reproduction myself before filing.
Change History (2)
comment:1 by , 9 minutes ago
| Has patch: | set |
|---|
comment:2 by , 7 minutes ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
PR: https://github.com/django/django/pull/22340