aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/__init__.py
diff options
context:
space:
mode:
authorDennis Fink2026-10-31 16:42:44 +0100
committerDennis Fink2026-10-31 16:42:44 +0100
commit3494eab1208dc18478485e02c61e292556502fa6 (patch)
tree5d9e95d709b119a0245d0294837f9b6a7e38bff1 /webmentions_ssg/__init__.py
parentfdb1762715658eae987dd104a0e6d3cb92a4a8d7 (diff)
downloadwebmentions-ssg-3494eab1208dc18478485e02c61e292556502fa6.tar.gz
webmentions-ssg-3494eab1208dc18478485e02c61e292556502fa6.zip
fix(core): harden session and credential security
Require persistent non-placeholder signing keys outside local development and bind login sessions to the current password hash so password changes revoke existing cookies. Enforce a minimal password policy for user administration while preserving long Unicode passphrases without arbitrary composition limits.
Diffstat (limited to 'webmentions_ssg/__init__.py')
-rw-r--r--webmentions_ssg/__init__.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/webmentions_ssg/__init__.py b/webmentions_ssg/__init__.py
index 518add0..51635ef 100644
--- a/webmentions_ssg/__init__.py
+++ b/webmentions_ssg/__init__.py
@@ -27,6 +27,7 @@ from webmentions_ssg.config import (
normalize_allowed_hostnames,
)
+from .security import validate_secret_key
from .tasks import Huey
from .url_security import is_http_url
@@ -82,6 +83,16 @@ def create_app(config_class: type[DefaultConfig] | None = None) -> Flask:
app.config.from_prefixed_env(prefix="FLASK")
app.config.from_prefixed_env(prefix="WEBMENTIONS_SSG")
+ # A fixed key is convenient only for local debugging. All other
+ # deployments must supply their own persistent, random signing key.
+ using_local_dev_key = (
+ issubclass(config_class, DevelopmentConfig)
+ and app.debug
+ and app.config.get("SECRET_KEY") == DevelopmentConfig.SECRET_KEY
+ )
+ if not app.testing and not using_local_dev_key:
+ validate_secret_key(app.config.get("SECRET_KEY"))
+
app.config["ALLOWED_HOSTNAMES"] = normalize_allowed_hostnames(
app.config["ALLOWED_HOSTNAMES"]
)