8000 GH-123599: Match `file:` URL hostname against machine hostname in urllib · barneygale/cpython@fc78d00 · GitHub
[go: up one dir, main page]

Skip to content

Commit fc78d00

Browse files
committed
pythonGH-123599: Match file: URL hostname against machine hostname in urllib
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.
1 parent bd47ec9 commit fc78d00

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Lib/urllib/request.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,13 @@ def open_local_file(self, req):
14851485
def _is_local_authority(authority):
14861486
if not authority or authority == 'localhost':
14871487
return True
1488+
try:
1489+
hostname = socket.gethostname()
1490+
except socket.gaierror:
1491+
pass
1492+
else:
1493+
if authority == hostname:
1494+
return True
14881495
try:
14891496
address = socket.gethostbyname(authority)
14901497
except (socket.gaierror, AttributeError):

0 commit comments

Comments
 (0)
0