mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
GH-123599: Match file:
URL hostname against machine hostname in urllib (#132523)
In `_is_local_authority()`, return early if the authority matches the machine hostname from `socket.gethostname()`, rather than resolving the names and matching IP addresses.
This commit is contained in:
parent
102f825c51
commit
0879ebc953
2 changed files with 12 additions and 3 deletions
|
@ -1483,8 +1483,17 @@ class FileHandler(BaseHandler):
|
|||
file_open = open_local_file
|
||||
|
||||
def _is_local_authority(authority):
|
||||
# Compare hostnames
|
||||
if not authority or authority == 'localhost':
|
||||
return True
|
||||
try:
|
||||
hostname = socket.gethostname()
|
||||
except (socket.gaierror, AttributeError):
|
||||
pass
|
||||
else:
|
||||
if authority == hostname:
|
||||
return True
|
||||
# Compare IP addresses
|
||||
try:
|
||||
address = socket.gethostbyname(authority)
|
||||
except (socket.gaierror, AttributeError):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue