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

Hash cookie secret with user hashed password. #3009

Merged
merged 1 commit into from
Nov 3, 2017
Merged

Conversation

Carreau
Copy link
Member

@Carreau Carreau commented Nov 2, 2017

Currently changing the password does not revoke current session:

  • jupyter notebook password
  • jupyter notebook
  • Logging in
  • Kill server
  • jupyter notebook password
  • jupyter notebook
  • Oh ! I'm still logged in.

With this, as the "effective" secret depends on the (hashed) password,
changing it void any existing session (which I believe is the goal of
most password change)

cc @minrk, @rgbkrk, and @yuvipanda for review.

return secret
key = encodebytes(os.urandom(1024))
self._write_cookie_secret_file(key)
h = sha256(digest_size=len(key))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to make a comment here about what happens if the cookie file happened to be empty (leading to a 0 length), then I noticed that at least on my systems I can't set this keyword argument:

In [1]: from hashlib import sha256

In [2]: sha256(digest_size=0)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-2-94e5dda9a83d> in <module>()
----> 1 sha256(digest_size=0)

TypeError: openssl_sha256() takes no keyword arguments

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hum, weird.

self._write_cookie_secret_file(key)
h = sha256(digest_size=len(key))
h.update(key)
h.update(self.password.encode())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO this should be a HMAC, with the secret key as the HMAC key & the password as the message. HMACs are built for this exact specific use case, and supported in the stdlib.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I disagree that HMAC are built for that (no code is going to check hmac(key, pw) equal the value here). The result of this function will be used by HMAC as the key later on (in tornado), so we're basically doing HMAC(HMAC(key, pwd_sha), cookie_value); Though I agree that the returned value with HMAC will still be (pseudo-)random enough.

Currently changing the password does not revoke current session:

  - jupyter notebook password <password1>
  - jupyter notebook
  - Logging in
  - Kill server
  - jupyter notebook password <other password>
  - jupyter notebook
  - Oh ! I'm still logged in.

With this, as the "effective" secret depends on the (hashed) password,
changing it void any existing session (which I believe is the goal of
most password change)
@Carreau
Copy link
Member Author

Carreau commented Nov 2, 2017

Should we also (or as an alternative) have the the jupyter notebook password command to regenerate the cookie secret ? Because If I change my password to an old one, then the previous sessions will become valid again. Or is this a "feature" ?

@minrk minrk merged commit 9a05f28 into jupyter:master Nov 3, 2017
@takluyver takluyver added this to the 5.3 milestone Jan 17, 2018
@Carreau Carreau deleted the hashpw branch August 25, 2018 19:26
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants