mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-18 11:55:46 +08:00
Merge pull request #3009 from Carreau/hashpw
Hash cookie secret with user hashed password.
This commit is contained in:
commit
9a05f28677
@ -27,6 +27,7 @@ import threading
|
||||
import time
|
||||
import warnings
|
||||
import webbrowser
|
||||
import hmac
|
||||
|
||||
try: #PY3
|
||||
from base64 import encodebytes
|
||||
@ -674,11 +675,16 @@ class NotebookApp(JupyterApp):
|
||||
def _default_cookie_secret(self):
|
||||
if os.path.exists(self.cookie_secret_file):
|
||||
with io.open(self.cookie_secret_file, 'rb') as f:
|
||||
return f.read()
|
||||
key = f.read()
|
||||
else:
|
||||
secret = encodebytes(os.urandom(1024))
|
||||
self._write_cookie_secret_file(secret)
|
||||
return secret
|
||||
key = encodebytes(os.urandom(1024))
|
||||
self._write_cookie_secret_file(key)
|
||||
h = hmac.HMAC(key)
|
||||
h.digest_size = len(key)
|
||||
h.update(self.password.encode())
|
||||
return h.digest()
|
||||
|
||||
|
||||
|
||||
def _write_cookie_secret_file(self, secret):
|
||||
"""write my secret to my secret_file"""
|
||||
|
Loading…
Reference in New Issue
Block a user