From 394e128e9fd5dbf68ed293f787e09eeaca57723b Mon Sep 17 00:00:00 2001 From: cellarspoon Date: Fri, 17 Dec 2021 17:37:48 +0100 Subject: [PATCH] random generation of secrets --- app.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index 74b0df7..105030d 100644 --- a/app.py +++ b/app.py @@ -1,4 +1,6 @@ import os +import random +import string from pathlib import Path import petname @@ -11,9 +13,15 @@ from werkzeug.utils import secure_filename from wtforms import HiddenField, RadioField, StringField from wtforms.validators import DataRequired + +def rand(): + """Generated random secret.""" + return "".join(random.choices(string.ascii_uppercase + string.digits, k=N)) + + app = Flask(__name__) -app.config["SECRET_KEY"] = "foo" -app.config["WTF_CSRF_SECRET_KEY"] = "bar" +app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY", rand()) +app.config["WTF_CSRF_SECRET_KEY"] = os.environ.get("WTF_CSRF_SECRET_KEY", rand()) CWD = Path().resolve()