Skip to content

Commit 6d45dd4

Browse files
Ensure master password pop up is not shown on setting MASTER_PASSWORD_REQUIRED to false. #8299
1 parent b22bfdf commit 6d45dd4

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

web/pgadmin/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,9 @@ def before_request():
835835
# but the user session may still be active. Logout the user
836836
# to get the key again when login
837837
if config.SERVER_MODE and current_user.is_authenticated and \
838-
session['auth_source_manager']['current_source'] not in [
839-
KERBEROS, OAUTH2, WEBSERVER] and \
838+
'auth_source_manager' in session and \
839+
session['auth_source_manager']['current_source'] not in \
840+
[KERBEROS, OAUTH2, WEBSERVER] and \
840841
current_app.keyManager.get() is None and \
841842
request.endpoint not in ('security.login', 'security.logout'):
842843
logout_user()

web/pgadmin/utils/master_password.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,23 @@ def get_crypt_key():
2828
:return: the key
2929
"""
3030
enc_key = current_app.keyManager.get()
31-
# if desktop mode and master pass and local os secret is
32-
# disabled then use the password hash
33-
if not config.MASTER_PASSWORD_REQUIRED and\
34-
not config.USE_OS_SECRET_STORAGE and not config.SERVER_MODE:
35-
return True, current_user.password
36-
# if desktop mode and master pass enabled
37-
elif (config.MASTER_PASSWORD_REQUIRED or config.USE_OS_SECRET_STORAGE) \
38-
and enc_key is None:
39-
return False, None
40-
elif not config.MASTER_PASSWORD_REQUIRED and config.SERVER_MODE and \
41-
'pass_enc_key' in session:
42-
return True, session['pass_enc_key']
31+
if config.SERVER_MODE:
32+
if config.MASTER_PASSWORD_REQUIRED and enc_key is None:
33+
return False, None
34+
if 'pass_enc_key' in session:
35+
return True, session['pass_enc_key']
4336
else:
44-
return True, enc_key
37+
# if desktop mode and master pass and
38+
# local os secret is disabled then use the password hash
39+
if not config.MASTER_PASSWORD_REQUIRED and\
40+
not config.USE_OS_SECRET_STORAGE:
41+
return True, current_user.password
42+
# and master pass enabled or local os secret enabled
43+
# but enc key is none
44+
if (config.MASTER_PASSWORD_REQUIRED or config.USE_OS_SECRET_STORAGE) \
45+
and enc_key is None:
46+
return False, None
47+
return True, enc_key
4548

4649

4750
def get_master_password_key_from_os_secret():
@@ -79,7 +82,7 @@ def validate_master_password(password):
7982
else:
8083
return True
8184
except Exception:
82-
False
85+
return False
8386

8487

8588
def set_masterpass_check_text(password, clear=False):

0 commit comments

Comments
 (0)