From a662ceb28e5224ab841944077b9e821f613a163e Mon Sep 17 00:00:00 2001
From: Julian Rother <julian@cccv.de>
Date: Fri, 23 Feb 2024 23:39:53 +0100
Subject: [PATCH] Fix SECRET_KEY auto-generation in debug mode

Compatibility fix for Flask v2 (Debian Bookworm) and newer
---
 uffd/__init__.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/uffd/__init__.py b/uffd/__init__.py
index b669c00..f901548 100644
--- a/uffd/__init__.py
+++ b/uffd/__init__.py
@@ -46,9 +46,10 @@ def init_config(app: Flask, test_config):
 			if load_config_file(app, os.path.join(app.instance_path, filename), silent=True):
 				break
 
-	if app.env == "production" and app.secret_key is None:
-		raise Exception("SECRET_KEY not configured and we are running in production mode!")
-	app.config.setdefault("SECRET_KEY", secrets.token_hex(128))
+	if app.secret_key is None:
+		if app.env == "production":
+			raise Exception("SECRET_KEY not configured and we are running in production mode!")
+		app.secret_key = secrets.token_hex(128)
 
 def create_app(test_config=None): # pylint: disable=too-many-locals,too-many-statements
 	app = Flask(__name__, instance_relative_config=False)
-- 
GitLab