diff options
| author | Dennis Fink | 2026-10-31 19:22:11 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-10-31 19:22:11 +0100 |
| commit | 40bdba0f2aa132f47326d2591e83039249ae2121 (patch) | |
| tree | db45887ea64777ecd1e5e970333c87730bc7b531 /webmentions_ssg/tasks | |
| parent | 3d6ee99142fbcc7fabaeab770a9c9e9d090ddf0f (diff) | |
| download | webmentions-ssg-40bdba0f2aa132f47326d2591e83039249ae2121.tar.gz webmentions-ssg-40bdba0f2aa132f47326d2591e83039249ae2121.zip | |
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.
Diffstat (limited to '')
| -rw-r--r-- | webmentions_ssg/tasks/sender.py | 42 |
1 files changed, 28 insertions, 14 deletions
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 |
