Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0879ebc

Browse filesBrowse files
authored
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.
1 parent 102f825 commit 0879ebc
Copy full SHA for 0879ebc

File tree

Expand file treeCollapse file tree

2 files changed

+12
-3
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+12
-3
lines changed

‎Doc/library/urllib.request.rst

Copy file name to clipboardExpand all lines: Doc/library/urllib.request.rst
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ The :mod:`urllib.request` module defines the following functions:
199199

200200
.. versionchanged:: next
201201
This function calls :func:`socket.gethostbyname` if the URL authority
202-
isn't empty or ``localhost``. If the authority resolves to a local IP
203-
address then it is discarded; otherwise, on Windows a UNC path is
204-
returned (as before), and on other platforms a
202+
isn't empty, ``localhost``, or the machine hostname. If the authority
203+
resolves to a local IP address then it is discarded; otherwise, on
204+
Windows a UNC path is returned (as before), and on other platforms a
205205
:exc:`~urllib.error.URLError` is raised.
206206

207207
.. versionchanged:: next

‎Lib/urllib/request.py

Copy file name to clipboardExpand all lines: Lib/urllib/request.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,8 +1483,17 @@ def open_local_file(self, req):
14831483
file_open = open_local_file
14841484

14851485
def _is_local_authority(authority):
1486+
# Compare hostnames
14861487
if not authority or authority == 'localhost':
14871488
return True
1489+
try:
1490+
hostname = socket.gethostname()
1491+
except (socket.gaierror, AttributeError):
1492+
pass
1493+
else:
1494+
if authority == hostname:
1495+
return True
1496+
# Compare IP addresses
14881497
try:
14891498
address = socket.gethostbyname(authority)
14901499
except (socket.gaierror, AttributeError):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.