From eb404d9a1a328278c92753e65100579e7ad98e48 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Mon, 16 Nov 2026 08:57:31 +0100 Subject: refactor(core): organize configuration by subsystem Group default and example settings into consistent application, security, networking, receiver, scanner, sender, rate-limit, and mail sections. Reorder configuration declarations without changing their values or behavior. --- webmentions_ssg/config.py | 82 ++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 33 deletions(-) (limited to 'webmentions_ssg/config.py') diff --git a/webmentions_ssg/config.py b/webmentions_ssg/config.py index 15667ab..2110a62 100644 --- a/webmentions_ssg/config.py +++ b/webmentions_ssg/config.py @@ -13,56 +13,87 @@ MIN_SECRET_KEY_LENGTH = 32 class DefaultConfig: + # Application TESTING = False DEBUG = False - # Production must provide a persistent, random key through configuration. - SECRET_KEY = None BOOTSTRAP_SERVE_LOCAL = True # BOOTSTRAP_BOOTSWATCH_THEME = "Materia" + + # Security and reverse proxy + # Production must provide a persistent, random key through configuration. + SECRET_KEY = None # Secure by default; deployment configuration can override these values. SESSION_COOKIE_SECURE = True SESSION_COOKIE_HTTPONLY = True SESSION_COOKIE_SAMESITE = "Lax" + # Number of trusted reverse-proxy hops for X-Forwarded-For/Proto. + # 0 (default) means forwarded headers are not trusted. + PROXY_FIX_TRUSTED_HOPS = 0 + + # Database + SQLALCHEMY_DATABASE_URI = "sqlite:///webmentions-ssg.db" + + # Logging LOG_FILE = "/var/log/webmentions-ssg.log" - LOG_FORMAT = "[%(asctime)s]:%(levelname)s:%(name)s %(message)s" LOG_LEVEL = logging.INFO + LOG_FORMAT = "[%(asctime)s]:%(levelname)s:%(name)s %(message)s" LOG_FILE_MAX_BYTES = 20_000_000 LOG_FILE_BACKUP_COUNT = 10 - SQLALCHEMY_DATABASE_URI = "sqlite:///webmentions-ssg.db" + # Background tasks (Huey) + # HUEY_URL is intentionally unset; production must configure a persistent queue. + + # Outbound HTTP requests (shared by receiver and sender) + REQUEST_TIMEOUT_SECONDS = 5.0 + # Absolute wall-clock budget for each verification or delivery attempt. + REQUEST_TOTAL_TIMEOUT_SECONDS = 30.0 + MAX_REDIRECTS = 20 + + # Receiver # Empty by default: no target hostnames are accepted until configured. ALLOWED_TARGET_HOSTNAMES = frozenset() # Cap incoming HTTP request bodies (also applies to other Flask routes). MAX_CONTENT_LENGTH = 64 * 1024 # Independent UTF-8 byte limit for each submitted source/target URL. MAX_WEBMENTION_URL_BYTES = 8192 - # Purge terminal failed/source-removed received Webmentions after 30 days. - RECEIVED_RETENTION_DAYS = 30 - RECEIVED_RETENTION_SCHEDULE = "0 3 * * *" - MAX_REDIRECTS = 20 MAX_RECEIVED_SOURCE_BYTES = 1_000_000 - MAX_DISCOVERY_TARGET_BYTES = 1_000_000 - REQUEST_TIMEOUT_SECONDS = 5.0 - # Absolute wall-clock budget for each verification or delivery attempt. - REQUEST_TOTAL_TIMEOUT_SECONDS = 30.0 # Requeue abandoned verification attempts after 15 minutes. VERIFICATION_STALE_AFTER_SECONDS = 900 # Maximum automatic recoveries of a stale received/verifying row. VERIFICATION_MAX_RECOVERIES = 3 VERIFICATION_RECOVERY_SCHEDULE = "*/5 * * * *" + # Purge terminal failed/source-removed received Webmentions after 30 days. + RECEIVED_RETENTION_DAYS = 30 + RECEIVED_RETENTION_SCHEDULE = "0 3 * * *" + # Scanner SITE_OUTPUT_DIRECTORY = None SITE_BASE_URL = None - IGNORED_TARGET_HOSTNAMES = () SOURCE_SCAN_SCHEDULE = "0 * * * *" + + # Sender + IGNORED_TARGET_HOSTNAMES = () + MAX_DISCOVERY_TARGET_BYTES = 1_000_000 # Total send attempts per source revision (not additional retries). SEND_MAX_ATTEMPTS = 6 SEND_RETRY_BASE_SECONDS = 3600 SEND_RETRY_MAX_SECONDS = 86400 + # Rate limiting + RATELIMIT_STORAGE_URI = "memory://" + RATELIMIT_HEADERS_ENABLED = True + ENDPOINT_RATE_LIMIT = "10/minute;100/hour" + ENDPOINT_GLOBAL_RATE_LIMIT = "1000/hour" + ENDPOINT_REVERIFY_COOLDOWN_SECONDS = 600 + LOGIN_RATE_LIMIT = "5/minute;30/hour" + # Separate cross-IP limit for each submitted username (hashed in storage). + LOGIN_USERNAME_RATE_LIMIT = "20/minute;100/hour" + + # Email notifications DIGEST_EMAIL = None DIGEST_SCHEDULE = "0 8 * * *" + # Mail (SMTP) MAIL_SERVER = "localhost" MAIL_PORT = 25 MAIL_USE_TLS = False @@ -71,21 +102,6 @@ class DefaultConfig: MAIL_PASSWORD = None MAIL_DEFAULT_SENDER = None - # Number of trusted reverse-proxy hops for X-Forwarded-For/Proto. - # 0 (default) means forwarded headers are not trusted. - PROXY_FIX_TRUSTED_HOPS = 0 - - RATELIMIT_STORAGE_URI = "memory://" - RATELIMIT_HEADERS_ENABLED = True - - ENDPOINT_RATE_LIMIT = "10/minute;100/hour" - ENDPOINT_GLOBAL_RATE_LIMIT = "1000/hour" - ENDPOINT_REVERIFY_COOLDOWN_SECONDS = 600 - - LOGIN_RATE_LIMIT = "5/minute;30/hour" - # Separate cross-IP limit for each submitted username (hashed in storage). - LOGIN_USERNAME_RATE_LIMIT = "20/minute;100/hour" - class DevelopmentConfig(DefaultConfig): DEBUG = True @@ -103,17 +119,17 @@ class ProductionConfig(DefaultConfig): class TestingConfig(DefaultConfig): TESTING = True - SESSION_COOKIE_SECURE = False - - SECRET_KEY = "testing-secret-key" WTF_CSRF_ENABLED = False - LOG_FILE = "testing/webmentions-ssg-tests.log" - LOG_LEVEL = logging.DEBUG + SECRET_KEY = "testing-secret-key" + SESSION_COOKIE_SECURE = False SQLALCHEMY_DATABASE_URI = "sqlite:///:memory:" SQLALCHEMY_TRACK_MODIFICATIONS = False + LOG_FILE = "testing/webmentions-ssg-tests.log" + LOG_LEVEL = logging.DEBUG + HUEY_URL = "memory://" ALLOWED_TARGET_HOSTNAMES = frozenset({"dennisfink.me"}) -- cgit v1.3.1