diff options
| author | Dennis Fink | 2026-10-29 18:03:15 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-10-29 18:03:15 +0100 |
| commit | 839f6bdc15391ab03e52a516a828b7ea157d724a (patch) | |
| tree | 829be4ca19ad0e3323a65b7092ad434e0c1659d5 /webmentions_ssg/tasks | |
| parent | b8772268cc69d16860263bb1e3b03b2772d887e2 (diff) | |
| download | webmentions-ssg-839f6bdc15391ab03e52a516a828b7ea157d724a.tar.gz webmentions-ssg-839f6bdc15391ab03e52a516a828b7ea157d724a.zip | |
fix(sender): validate Webmention status URLs
Treat status URLs returned by remote endpoints as untrusted input so
malformed or non-HTTP schemes cannot be persisted or exposed as
clickable links.
Preserve successful delivery when a Location header is invalid while
rendering legacy unsafe status values as plain text in the admin
interface.
Diffstat (limited to '')
| -rw-r--r-- | webmentions_ssg/tasks/sender.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/webmentions_ssg/tasks/sender.py b/webmentions_ssg/tasks/sender.py index cceefcd..8834934 100644 --- a/webmentions_ssg/tasks/sender.py +++ b/webmentions_ssg/tasks/sender.py @@ -257,7 +257,14 @@ def post_webmention( if response.status_code == 201 and ( location := response.headers.get("Location") ): - status_url = urljoin(str(response.url), location) + try: + candidate = urljoin(str(response.url), location) + except ValueError: + # A malformed Location must not fail an otherwise successful send. + pass + else: + if is_http_url(candidate): + status_url = candidate return (response.status_code, status_url) @@ -399,7 +406,9 @@ def send_webmention(webmention_uuid: uuid.UUID) -> None: webmention.endpoint = endpoint webmention.response_status = response_status - webmention.status_url = status_url + webmention.status_url = ( + status_url if status_url is not None and is_http_url(status_url) else None + ) webmention.last_sent_at = datetime.now(UTC) |
