aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg/__init__.py
diff options
context:
space:
mode:
authorDennis Fink2026-10-30 08:35:46 +0100
committerDennis Fink2026-10-30 08:41:42 +0100
commit4485aeb573ceb37237ea1fbc80665ed6c4136116 (patch)
treebce18a2c7fadd657d9f9809ebbc65d06c6cc4dc4 /webmentions_ssg/__init__.py
parent9f093cf07a3531ee4b7d02c20151e21c141a93de (diff)
downloadwebmentions-ssg-4485aeb573ceb37237ea1fbc80665ed6c4136116.tar.gz
webmentions-ssg-4485aeb573ceb37237ea1fbc80665ed6c4136116.zip
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.
Diffstat (limited to '')
-rw-r--r--webmentions_ssg/__init__.py16
1 files changed, 14 insertions, 2 deletions
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