Skip to content

Commit a90957d

Browse files
authoredOct 31, 2019
Merge pull request #4999 from betteridiot/betteridiot_disable_redirect_file
Setting to disable redirect file browser launch
2 parents eb3e1a4 + 0a1fff1 commit a90957d

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed
 

‎notebook/notebookapp.py

+30-3
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,24 @@ def _default_log_format(self):
645645
help=_("Whether to allow the user to run the notebook as root.")
646646
)
647647

648+
use_redirect_file = Bool(True, config=True,
649+
help="""Disable launching browser by redirect file
650+
651+
For versions of notebook > 5.7.2, a security feature measure was added that
652+
prevented the authentication token used to launch the browser from being visible.
653+
This feature makes it difficult for other users on a multi-user system from
654+
running code in your Jupyter session as you.
655+
656+
However, some environments (like Windows Subsystem for Linux (WSL) and Chromebooks),
657+
launching a browser using a redirect file can lead the browser failing to load.
658+
This is because of the difference in file structures/paths between the runtime and
659+
the browser.
660+
661+
Disabling this setting to False will disable this behavior, allowing the browser
662+
to launch by using a URL and visible token (as before).
663+
"""
664+
)
665+
648666
default_url = Unicode('/tree', config=True,
649667
help=_("The default URL to redirect to from `/`")
650668
)
@@ -1805,6 +1823,12 @@ def launch_browser(self):
18051823
if not browser:
18061824
return
18071825

1826+
if not self.use_redirect_file:
1827+
uri = self.default_url[len(self.base_url):]
1828+
1829+
if self.token:
1830+
uri = url_concat(uri, {'token': self.token})
1831+
18081832
if self.file_to_run:
18091833
if not os.path.exists(self.file_to_run):
18101834
self.log.critical(_("%s does not exist") % self.file_to_run)
@@ -1820,9 +1844,12 @@ def launch_browser(self):
18201844
else:
18211845
open_file = self.browser_open_file
18221846

1823-
b = lambda: browser.open(
1824-
urljoin('file:', pathname2url(open_file)),
1825-
new=self.webbrowser_open_new)
1847+
if self.use_redirect_file:
1848+
assembled_url = urljoin('file:', pathname2url(open_file))
1849+
else:
1850+
assembled_url = url_path_join(self.connection_url, uri)
1851+
1852+
b = lambda: browser.open(assembled_url, new=self.webbrowser_open_new)
18261853
threading.Thread(target=b).start()
18271854

18281855
def start(self):

0 commit comments

Comments
 (0)
Please sign in to comment.