Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/test/test_urlparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1036,6 +1036,11 @@ def test_splithost(self):
self.assertEqual(splithost("//example.net/file#"),
('example.net', '/file#'))

# bpo-35906: # avoid the header injection
self.assertEqual(
splithost('//127.0.0.1:1234/?q=HTTP/1.1\r\nHeader: Value'),
('127.0.0.1:1234', '/?q=HTTP/1.1'))

def test_splituser(self):
splituser = urllib.parse._splituser
self.assertEqual(splituser('User:Pass@www.python.org:080'),
Expand Down
5 changes: 5 additions & 0 deletions Lib/urllib/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,8 +1004,13 @@ def _splithost(url):
match = _hostprog.match(url)
if match:
host_port, path = match.groups()

if path:
path = path.splitlines()[0]

if path and path[0] != '/':
path = '/' + path

return host_port, path
return None, url

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid headers injection with urllib.urlopen.