Skip to content

Commit

Permalink
Raise InvalidURL if hosts starts with '.' as was reported at #5367.
Browse files Browse the repository at this point in the history
  • Loading branch information
mondeja authored and nateprewitt committed Dec 28, 2021
1 parent 39d0fdd commit 658c10e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion requests/models.py
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/test_requests.py
Expand Up @@ -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):
Expand Down

0 comments on commit 658c10e

Please sign in to comment.