Limit the size of each request line

This commit is contained in:
Miguel Grinberg
2021-09-27 17:54:51 +01:00
parent d75449eb32
commit de9c991a9a
4 changed files with 55 additions and 6 deletions

View File

@@ -89,6 +89,18 @@ class TestRequestAsync(unittest.TestCase):
req = _run(Request.create('app', fd, 'addr'))
self.assertIsNone(req.form)
def test_large_line(self):
saved_max_readline = Request.max_readline
Request.max_readline = 16
fd = get_async_request_fd('GET', '/foo', headers={
'Content-Type': 'application/x-www-form-urlencoded'},
body='foo=bar&abc=def&x=y')
with self.assertRaises(ValueError):
_run(Request.create('app', fd, 'addr'))
Request.max_readline = saved_max_readline
def test_large_payload(self):
saved_max_content_length = Request.max_content_length
Request.max_content_length = 16
@@ -97,6 +109,6 @@ class TestRequestAsync(unittest.TestCase):
'Content-Type': 'application/x-www-form-urlencoded'},
body='foo=bar&abc=def&x=y')
req = _run(Request.create('app', fd, 'addr'))
assert req.body == b''
self.assertEqual(req.body, b'')
Request.max_content_length = saved_max_content_length