From 13a9d9ddce09230017699bc34ac3bf08ed2f84ed Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 30 Oct 2026 20:31:43 +0100 Subject: fix(core): prevent DNS rebinding in HTTP requests Pin outbound connections to validated public IP addresses so DNS changes cannot redirect receiver or sender requests onto private or link-local networks. Apply the same protection across redirects, add an overall request deadline, and keep DNS resolution out of synchronous endpoint form validation. --- tests/tasks/test_sender.py | 37 ------------------------------------- 1 file changed, 37 deletions(-) (limited to 'tests/tasks/test_sender.py') diff --git a/tests/tasks/test_sender.py b/tests/tasks/test_sender.py index 0db0d8c..38bae11 100644 --- a/tests/tasks/test_sender.py +++ b/tests/tasks/test_sender.py @@ -1214,43 +1214,6 @@ def test_send_webmention_ignores_unknown_identifier( assert f"Cannot send unknown SentWebmention {identifier}" in caplog.text -def test_ensure_public_request_accepts_public_url( - sender_module: ModuleType, monkeypatch: pytest.MonkeyPatch -) -> None: - is_public_url = Mock(return_value=True) - monkeypatch.setattr(sender_module, "is_public_url", is_public_url) - sender_module.ensure_public_request(httpx.Request("GET", TARGET_URL)) - is_public_url.assert_called_once_with(TARGET_URL) - - -def test_ensure_public_request_rejects_non_public_address( - sender_module: ModuleType, monkeypatch: pytest.MonkeyPatch -) -> None: - is_public_url = Mock(return_value=False) - monkeypatch.setattr(sender_module, "is_public_url", is_public_url) - with pytest.raises( - sender_module.PermanentSenderError, - match="Request resolves to a non-public address", - ): - sender_module.ensure_public_request(httpx.Request("GET", TARGET_URL)) - is_public_url.assert_called_once_with(TARGET_URL) - - -def test_ensure_public_request_maps_dns_failure_to_temporary_error( - sender_module: ModuleType, monkeypatch: pytest.MonkeyPatch -) -> None: - is_public_url = Mock( - side_effect=AddressResolutionError("Could not resolve hostname") - ) - monkeypatch.setattr(sender_module, "is_public_url", is_public_url) - with pytest.raises( - sender_module.TemporarySenderError, - match="Request hostname could not be resolved", - ): - sender_module.ensure_public_request(httpx.Request("GET", TARGET_URL)) - is_public_url.assert_called_once_with(TARGET_URL) - - def test_resolve_endpoint_rejects_invalid_url( sender_module: ModuleType, monkeypatch: pytest.MonkeyPatch ) -> None: -- cgit v1.3.1