Skip to content

Commit e321c80

Browse files
authored
Merge pull request #3341 from takluyver/csp-sandbox-files
Use CSP header to treat served files as belonging to a separate origin
2 parents c1c7d3d + 694ed72 commit e321c80

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

notebook/base/handlers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,13 @@ def prepare(self):
601601
class AuthenticatedFileHandler(IPythonHandler, web.StaticFileHandler):
602602
"""static files should only be accessible when logged in"""
603603

604+
@property
605+
def content_security_policy(self):
606+
# In case we're serving HTML/SVG, confine any Javascript to a unique
607+
# origin so it can't interact with the notebook server.
608+
return super(AuthenticatedFileHandler, self).content_security_policy + \
609+
"; sandbox allow-scripts"
610+
604611
@web.authenticated
605612
def get(self, path):
606613
if os.path.splitext(path)[1] == '.ipynb' or self.get_argument("download", False):

notebook/files/handlers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ class FilesHandler(IPythonHandler):
2626
a subclass of StaticFileHandler.
2727
"""
2828

29+
@property
30+
def content_security_policy(self):
31+
# In case we're serving HTML/SVG, confine any Javascript to a unique
32+
# origin so it can't interact with the notebook server.
33+
return super(FilesHandler, self).content_security_policy + \
34+
"; sandbox allow-scripts"
35+
2936
@web.authenticated
3037
def head(self, path):
3138
self.get(path, include_body=False)

0 commit comments

Comments
 (0)