From df3b79e2c89978ec21dc2da7f90801dce33aeab2 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 31 Oct 2026 19:00:17 +0100 Subject: fix(receiver): prevent endless verification recovery Cap stale verification requeues so repeatedly lost or crashing tasks eventually become terminal failures instead of cycling indefinitely. Reject URLs that httpx cannot safely fetch before enqueueing, and persist unexpected verification errors as terminal failures. --- tests/forms/test_init.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'tests/forms/test_init.py') diff --git a/tests/forms/test_init.py b/tests/forms/test_init.py index 2a68509..42e6a2c 100644 --- a/tests/forms/test_init.py +++ b/tests/forms/test_init.py @@ -144,7 +144,7 @@ def test_endpoint_handles_malformed_ipv6_without_crashing(app: Flask) -> None: meta={"csrf": False}, ) assert not form.validate() - assert "Invalid input." in form.errors["target"] + assert "Invalid URL." in form.errors["target"] def test_endpoint_form_applies_configurable_url_byte_limit_to_both_fields( @@ -168,3 +168,38 @@ def test_endpoint_form_applies_configurable_url_byte_limit_to_both_fields( assert not form.validate() assert "target" in form.errors assert any("bytes" in message for message in form.errors["target"]) + + +@pytest.mark.parametrize("field_name", ["source", "target"]) +@pytest.mark.parametrize( + "invalid_url", + [ + pytest.param("http://ex☃mple.test/", id="invalid-idn"), + pytest.param("https://example.com/a\nb", id="newline"), + pytest.param("https://example.com/a\rb", id="carriage-return"), + pytest.param("https://example.com/\x00b", id="nul"), + pytest.param("https://example.com/a b", id="ascii-space"), + pytest.param("https://example.com/a\u00a0b", id="unicode-whitespace"), + pytest.param("https://example.com/\x7fb", id="del"), + ], +) +def test_endpoint_rejects_invalid_httpx_urls_and_whitespace( + app: Flask, field_name: str, invalid_url: str +) -> None: + data = {"source": VALID_SOURCE, "target": VALID_TARGET} + data[field_name] = invalid_url + with app.test_request_context("/endpoint", method="POST"): + form = EndpointForm(formdata=MultiDict(data), meta={"csrf": False}) + assert not form.validate() + assert "Invalid URL." in form.errors[field_name] + + +def test_endpoint_accepts_encoded_path_space(app: Flask) -> None: + with app.test_request_context("/endpoint", method="POST"): + form = EndpointForm( + formdata=MultiDict( + {"source": "https://source.example/a%20b", "target": VALID_TARGET} + ), + meta={"csrf": False}, + ) + assert form.validate() -- cgit v1.3.1