Skip to content

Commit 860c367

Browse files
committed
Issue #22419: Limit the length of incoming HTTP request in wsgiref server to
65536 bytes and send a 414 error code for higher lengths. Patch contributed by Devin Cook.
1 parent 21bf3f9 commit 860c367

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

Lib/test/test_wsgiref.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ def test_plain_hello(self):
114114
out, err = run_amock()
115115
self.check_hello(out)
116116

117+
def test_request_length(self):
118+
out, err = run_amock(data=b"GET " + (b"x" * 65537) + b" HTTP/1.0\n\n")
119+
self.assertEqual(out.splitlines()[0],
120+
b"HTTP/1.0 414 Request-URI Too Long")
121+
117122
def test_validated_hello(self):
118123
out, err = run_amock(validator(hello_app))
119124
# 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
@@ -114,7 +114,14 @@ def get_stderr(self):
114114
def handle(self):
115115
"""Handle a single HTTP request"""
116116

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

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ Denver Coneybeare
219219
Geremy Condra
220220
Juan José Conti
221221
Matt Conway
222+
Devin Cook
222223
David M. Cooke
223224
Jason R. Coombs
224225
Garrett Cooper

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ What's New in Python 3.2.6?
1010
Library
1111
-------
1212

13+
- Issue #22419: Limit the length of incoming HTTP request in wsgiref server to
14+
65536 bytes and send a 414 error code for higher lengths. Patch contributed
15+
by Devin Cook.
16+
1317
- Issue #22517: When a io.BufferedRWPair object is deallocated, clear its
1418
weakrefs.
1519

0 commit comments

Comments
 (0)