From 6924ad7e52033365c55d5afacdd916c502cc80cb Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 31 Oct 2026 17:42:00 +0100 Subject: feat(receiver): add resource limits and retention Bound incoming request and URL sizes so untrusted Webmention submissions cannot consume unbounded application or database resources. Purge old failed and deleted received Webmentions on a schedule, and use portable SHA-256 URL fingerprints to preserve uniqueness for long URLs. --- tests/test_config.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/test_config.py') diff --git a/tests/test_config.py b/tests/test_config.py index dd02c01..933f437 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -232,3 +232,25 @@ def test_development_rejects_placeholder_even_with_debug(tmp_path: Path) -> None with pytest.raises(RuntimeError, match="SECRET_KEY"): create_app(LocalDevelopment) + + +def test_resource_limits_have_safe_defaults() -> None: + assert DefaultConfig.MAX_CONTENT_LENGTH == 64 * 1024 + assert DefaultConfig.MAX_WEBMENTION_URL_BYTES == 8192 + assert DefaultConfig.RECEIVED_RETENTION_DAYS == 30 + assert DefaultConfig.RECEIVED_RETENTION_SCHEDULE == "0 3 * * *" + + +@pytest.mark.parametrize( + "key", ["MAX_CONTENT_LENGTH", "MAX_WEBMENTION_URL_BYTES", "RECEIVED_RETENTION_DAYS"] +) +@pytest.mark.parametrize("value", [None, "100", 0, -1, True, 1.5]) +def test_invalid_resource_limits_fail_at_startup( + tmp_path: Path, key: str, value: object +) -> None: + class InvalidResourceLimit(TestingConfig): + LOG_FILE = str(tmp_path / "invalid-resource.log") + + setattr(InvalidResourceLimit, key, value) + with pytest.raises(ValueError, match=key): + create_app(InvalidResourceLimit) -- cgit v1.3.1