Skip to content

Commit

Permalink
Apply CSP sandboxing for nbconvert responses
Browse files Browse the repository at this point in the history
These may contain untrusted content, so they should be treated as being
from a different domain to the notebook server.
  • Loading branch information
takluyver committed Nov 16, 2018
1 parent 775cb20 commit 4026ef0
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions notebook/nbconvert/handlers.py
Expand Up @@ -78,6 +78,13 @@ class NbconvertFileHandler(IPythonHandler):

SUPPORTED_METHODS = ('GET',)

@property
def content_security_policy(self):
# In case we're serving HTML/SVG, confine any Javascript to a unique
# origin so it can't interact with the notebook server.
return super(NbconvertFileHandler, self).content_security_policy + \
"; sandbox allow-scripts"

@web.authenticated
def get(self, format, path):

Expand Down Expand Up @@ -145,6 +152,13 @@ def get(self, format, path):
class NbconvertPostHandler(IPythonHandler):
SUPPORTED_METHODS = ('POST',)

@property
def content_security_policy(self):
# In case we're serving HTML/SVG, confine any Javascript to a unique
# origin so it can't interact with the notebook server.
return super(NbconvertPostHandler, self).content_security_policy + \
"; sandbox allow-scripts"

@web.authenticated
def post(self, format):
exporter = get_exporter(format, config=self.config)
Expand Down

0 comments on commit 4026ef0

Please sign in to comment.