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
10 changes: 10 additions & 0 deletions Lib/test/test_urlparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,16 @@ def test_splithost(self):
self.assertEqual(splithost("//example.net/file#"),
('example.net', '/file#'))

# bpo-35906: disallow line breaks
self.assertEqual(splithost('//127.0.0.1:1234/?q=HTTP/1.1\r\nHeader: Value'),
(None, '//127.0.0.1:1234/?q=HTTP/1.1\r\nHeader: Value'))

self.assertEqual(splithost('//127.0.0.1:1234?q=HTTP/1.1\r\nHeader: Value'),
(None, '//127.0.0.1:1234?q=HTTP/1.1\r\nHeader: Value'))

self.assertEqual(splithost('//127.0.0.1:1234#q=HTTP/1.1\r\nHeader: Value'),
(None, '//127.0.0.1:1234#q=HTTP/1.1\r\nHeader: Value'))

def test_splituser(self):
splituser = urllib.parse._splituser
self.assertEqual(splituser('User:Pass@www.python.org:080'),
Expand Down
2 changes: 1 addition & 1 deletion Lib/urllib/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ def _splithost(url):
"""splithost('//host[:port]/path') --> 'host[:port]', '/path'."""
global _hostprog
if _hostprog is None:
_hostprog = re.compile('//([^/#?]*)(.*)', re.DOTALL)
_hostprog = re.compile('//([^/#?]*)(.*)$')

match = _hostprog.match(url)
if match:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix CRLF injection in urllib as disallowing line breaks in parse