]> granicus.if.org Git - python/commitdiff
Issue #22419: Limit the length of incoming HTTP request in wsgiref server to 65536...
authorSenthil Kumaran <senthil@uthcode.com>
Wed, 17 Sep 2014 08:27:06 +0000 (16:27 +0800)
committerSenthil Kumaran <senthil@uthcode.com>
Wed, 17 Sep 2014 08:27:06 +0000 (16:27 +0800)
Lib/test/test_wsgiref.py
Lib/wsgiref/simple_server.py
Misc/ACKS
Misc/NEWS

index 401d784b219636dbdd22fe020625dad85362c7e5..40fc35efbcbb87d2e4441b358103fc3cf1dc8960 100644 (file)
@@ -113,6 +113,11 @@ class IntegrationTests(TestCase):
         out, err = run_amock()
         self.check_hello(out)
 
+    def test_request_length(self):
+        out, err = run_amock(data="GET " + ("x" * 65537) + " HTTP/1.0\n\n")
+        self.assertEqual(out.splitlines()[0],
+                         "HTTP/1.0 414 Request-URI Too Long")
+
     def test_validated_hello(self):
         out, err = run_amock(validator(hello_app))
         # the middleware doesn't support len(), so content-length isn't there
index 12119ea5c1d9293e7c135d992055b1f8d01ddc9d..35b98d10d87edbc9e8c1f5e0dd1078a5db0897cc 100644 (file)
@@ -113,7 +113,14 @@ class WSGIRequestHandler(BaseHTTPRequestHandler):
     def handle(self):
         """Handle a single HTTP request"""
 
-        self.raw_requestline = self.rfile.readline()
+        self.raw_requestline = self.rfile.readline(65537)
+        if len(self.raw_requestline) > 65536:
+            self.requestline = ''
+            self.request_version = ''
+            self.command = ''
+            self.send_error(414)
+            return
+
         if not self.parse_request(): # An error code has been sent, just exit
             return
 
index 1ca04794fc90748124dd6846792766d6bbe81a46..15125e5e5df87964eacb3fdb6ac93b8d11557b76 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -268,6 +268,7 @@ Denver Coneybeare
 Phil Connell
 Juan José Conti
 Matt Conway
+Devin Cook
 David M. Cooke
 Jason R. Coombs
 Garrett Cooper
index 2907c1c7c6d0d345c3bcc031b172b76c3ea44ad1..b545a5538a7a47dcc9c66cde76e37c4d4f986cbf 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -21,6 +21,10 @@ Core and Builtins
 
 Library
 -------
+- 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.
+
 - Lax cookie parsing in http.cookies could be a security issue when combined
   with non-standard cookie handling in some Web browsers.  Reported by
   Sergey Bobrov.