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. --- contrib/webmentions-ssg.example.cfg | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'contrib/webmentions-ssg.example.cfg') diff --git a/contrib/webmentions-ssg.example.cfg b/contrib/webmentions-ssg.example.cfg index d92726e..d214312 100644 --- a/contrib/webmentions-ssg.example.cfg +++ b/contrib/webmentions-ssg.example.cfg @@ -15,27 +15,13 @@ BOOTSTRAP_SERVE_LOCAL = True # BOOTSTRAP_BOOTSWATCH_THEME = "Materia" # --------------------------------------------------------------------------- -# Flask / Security +# Flask / Security # --------------------------------------------------------------------------- -# Generate a persistent random key, e.g.: +# Generate a persistent random key, e.g.: # python -c 'import secrets; print(secrets.token_urlsafe(32))' # Never commit your real key or SMTP password to version control. SECRET_KEY = "REPLACE_WITH_A_LONG_RANDOM_SECRET" -# Only transmit session cookies over HTTPS connections. -# Recommended for production deployments using HTTPS. -# Set to False only when developing locally over plain HTTP. -SESSION_COOKIE_SECURE = True - -# Prevent JavaScript from accessing session cookies via document.cookie. -# Helps protect session cookies from theft through XSS attacks. -SESSION_COOKIE_HTTPONLY = True - -# Restrict session cookies to same-site requests to help mitigate CSRF. -# "Lax" allows normal navigation from external sites while restricting -# cookies on most cross-site requests. -SESSION_COOKIE_SAMESITE = "Lax" - # --------------------------------------------------------------------------- # Database and logging # --------------------------------------------------------------------------- @@ -63,6 +49,23 @@ REQUEST_TIMEOUT = 5.0 # seconds; also used for outgoing requests MAX_REDIRECTS = 20 # also used for outgoing requests MAX_SOURCE_BYTES = 1_000_000 +# --------------------------------------------------------------------------- +# Rate limiting +# --------------------------------------------------------------------------- +# In-memory storage is for development/testing ONLY. Production requires shared +# storage, such as Redis, or the application will refuse to start. +RATELIMIT_STORAGE_URI = "memory://" +RATELIMIT_HEADERS_ENABLED = True + +# Limits per client and across all clients for incoming Webmention submissions. +ENDPOINT_RATE_LIMIT = "10/minute;100/hour" +ENDPOINT_GLOBAL_RATE_LIMIT = "1000/hour" +# Minimum seconds between verifications of the same source/target pair. +ENDPOINT_REVERIFY_COOLDOWN_SECONDS = 600 + +# Limit login POST attempts per client. +LOGIN_RATE_LIMIT = "5/minute;30/hour" + # --------------------------------------------------------------------------- # Sending Webmentions from a statically generated site # --------------------------------------------------------------------------- @@ -92,6 +95,8 @@ HUEY_URL = "redis://127.0.0.1:6379/0" # --------------------------------------------------------------------------- # Set NOTIFICATION_EMAIL = None to disable notification emails. NOTIFICATION_EMAIL = "admin@example.com" +# Daily notification digest at 08:00 UTC (Huey defaults to UTC). +NOTIFICATION_SCHEDULE = "0 8 * * *" # Example SMTP-over-STARTTLS setup; adapt to your mail provider. MAIL_SERVER = "smtp.example.com" -- cgit v1.3.1