Skip to content

Commit

Permalink
check_xsrf_cookie after authentication
Browse files Browse the repository at this point in the history
now that get_user is async, we have to re-run the check in prepare
  • Loading branch information
minrk committed Apr 25, 2022
1 parent b221692 commit 31f53c6
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions jupyter_server/base/handlers.py
Expand Up @@ -506,6 +506,9 @@ def check_referer(self):

def check_xsrf_cookie(self):
"""Bypass xsrf cookie checks when token-authenticated"""
if not hasattr(self, "_jupyter_user"):
# Called too early, will be checked later
return
if self.token_authenticated or self.settings.get("disable_check_xsrf", False):
# Token-authenticated requests do not need additional XSRF-check
# Servers without authentication are vulnerable to XSRF
Expand Down Expand Up @@ -593,8 +596,11 @@ async def prepare(self):

# self.current_user for tornado's @web.authenticated
# self._jupyter_user for backward-compat in deprecated get_current_user calls
# and our own private checks for whether .current_user has been set
self.current_user = self._jupyter_user = user
# complete initial steps which require auth to resolve first:
self.set_cors_headers()
self.check_xsrf_cookie()
return super().prepare()

# ---------------------------------------------------------------
Expand Down

0 comments on commit 31f53c6

Please sign in to comment.