Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e025b52

Browse files
committed
Issue #22419: Limit the length of incoming HTTP request in wsgiref server to 65536 bytes.
1 parent 2a42a0b commit e025b52

4 files changed

Lines changed: 18 additions & 1 deletion

File tree

Lib/test/test_wsgiref.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ def test_plain_hello(self):
118118
out, err = run_amock()
119119
self.check_hello(out)
120120

121+
def test_request_length(self):
122+
out, err = run_amock(data=b"GET " + (b"x" * 65537) + b" HTTP/1.0\n\n")
123+
self.assertEqual(out.splitlines()[0],
124+
b"HTTP/1.0 414 Request-URI Too Long")
125+
121126
def test_validated_hello(self):
122127
out, err = run_amock(validator(hello_app))
123128
# the middleware doesn't support len(), so content-length isn't there

Lib/wsgiref/simple_server.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,14 @@ def get_stderr(self):
115115
def handle(self):
116116
"""Handle a single HTTP request"""
117117

118-
self.raw_requestline = self.rfile.readline()
118+
self.raw_requestline = self.rfile.readline(65537)
119+
if len(self.raw_requestline) > 65536:
120+
self.requestline = ''
121+
self.request_version = ''
122+
self.command = ''
123+
self.send_error(414)
124+
return
125+
119126
if not self.parse_request(): # An error code has been sent, just exit
120127
return
121128

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ Denver Coneybeare
251251
Phil Connell
252252
Juan José Conti
253253
Matt Conway
254+
Devin Cook
254255
David M. Cooke
255256
Jason R. Coombs
256257
Garrett Cooper

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ Core and Builtins
1313
Library
1414
-------
1515

16+
- Issue #22419: Limit the length of incoming HTTP request in wsgiref server to
17+
65536 bytes and send a 414 error code for higher lengths. Patch contributed
18+
by Devin Cook.
19+
1620
- Lax cookie parsing in http.cookies could be a security issue when combined
1721
with non-standard cookie handling in some Web browsers. Reported by
1822
Sergey Bobrov.

0 commit comments

Comments
 (0)