From 658c10e84a461e5298199f20f17b510b90ac478a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Mond=C3=A9jar?= Date: Sun, 5 Apr 2020 18:47:21 +0200 Subject: [PATCH] Raise InvalidURL if hosts starts with '.' as was reported at #5367. --- requests/models.py | 2 +- tests/test_requests.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/requests/models.py b/requests/models.py index e7d292d580..d86388182b 100644 --- a/requests/models.py +++ b/requests/models.py @@ -403,7 +403,7 @@ def prepare_url(self, url, params): host = self._get_idna_encoded_host(host) except UnicodeError: raise InvalidURL('URL has an invalid label.') - elif host.startswith(u'*'): + elif host.startswith((u'*', u'.')): raise InvalidURL('URL has an invalid label.') # Carefully reconstruct the network location diff --git a/tests/test_requests.py b/tests/test_requests.py index 463e8bf47a..29b3aca84e 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -81,6 +81,8 @@ def test_entry_points(self): (InvalidSchema, 'localhost.localdomain:3128/'), (InvalidSchema, '10.122.1.1:3128/'), (InvalidURL, 'http://'), + (InvalidURL, 'http://*example.com'), + (InvalidURL, 'http://.example.com'), )) def test_invalid_url(self, exception, url): with pytest.raises(exception):