mirror of
https://github.com/python/cpython.git
synced 2025-08-22 09:45:06 +00:00
bpo-39603: Prevent header injection in http methods (GH-18485)
reject control chars in http method in http.client.putrequest to prevent http header injection
This commit is contained in:
parent
9b01c598ca
commit
8ca8a2e8fb
3 changed files with 39 additions and 0 deletions
|
@ -368,6 +368,28 @@ class HeaderTests(TestCase):
|
|||
self.assertEqual(lines[3], "header: Second: val2")
|
||||
|
||||
|
||||
class HttpMethodTests(TestCase):
|
||||
def test_invalid_method_names(self):
|
||||
methods = (
|
||||
'GET\r',
|
||||
'POST\n',
|
||||
'PUT\n\r',
|
||||
'POST\nValue',
|
||||
'POST\nHOST:abc',
|
||||
'GET\nrHost:abc\n',
|
||||
'POST\rRemainder:\r',
|
||||
'GET\rHOST:\n',
|
||||
'\nPUT'
|
||||
)
|
||||
|
||||
for method in methods:
|
||||
with self.assertRaisesRegex(
|
||||
ValueError, "method can't contain control characters"):
|
||||
conn = client.HTTPConnection('example.com')
|
||||
conn.sock = FakeSocket(None)
|
||||
conn.request(method=method, url="/")
|
||||
|
||||
|
||||
class TransferEncodingTest(TestCase):
|
||||
expected_body = b"It's just a flesh wound"
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue