Skip to content

[3.13] gh-150751: validate http.client Content-Length and chunk-size (GH-150752) - #160770

Open
miss-islington wants to merge 4 commits into
python:3.13from
miss-islington:backport-2eb2af8-3.13
Open

miss-islington wants to merge 4 commits into
python:3.13from
miss-islington:backport-2eb2af8-3.13

Conversation

@miss-islington

@miss-islington miss-islington commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

RFC 9112 defines Content-Length as 1DIGIT and chunk-size as 1HEXDIG, but int() also accepts a sign, underscores, surrounding whitespace and an 0x prefix, so malformed framing values were parsed instead of rejected.
(cherry picked from commit 2eb2af8)

Co-authored-by: metsw24-max metsw24@gmail.com

…ythonGH-150752)

RFC 9112 defines Content-Length as 1*DIGIT and chunk-size as 1*HEXDIG, but int() also accepts a sign, underscores, surrounding whitespace and an 0x prefix, so malformed framing values were parsed instead of rejected.
(cherry picked from commit 2eb2af8)

Co-authored-by: metsw24-max <metsw24@gmail.com>
danilablagorodniy37 and others added 3 commits November 6, 2026 14:10
…http.client (pythonGH-159156)

pythongh-150752 started validating the Content-Length value against the
RFC 9112 grammar (1*DIGIT), but the compat32 header parser keeps
trailing SP/HTAB in the field value, so "Content-Length: 5 " is now
treated as a missing header. HTTPResponse then assumes that the
connection will close and read() blocks until the server closes it,
which never happens on a keep-alive connection.

RFC 9112, section 5.1 says that optional whitespace around a field
value is excluded by parsers. Strip SP/HTAB before the grammar check;
values such as "+5", "5_0" and "5 0" are still rejected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

5 participants