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
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
Prev Previous commit
Next Next commit
renamed the new function to _read_headers to keep it private.
  • Loading branch information
gpshead authored May 5, 2021
commit 17941e81cf3d189b849b2ac322ed27239727478c
11 changes: 6 additions & 5 deletions Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ def getallmatchingheaders(self, name):
lst.append(line)
return lst

def read_headers(fp):
"""Reads headers into a list from a file pointer.
def _read_headers(fp):
"""Reads potential header lines into a list from a file pointer.

Length of line is limited by _MAXLINE, and number of
headers is limited by _MAXHEADERS.
Expand All @@ -230,7 +230,7 @@ def parse_headers(fp, _class=HTTPMessage):
to parse.

"""
headers = read_headers(fp)
headers = _read_headers(fp)
hstring = b''.join(headers).decode('iso-8859-1')
return email.parser.Parser(_class=_class).parsestr(hstring)

Expand Down Expand Up @@ -318,9 +318,10 @@ def begin(self):
if status != CONTINUE:
break
# skip the header from the 100 response
skip = read_headers(self.fp)
skipped_headers = _read_headers(self.fp)
if self.debuglevel > 0:
print("header:", skip)
print("headers:", skipped_headers)
del skipped_headers

self.code = self.status = status
self.reason = reason.strip()
Expand Down
0