|
|
|
|
@ -15,6 +15,7 @@ import hashlib
|
|
|
|
|
import hmac
|
|
|
|
|
import importlib
|
|
|
|
|
import io
|
|
|
|
|
import ipaddress
|
|
|
|
|
import json
|
|
|
|
|
import logging
|
|
|
|
|
import mimetypes
|
|
|
|
|
@ -252,6 +253,8 @@ class NotebookWebApplication(web.Application):
|
|
|
|
|
password=jupyter_app.password,
|
|
|
|
|
xsrf_cookies=True,
|
|
|
|
|
disable_check_xsrf=jupyter_app.disable_check_xsrf,
|
|
|
|
|
allow_remote_access=jupyter_app.allow_remote_access,
|
|
|
|
|
local_hostnames=jupyter_app.local_hostnames,
|
|
|
|
|
|
|
|
|
|
# managers
|
|
|
|
|
kernel_manager=kernel_manager,
|
|
|
|
|
@ -831,6 +834,46 @@ class NotebookApp(JupyterApp):
|
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
allow_remote_access = Bool(config=True,
|
|
|
|
|
help="""Allow requests where the Host header doesn't point to a local server
|
|
|
|
|
|
|
|
|
|
By default, requests get a 403 forbidden response if the 'Host' header
|
|
|
|
|
shows that the browser thinks it's on a non-local domain.
|
|
|
|
|
Setting this option to True disables this check.
|
|
|
|
|
|
|
|
|
|
This protects against 'DNS rebinding' attacks, where a remote web server
|
|
|
|
|
serves you a page and then changes its DNS to send later requests to a
|
|
|
|
|
local IP, bypassing same-origin checks.
|
|
|
|
|
|
|
|
|
|
Local IP addresses (such as 127.0.0.1 and ::1) are allowed as local,
|
|
|
|
|
along with hostnames configured in local_hostnames.
|
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
@default('allow_remote_access')
|
|
|
|
|
def _default_allow_remote(self):
|
|
|
|
|
"""Disallow remote access if we're listening only on loopback addresses"""
|
|
|
|
|
try:
|
|
|
|
|
addr = ipaddress.ip_address(self.ip)
|
|
|
|
|
except ValueError:
|
|
|
|
|
# Address is a hostname
|
|
|
|
|
for info in socket.getaddrinfo(self.ip, self.port, 0, socket.SOCK_STREAM):
|
|
|
|
|
addr = info[4][0]
|
|
|
|
|
if not py3compat.PY3:
|
|
|
|
|
addr = addr.decode('ascii')
|
|
|
|
|
if not ipaddress.ip_address(addr).is_loopback:
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
else:
|
|
|
|
|
return not addr.is_loopback
|
|
|
|
|
|
|
|
|
|
local_hostnames = List(Unicode(), ['localhost'], config=True,
|
|
|
|
|
help="""Hostnames to allow as local when allow_remote_access is False.
|
|
|
|
|
|
|
|
|
|
Local IP addresses (such as 127.0.0.1 and ::1) are automatically accepted
|
|
|
|
|
as local as well.
|
|
|
|
|
"""
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
open_browser = Bool(True, config=True,
|
|
|
|
|
help="""Whether to open in a browser after starting.
|
|
|
|
|
The specific browser used is platform dependent and
|
|
|
|
|
|