Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Set XSRF cookie on API request #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions jupyter_server/auth/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ def set_login_cookie(cls, handler, user_id=None):
cookie_options.setdefault("secure", True)
cookie_options.setdefault("path", handler.base_url)
handler.set_secure_cookie(handler.cookie_name, user_id, **cookie_options)
# To set _xsrf cookie at login
handler.current_user = handler._jupyter_current_user = user_id
handler.xsrf_token
return user_id

auth_header_pat = re.compile(r"token\s+(.+)", re.IGNORECASE)
Expand Down
1 change: 1 addition & 0 deletions jupyter_server/base/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def clear_login_cookie(self):
# N.B. This bypasses the normal cookie handling, which can't update
# two cookies with the same name. See the method above.
self.force_clear_cookie(self.cookie_name)
self.clear_cookie("_xsrf")

def get_current_user(self):
clsname = self.__class__.__name__
Expand Down