Skip to content

Commit d7becaf

Browse files
committed
add xsrf checks on files endpoints
1 parent 98773c1 commit d7becaf

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

notebook/base/handlers.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,14 +650,21 @@ def content_security_policy(self):
650650
return super(AuthenticatedFileHandler, self).content_security_policy + \
651651
"; sandbox allow-scripts"
652652

653+
@web.authenticated
654+
def head(self, path):
655+
self.check_xsrf_cookie()
656+
return super(AuthenticatedFileHandler, self).head(path)
657+
653658
@web.authenticated
654659
def get(self, path):
660+
self.check_xsrf_cookie()
661+
655662
if os.path.splitext(path)[1] == '.ipynb' or self.get_argument("download", False):
656663
name = path.rsplit('/', 1)[-1]
657664
self.set_attachment_header(name)
658665

659666
return web.StaticFileHandler.get(self, path)
660-
667+
661668
def get_content_type(self):
662669
path = self.absolute_path.strip('/')
663670
if '/' in path:

notebook/files/handlers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,13 @@ def content_security_policy(self):
3131

3232
@web.authenticated
3333
def head(self, path):
34-
self.get(path, include_body=False)
34+
self.check_xsrf_cookie()
35+
return self.get(path, include_body=False)
3536

3637
@web.authenticated
3738
def get(self, path, include_body=True):
39+
# /files/ requests must originate from the same site
40+
self.check_xsrf_cookie()
3841
cm = self.contents_manager
3942

4043
if cm.is_hidden(path) and not cm.allow_hidden:

notebook/services/nbconvert/handlers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class NbconvertRootHandler(APIHandler):
99

1010
@web.authenticated
1111
def get(self):
12+
self.check_xsrf_cookie()
1213
try:
1314
from nbconvert.exporters import base
1415
except ImportError as e:

0 commit comments

Comments
 (0)