Skip to content

Commit 8601a14

Browse files
committed
Warn when both encrypted and unencrypted secret are present
1 parent 2de5d0a commit 8601a14

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

emailproxy.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__author__ = 'Simon Robinson'
77
__copyright__ = 'Copyright (c) 2023 Simon Robinson'
88
__license__ = 'Apache 2.0'
9-
__version__ = '2023-12-21' # ISO 8601 (YYYY-MM-DD)
9+
__version__ = '2023-12-22' # ISO 8601 (YYYY-MM-DD)
1010
__package_version__ = '.'.join([str(int(i)) for i in __version__.split('-')]) # for pyproject.toml usage only
1111

1212
import abc
@@ -751,12 +751,18 @@ def get_account_with_catch_all_fallback(option):
751751

752752
try:
753753
# if both secret values are present we use the unencrypted version (as it may have been user-edited)
754-
if client_secret_encrypted and not client_secret:
755-
try:
756-
client_secret = cryptographer.decrypt(client_secret_encrypted)
757-
except InvalidToken as e: # needed to avoid looping as we don't remove secrets on decryption failure
758-
Log.error('Invalid password to decrypt', username, 'secret - aborting login:', Log.error_string(e))
759-
return False, '%s: Login failed - the password for account %s is incorrect' % (APP_NAME, username)
754+
if client_secret_encrypted:
755+
if not client_secret:
756+
try:
757+
client_secret = cryptographer.decrypt(client_secret_encrypted)
758+
except InvalidToken as e: # needed to avoid looping (we don't remove secrets on decryption failure)
759+
Log.error('Invalid password to decrypt', username, 'secret - aborting login:',
760+
Log.error_string(e))
761+
return False, '%s: Login failed - the password for account %s is incorrect' % (
762+
APP_NAME, username)
763+
else:
764+
Log.info('Warning: found both `client_secret_encrypted` and `client_secret` for account', username,
765+
' - the un-encrypted value will be used. Removing the un-encrypted value is recommended')
760766

761767
if access_token or refresh_token: # if possible, refresh the existing token(s)
762768
if not access_token or access_token_expiry - current_time < TOKEN_EXPIRY_MARGIN:

0 commit comments

Comments
 (0)