Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2a42a0b

Browse files
committed
Issue #22421 - Secure pydoc server run. Bind it to localhost instead of all interfaces.
1 parent 7d0b8f9 commit 2a42a0b

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

Lib/pydoc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,8 +2168,8 @@ def log_message(self, *args):
21682168
class DocServer(http.server.HTTPServer):
21692169

21702170
def __init__(self, port, callback):
2171-
self.host = (sys.platform == 'mac') and '127.0.0.1' or 'localhost'
2172-
self.address = ('', port)
2171+
self.host = 'localhost'
2172+
self.address = (self.host, port)
21732173
self.callback = callback
21742174
self.base.__init__(self, self.address, self.handler)
21752175
self.quit = False

Lib/test/test_pydoc.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,8 @@ def my_url_handler(url, content_type):
557557
return text
558558

559559
serverthread = pydoc._start_server(my_url_handler, port=0)
560+
self.assertIn('localhost', serverthread.docserver.address)
561+
560562
starttime = time.time()
561563
timeout = 1 #seconds
562564

0 commit comments

Comments
 (0)