Skip to content

Commit

Permalink
add xsrf checks on files endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed Mar 8, 2019
1 parent 98773c1 commit d7becaf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
9 changes: 8 additions & 1 deletion notebook/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,14 +650,21 @@ def content_security_policy(self):
return super(AuthenticatedFileHandler, self).content_security_policy + \
"; sandbox allow-scripts"

@web.authenticated
def head(self, path):
self.check_xsrf_cookie()
return super(AuthenticatedFileHandler, self).head(path)

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

if os.path.splitext(path)[1] == '.ipynb' or self.get_argument("download", False):
name = path.rsplit('/', 1)[-1]
self.set_attachment_header(name)

return web.StaticFileHandler.get(self, path)

def get_content_type(self):
path = self.absolute_path.strip('/')
if '/' in path:
Expand Down
5 changes: 4 additions & 1 deletion notebook/files/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ def content_security_policy(self):

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

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

if cm.is_hidden(path) and not cm.allow_hidden:
Expand Down
1 change: 1 addition & 0 deletions notebook/services/nbconvert/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class NbconvertRootHandler(APIHandler):

@web.authenticated
def get(self):
self.check_xsrf_cookie()
try:
from nbconvert.exporters import base
except ImportError as e:
Expand Down

0 comments on commit d7becaf

Please sign in to comment.