From 40bdba0f2aa132f47326d2591e83039249ae2121 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Sat, 31 Oct 2026 19:22:11 +0100 Subject: fix(sender): treat malformed requests as terminal failures Reject invalid stored targets and local URL or protocol errors as permanent failures so unrecoverable requests do not consume the sender retry budget. Preserve the recorded attempt state while preventing duplicate retries for the same source revision. --- webmentions_ssg/tasks/sender.py | 42 +++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) (limited to 'webmentions_ssg') diff --git a/webmentions_ssg/tasks/sender.py b/webmentions_ssg/tasks/sender.py index 4da1a5c..9330247 100644 --- a/webmentions_ssg/tasks/sender.py +++ b/webmentions_ssg/tasks/sender.py @@ -422,6 +422,9 @@ def send_webmention_task(webmention_uuid: uuid.UUID) -> None: response_status: int | None = None try: + if not is_http_url(target): + raise PermanentSenderError(f"Invalid target URL: {target!r}") + with httpx.Client( headers={"User-Agent": (f"{APP_NAME}/{VERSION} SentWebmention")}, timeout=httpx.Timeout(current_app.config.get("REQUEST_TIMEOUT", 5.0)), @@ -460,6 +463,31 @@ def send_webmention_task(webmention_uuid: uuid.UUID) -> None: raise PermanentSenderError(message) + except ( + PermanentSenderError, + UnsafeAddressError, + httpx.InvalidURL, + httpx.UnsupportedProtocol, + httpx.LocalProtocolError, + ValueError, + UnicodeError, + ) as exc: + # Malformed URLs and local request/protocol errors cannot be repaired + # by retrying this source revision. InvalidURL is not a RequestError; + # protocol errors are, so handle them before the retryable branch. + if not attempt_is_current(webmention, revision): + return + + webmention.processed_revision = revision + webmention.next_retry_at = None + webmention.status = SentWebmentionStatus.FAILED + webmention.failure_reason = str(exc) or type(exc).__name__ + webmention.endpoint = endpoint + webmention.response_status = response_status + + db.session.commit() + return + except (TemporarySenderError, AddressResolutionError, httpx.RequestError) as exc: if not attempt_is_current(webmention, revision): return @@ -483,20 +511,6 @@ def send_webmention_task(webmention_uuid: uuid.UUID) -> None: # No Huey retries: only the scanner may requeue after next_retry_at. return - except (PermanentSenderError, UnsafeAddressError) as exc: - if not attempt_is_current(webmention, revision): - return - - webmention.processed_revision = revision - webmention.next_retry_at = None - webmention.status = SentWebmentionStatus.FAILED - webmention.failure_reason = str(exc) - webmention.endpoint = endpoint - webmention.response_status = response_status - - db.session.commit() - return - if not attempt_is_current(webmention, revision): return -- cgit v1.3.1