From 3d6ee99142fbcc7fabaeab770a9c9e9d090ddf0f Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 31 Oct 2026 19:15:57 +0100 Subject: fix(sender): prevent source scanner path escapes Reject symlinked source files whose resolved targets leave the configured source directory so scans cannot read unintended files from the host filesystem. Normalize and validate ignored hostname patterns at startup and again at scan time to keep scanner filtering predictable. --- webmentions_ssg/config.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'webmentions_ssg/config.py') diff --git a/webmentions_ssg/config.py b/webmentions_ssg/config.py index e91c651..b1d588b 100644 --- a/webmentions_ssg/config.py +++ b/webmentions_ssg/config.py @@ -22,6 +22,24 @@ def normalize_allowed_hostnames(value: object) -> set[str]: return hostnames +def normalize_ignored_hostnames(value: object) -> tuple[str, ...]: + """Validate and normalize hostname patterns ignored by the source scanner.""" + if not isinstance(value, (list, tuple, set, frozenset)): + raise TypeError( + "IGNORED_HOSTNAMES must be a list, tuple, or set of hostname patterns, " + "not a string." + ) + + patterns: set[str] = set() + for pattern in value: + if not isinstance(pattern, str) or not ( + normalized := pattern.strip().lower().rstrip(".") + ): + raise ValueError("IGNORED_HOSTNAMES must contain non-empty strings only.") + patterns.add(normalized) + return tuple(sorted(patterns)) + + class DefaultConfig: TESTING = False DEBUG = False @@ -62,6 +80,7 @@ class DefaultConfig: SOURCE_DIRECTORY = None SOURCE_BASE_URL = None + IGNORED_HOSTNAMES = () SCANNER_SCHEDULE = "0 * * * *" # Total send attempts per source revision (not additional retries). SEND_MAX_ATTEMPTS = 6 -- cgit v1.3.1