Skip to content

Commit 62f4888

Browse files
committed
Detect invalid/tampered token_salt (incorrect 3rd-party guide)
Closes #143
1 parent 56d89d1 commit 62f4888

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

emailproxy.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
__author__ = 'Simon Robinson'
77
__copyright__ = 'Copyright (c) 2022 Simon Robinson'
88
__license__ = 'Apache 2.0'
9-
__version__ = '2023-03-15' # ISO 8601 (YYYY-MM-DD)
9+
__version__ = '2023-03-22' # ISO 8601 (YYYY-MM-DD)
1010

1111
import abc
1212
import argparse
@@ -603,8 +603,12 @@ def get_account_with_catch_all_fallback(option):
603603
token_salt = base64.b64encode(os.urandom(16)).decode('utf-8')
604604

605605
# generate encrypter/decrypter based on password and random salt
606-
key_derivation_function = PBKDF2HMAC(algorithm=hashes.SHA256(), length=32,
607-
salt=base64.b64decode(token_salt.encode('utf-8')), iterations=100000,
606+
try:
607+
decoded_salt = base64.b64decode(token_salt.encode('utf-8')) # catch incorrect third-party proxy guide
608+
except binascii.Error:
609+
return (False, '%s: Invalid `token_salt` value found in config file entry for account %s - this value is '
610+
'not intended to be manually created; please remove and retry' % (APP_NAME, username))
611+
key_derivation_function = PBKDF2HMAC(algorithm=hashes.SHA256(), length=32, salt=decoded_salt, iterations=100000,
608612
backend=default_backend())
609613
fernet = Fernet(base64.urlsafe_b64encode(key_derivation_function.derive(password.encode('utf-8'))))
610614

0 commit comments

Comments
 (0)