diff options
| author | Dennis Fink | 2026-10-31 19:15:57 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-10-31 19:15:57 +0100 |
| commit | 3d6ee99142fbcc7fabaeab770a9c9e9d090ddf0f (patch) | |
| tree | 52a304df07ef7fcdca1f6a139b94af6c23a15558 /webmentions_ssg/config.py | |
| parent | 0afc76fb78518bf8185c02e548e83e63c8bb0153 (diff) | |
| download | webmentions-ssg-3d6ee99142fbcc7fabaeab770a9c9e9d090ddf0f.tar.gz webmentions-ssg-3d6ee99142fbcc7fabaeab770a9c9e9d090ddf0f.zip | |
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.
Diffstat (limited to '')
| -rw-r--r-- | webmentions_ssg/config.py | 19 |
1 files changed, 19 insertions, 0 deletions
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 |
