]> 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:29:29 +0000 (16:29 +0800)
committerSenthil Kumaran <senthil@uthcode.com>
Wed, 17 Sep 2014 08:29:29 +0000 (16:29 +0800)
Lib/test/test_wsgiref.py
Lib/wsgiref/simple_server.py
Misc/ACKS
Misc/NEWS

index 901f3c99c6672781a8a90496f871d5c6e0df022e..e213d778f1759e5b007398756e2f300ed76f8246 100644 (file)
@@ -118,6 +118,11 @@ class IntegrationTests(TestCase):
         out, err = run_amock()
         self.check_hello(out)
 
+    def test_request_length(self):
+        out, err = run_amock(data=b"GET " + (b"x" * 65537) + b" HTTP/1.0\n\n")
+        self.assertEqual(out.splitlines()[0],
+                         b"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 cd9751a6551b5800757806f79d2f3c0457663aab..378b316bbd457c977f50fb4a6cfff43f90191033 100644 (file)
@@ -115,7 +115,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 d1ebba76508e609b23dc673c777da6ce22d288e0..cc194ab7adda030aa6d3f2e7e48b5a015114eec1 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -251,6 +251,7 @@ Denver Coneybeare
 Phil Connell
 Juan José Conti
 Matt Conway
+Devin Cook
 David M. Cooke
 Jason R. Coombs
 Garrett Cooper
index 1f389f8714fb430a2d6cb1b433d714170f093c64..b5eab851b4be139666e0d25189bbe18191a366df 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,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.