Skip to content

Commit

Permalink
Merge pull request #3341 from takluyver/csp-sandbox-files
Browse files Browse the repository at this point in the history
Use CSP header to treat served files as belonging to a separate origin
  • Loading branch information
takluyver authored Mar 9, 2018
2 parents c1c7d3d + 694ed72 commit e321c80
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions notebook/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,13 @@ def prepare(self):
class AuthenticatedFileHandler(IPythonHandler, web.StaticFileHandler):
"""static files should only be accessible when logged in"""

@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(AuthenticatedFileHandler, self).content_security_policy + \
"; sandbox allow-scripts"

@web.authenticated
def get(self, path):
if os.path.splitext(path)[1] == '.ipynb' or self.get_argument("download", False):
Expand Down
7 changes: 7 additions & 0 deletions notebook/files/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ class FilesHandler(IPythonHandler):
a subclass of StaticFileHandler.
"""

@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(FilesHandler, self).content_security_policy + \
"; sandbox allow-scripts"

@web.authenticated
def head(self, path):
self.get(path, include_body=False)
Expand Down

0 comments on commit e321c80

Please sign in to comment.