From 4485aeb573ceb37237ea1fbc80665ed6c4136116 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 30 Oct 2026 08:35:46 +0100 Subject: fix(core): harden application configuration Fail production startup when required configuration is missing, normalize allowed hostnames before validation, and move shared request limits into the default configuration so production does not depend on testing-only values. Set secure session cookie defaults while preserving explicit overrides and document the new rate-limit and notification settings in the example config. --- webmentions_ssg/__init__.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'webmentions_ssg/__init__.py') diff --git a/webmentions_ssg/__init__.py b/webmentions_ssg/__init__.py index c4ad4f6..518add0 100644 --- a/webmentions_ssg/__init__.py +++ b/webmentions_ssg/__init__.py @@ -20,7 +20,12 @@ from flask_sqlalchemy import SQLAlchemy from flask_wtf.csrf import CSRFProtect from sqlalchemy.orm import DeclarativeBase -from webmentions_ssg.config import DefaultConfig, DevelopmentConfig, ProductionConfig +from webmentions_ssg.config import ( + DefaultConfig, + DevelopmentConfig, + ProductionConfig, + normalize_allowed_hostnames, +) from .tasks import Huey from .url_security import is_http_url @@ -72,10 +77,17 @@ def create_app(config_class: type[DefaultConfig] | None = None) -> Flask: app.config.from_object(config_class) if not app.testing: - app.config.from_pyfile(app.config["CONFIG_FILE"], silent=True) + # Local development may omit its config file; production must not. + app.config.from_pyfile(app.config["CONFIG_FILE"], silent=app.debug) app.config.from_prefixed_env(prefix="FLASK") app.config.from_prefixed_env(prefix="WEBMENTIONS_SSG") + app.config["ALLOWED_HOSTNAMES"] = normalize_allowed_hostnames( + app.config["ALLOWED_HOSTNAMES"] + ) + if not app.testing and not app.debug and not app.config["ALLOWED_HOSTNAMES"]: + raise RuntimeError("Configure ALLOWED_HOSTNAMES before running in production.") + if ( not app.testing and not app.debug -- cgit v1.3.1