Skip to content

Commit d20e36f

Browse files
meeseeksdev[bot]gnestor
meeseeksdev[bot]
authored andcommitted
Backport PR #2959: set cookie on base_url (#3090)
1 parent 4dc145b commit d20e36f

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

notebook/auth/login.py

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def set_login_cookie(cls, handler, user_id=None):
9494
# 'secure' kwarg is passed to set_secure_cookie
9595
if handler.settings.get('secure_cookie', handler.request.protocol == 'https'):
9696
cookie_options.setdefault('secure', True)
97+
cookie_options.setdefault('path', handler.base_url)
9798
handler.set_secure_cookie(handler.cookie_name, user_id, **cookie_options)
9899
return user_id
99100

notebook/base/handlers.py

+9-3
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,16 @@ def set_default_headers(self):
8989
# if method is unsupported (websocket and Access-Control-Allow-Origin
9090
# for example, so just ignore)
9191
self.log.debug(e)
92-
92+
9393
def clear_login_cookie(self):
94-
self.clear_cookie(self.cookie_name)
95-
94+
cookie_options = self.settings.get('cookie_options', {})
95+
path = cookie_options.setdefault('path', self.base_url)
96+
self.clear_cookie(self.cookie_name, path=path)
97+
if path and path != '/':
98+
# also clear cookie on / to ensure old cookies
99+
# are cleared after the change in path behavior.
100+
self.clear_cookie(self.cookie_name)
101+
96102
def get_current_user(self):
97103
if self.login_handler is None:
98104
return 'anonymous'

0 commit comments

Comments
 (0)