Skip to content

Commit 72ee66b

Browse files
authored
Merge pull request #374 from afshin/disable-redirect-file
Add setting to disable redirect file browser launch
2 parents 60c66b6 + 491f53b commit 72ee66b

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

jupyter_server/serverapp.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,22 @@ def _default_allow_remote(self):
879879
else:
880880
return not addr.is_loopback
881881

882+
use_redirect_file = Bool(True, config=True,
883+
help="""Disable launching browser by redirect file
884+
For versions of notebook > 5.7.2, a security feature measure was added that
885+
prevented the authentication token used to launch the browser from being visible.
886+
This feature makes it difficult for other users on a multi-user system from
887+
running code in your Jupyter session as you.
888+
However, some environments (like Windows Subsystem for Linux (WSL) and Chromebooks),
889+
launching a browser using a redirect file can lead the browser failing to load.
890+
This is because of the difference in file structures/paths between the runtime and
891+
the browser.
892+
893+
Disabling this setting to False will disable this behavior, allowing the browser
894+
to launch by using a URL and visible token (as before).
895+
"""
896+
)
897+
882898
local_hostnames = List(Unicode(), ['localhost'], config=True,
883899
help="""Hostnames to allow as local when allow_remote_access is False.
884900
@@ -1761,6 +1777,12 @@ def launch_browser(self):
17611777
if not browser:
17621778
return
17631779

1780+
if not self.use_redirect_file:
1781+
uri = self.default_url[len(self.base_url):]
1782+
1783+
if self.token:
1784+
uri = url_concat(uri, {'token': self.token})
1785+
17641786
if self.file_to_run:
17651787
if not os.path.exists(self.file_to_run):
17661788
self.log.critical(_("%s does not exist") % self.file_to_run)
@@ -1776,9 +1798,12 @@ def launch_browser(self):
17761798
else:
17771799
open_file = self.browser_open_file
17781800

1779-
b = lambda: browser.open(
1780-
urljoin('file:', pathname2url(open_file)),
1781-
new=self.webbrowser_open_new)
1801+
if self.use_redirect_file:
1802+
assembled_url = urljoin('file:', pathname2url(open_file))
1803+
else:
1804+
assembled_url = url_path_join(self.connection_url, uri)
1805+
1806+
b = lambda: browser.open(assembled_url, new=self.webbrowser_open_new)
17821807
threading.Thread(target=b).start()
17831808

17841809
def start_app(self):

0 commit comments

Comments
 (0)