Skip to content

Commit cd79a98

Browse files
beledouxdenisZsailer
authored andcommitted
[FIX] notebookapp, auth: get_secure_cookie kwargs
Per Tornado's documentation: >By default, Tornado’s secure cookies expire after 30 days. >To change this, use the expires_days keyword argument to >set_secure_cookie and the max_age_days argument to get_secure_cookie. >These two values are passed separately so that you may >e.g. have a cookie that is valid for 30 days for most purposes, >but for certain sensitive actions >(such as changing billing information) >you use a smaller max_age_days when reading the cookie. With the current implementation in `auth/login.py`, this is possible to pass the `expires_days` option but not possible to enforce it as this is not possible to pass `max_age_days` to `get_secure_cookie` This makes impossible to set the cookie expiration without using a custom `LoginHandler`. This revision is about adding the possibility to pass options to Tornado's `get_secure_cookie` method, so it can be possible to set the cookies expiration, among others.
1 parent a80d7f0 commit cd79a98

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

jupyter_server/auth/login.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ def get_user(cls, handler):
166166
return handler._user_id
167167
user_id = cls.get_user_token(handler)
168168
if user_id is None:
169-
user_id = handler.get_secure_cookie(handler.cookie_name)
169+
get_secure_cookie_kwargs = handler.settings.get('get_secure_cookie_kwargs', {})
170+
user_id = handler.get_secure_cookie(handler.cookie_name, **get_secure_cookie_kwargs )
170171
else:
171172
cls.set_login_cookie(handler, user_id)
172173
# Record that the current request has been authenticated with a token.

jupyter_server/serverapp.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,10 @@ def _default_allow_remote(self):
931931
help=_("Extra keyword arguments to pass to `set_secure_cookie`."
932932
" See tornado's set_secure_cookie docs for details.")
933933
)
934+
get_secure_cookie_kwargs = Dict(config=True,
935+
help=_("Extra keyword arguments to pass to `get_secure_cookie`."
936+
" See tornado's get_secure_cookie docs for details.")
937+
)
934938
ssl_options = Dict(config=True,
935939
help=_("""Supply SSL options for the tornado HTTPServer.
936940
See the tornado docs for details."""))
@@ -1247,6 +1251,7 @@ def init_webapp(self):
12471251
self.tornado_settings['allow_origin_pat'] = re.compile(self.allow_origin_pat)
12481252
self.tornado_settings['allow_credentials'] = self.allow_credentials
12491253
self.tornado_settings['cookie_options'] = self.cookie_options
1254+
self.tornado_settings['get_secure_cookie_kwargs'] = self.get_secure_cookie_kwargs
12501255
self.tornado_settings['token'] = self.token
12511256
if (self.open_browser or self.file_to_run) and not self.password:
12521257
self.one_time_token = binascii.hexlify(os.urandom(24)).decode('ascii')

0 commit comments

Comments
 (0)