From 3494eab1208dc18478485e02c61e292556502fa6 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 31 Oct 2026 16:42:44 +0100 Subject: 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. --- webmentions_ssg/__init__.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'webmentions_ssg/__init__.py') 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"] ) -- cgit v1.3.1