8000 bpo-44022: Fix http client infinite line reading (DoS) after a http 100 by gen-xu · Pull Request #25916 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-44022: Fix http client infinite line reading (DoS) after a http 100 #25916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-44022: Fix httplib client deny of service with total header size …
…check after 100
  • Loading branch information
gen-xu committed May 5, 2021
commit e53f243a4d744912204cda9ae380879fca2e7ef1
5 changes: 4 additions & 1 deletion Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,12 @@ def begin(self):
if status != CONTINUE:
break
# skip the header from the 100 response
header_total_size = 0
while True:
skip = self.fp.readline(_MAXLINE + 1)
if len(skip) > _MAXLINE:
line_length = len(skip)
header_total_size += line_length
if line_length > _MAXLINE or header_total_size > _MAXLINE:
raise LineTooLong("header line")
skip = skip.strip()
if not skip:
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_httplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,6 +1180,14 @@ def test_overflowing_header_line(self):
resp = client.HTTPResponse(FakeSocket(body))
self.assertRaises(client.LineTooLong, resp.begin)

def test_overflowing_total_header_size_after_100(self):
body = (
'HTTP/1.1 100 OK\r\n'
'r\n' * 32768
)
resp = client.HTTPResponse(FakeSocket(body))
self.assertRaises(client.LineTooLong, resp.begin)

def test_overflowing_chunked_line(self):
body = (
'HTTP/1.1 200 OK\r\n'
Expand Down
0