File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 1010
1111import binascii
1212import datetime
13+ import hashlib
1314import json
1415import os
1516import re
@@ -610,6 +611,18 @@ def logout_available(self):
610611 """Whether a LogoutHandler is needed."""
611612 return True
612613
614+ def cookie_secret_hook (self , h : hashlib ._Hash ) -> hashlib ._Hash :
615+ """Update cookie secret input
616+
617+ Subclasses may call `h.update()` with any credentials that,
618+ when changed, should invalidate existing cookies, such as a
619+ password.
620+
621+ The updated hashlib object should be returned.
622+
623+ """
624+ return h
625+
613626
614627class PasswordIdentityProvider (IdentityProvider ):
615628 """A password identity provider."""
@@ -740,6 +753,14 @@ def validate_security(
740753 self .log .critical (_i18n ("\t $ python -m jupyter_server.auth password" ))
741754 sys .exit (1 )
742755
756+ def cookie_secret_hook (self , h : hashlib ._Hash ) -> hashlib ._Hash :
757+ """Include password in cookie secret.
758+
759+ This makes it so changing the password invalidates cookies.
760+ """
761+ h .update (self .hashed_password .encode ())
762+ return h
763+
743764
744765class LegacyIdentityProvider (PasswordIdentityProvider ):
745766 """Legacy IdentityProvider for use with custom LoginHandlers
Original file line number Diff line number Diff line change @@ -1169,6 +1169,7 @@ def _default_cookie_secret(self) -> bytes:
11691169 self ._write_cookie_secret_file (key )
11701170 h = hmac .new (key , digestmod = hashlib .sha256 )
11711171 h .update (self .password .encode ())
1172+ h = self .identity_provider .cookie_secret_hook (h )
11721173 return h .digest ()
11731174
11741175 def _write_cookie_secret_file (self , secret : bytes ) -> None :
You can’t perform that action at this time.
0 commit comments