aboutsummaryrefslogtreecommitdiff
path: root/tests/test_config.py
diff options
context:
space:
mode:
authorDennis Fink2026-10-31 19:15:57 +0100
committerDennis Fink2026-10-31 19:15:57 +0100
commit3d6ee99142fbcc7fabaeab770a9c9e9d090ddf0f (patch)
tree52a304df07ef7fcdca1f6a139b94af6c23a15558 /tests/test_config.py
parent0afc76fb78518bf8185c02e548e83e63c8bb0153 (diff)
downloadwebmentions-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 'tests/test_config.py')
-rw-r--r--tests/test_config.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/test_config.py b/tests/test_config.py
index 933f437..aae7cce 100644
--- a/tests/test_config.py
+++ b/tests/test_config.py
@@ -75,6 +75,7 @@ def test_endpoint_limits_are_inherited_from_defaults() -> None:
assert config.REQUEST_TOTAL_TIMEOUT == 30.0
assert DefaultConfig.ALLOWED_HOSTNAMES == set()
+ assert DefaultConfig.IGNORED_HOSTNAMES == ()
def test_allowed_hostnames_are_normalized_at_startup(tmp_path: Path) -> None:
@@ -124,6 +125,39 @@ def test_invalid_allowed_hostnames_fail_at_startup(
create_app(InvalidHostnameConfig)
+def test_ignored_hostnames_are_normalized_at_startup(tmp_path: Path) -> None:
+ class MixedCaseConfig(TestingConfig):
+ LOG_FILE = str(tmp_path / "test.log")
+ IGNORED_HOSTNAMES = [" Example.COM. ", "*.EXAMPLE.com.", "example.com"]
+
+ app = create_app(MixedCaseConfig)
+ assert app.config["IGNORED_HOSTNAMES"] == ("*.example.com", "example.com")
+
+
+@pytest.mark.parametrize(
+ "hostnames,expected_exception",
+ [
+ ("example.com", TypeError),
+ (None, TypeError),
+ ({"example.com": True}, TypeError),
+ (123, TypeError),
+ (["example.com", None], ValueError),
+ (["example.com", ""], ValueError),
+ (["example.com", " "], ValueError),
+ (["example.com", "..."], ValueError),
+ ],
+)
+def test_invalid_ignored_hostnames_fail_at_startup(
+ tmp_path: Path, hostnames: object, expected_exception: type[Exception]
+) -> None:
+ class InvalidHostnameConfig(TestingConfig):
+ LOG_FILE = str(tmp_path / "test.log")
+ IGNORED_HOSTNAMES = hostnames
+
+ with pytest.raises(expected_exception, match="IGNORED_HOSTNAMES"):
+ create_app(InvalidHostnameConfig)
+
+
def test_production_requires_nonempty_allowed_hostnames(tmp_path: Path) -> None:
config_path = tmp_path / "production.cfg"
config_path.write_text(