Fall back to random secret key on permission exception

Fixes #1136
main
Ben Busby 2024-04-19 12:49:52 -06:00
parent 80e41e6b44
commit 37ff61dfac
No known key found for this signature in database
GPG Key ID: B9B7231E01D924A1
1 changed files with 4 additions and 1 deletions

View File

@ -101,7 +101,10 @@ if not os.path.exists(app.config['BUILD_FOLDER']):
# Session values # Session values
app_key_path = os.path.join(app.config['CONFIG_PATH'], 'whoogle.key') app_key_path = os.path.join(app.config['CONFIG_PATH'], 'whoogle.key')
if os.path.exists(app_key_path): if os.path.exists(app_key_path):
app.config['SECRET_KEY'] = open(app_key_path, 'r').read() try:
app.config['SECRET_KEY'] = open(app_key_path, 'r').read()
except PermissionError:
app.config['SECRET_KEY'] = str(b64encode(os.urandom(32)))
else: else:
app.config['SECRET_KEY'] = str(b64encode(os.urandom(32))) app.config['SECRET_KEY'] = str(b64encode(os.urandom(32)))
with open(app_key_path, 'w') as key_file: with open(app_key_path, 'w') as key_file: