mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +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
(cherry picked from commit 8ca8a2e8fb
)
Co-authored-by: AMIR <31338382+amiremohamadi@users.noreply.github.com>
This commit is contained in:
parent
f92544483f
commit
27b811057f
3 changed files with 39 additions and 0 deletions
|
@ -365,6 +365,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