From 37ff61dfac640a6c48d708df1c2eceb678c8c4ad Mon Sep 17 00:00:00 2001 From: Ben Busby Date: Fri, 19 Apr 2024 12:49:52 -0600 Subject: [PATCH] Fall back to random secret key on permission exception Fixes #1136 --- app/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/__init__.py b/app/__init__.py index d84997a..db58385 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -101,7 +101,10 @@ if not os.path.exists(app.config['BUILD_FOLDER']): # Session values app_key_path = os.path.join(app.config['CONFIG_PATH'], 'whoogle.key') 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: app.config['SECRET_KEY'] = str(b64encode(os.urandom(32))) with open(app_key_path, 'w') as key_file: