aboutsummaryrefslogtreecommitdiff
path: root/webmentions_ssg
diff options
context:
space:
mode:
authorDennis Fink2026-10-29 18:03:15 +0100
committerDennis Fink2026-10-29 18:03:15 +0100
commit839f6bdc15391ab03e52a516a828b7ea157d724a (patch)
tree829be4ca19ad0e3323a65b7092ad434e0c1659d5 /webmentions_ssg
parentb8772268cc69d16860263bb1e3b03b2772d887e2 (diff)
downloadwebmentions-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/__init__.py3
-rw-r--r--webmentions_ssg/tasks/sender.py13
-rw-r--r--webmentions_ssg/templates/sent_source.html6
3 files changed, 19 insertions, 3 deletions
diff --git a/webmentions_ssg/__init__.py b/webmentions_ssg/__init__.py
index 04746d6..61add02 100644
--- a/webmentions_ssg/__init__.py
+++ b/webmentions_ssg/__init__.py
@@ -21,6 +21,7 @@ from sqlalchemy.orm import DeclarativeBase
from webmentions_ssg.config import DefaultConfig, DevelopmentConfig, ProductionConfig
from .tasks import Huey
+from .url_security import is_http_url
APP_NAME = "webmentions-ssg"
VERSION = "0.0.2"
@@ -126,6 +127,8 @@ def create_app(config_class: type[DefaultConfig] | None = None) -> Flask:
"""
return {"VERSION": VERSION}
+ app.add_template_filter(is_http_url)
+
from .views import root_page
app.register_blueprint(root_page)
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)
diff --git a/webmentions_ssg/templates/sent_source.html b/webmentions_ssg/templates/sent_source.html
index e840f8f..8d22068 100644
--- a/webmentions_ssg/templates/sent_source.html
+++ b/webmentions_ssg/templates/sent_source.html
@@ -154,7 +154,11 @@ SPDX-License-Identifier: BSD-3-Clause
{% if webmention.status_url is not none %}
<div>
<strong>Status:</strong>
- <a href="{{ webmention.status_url }}" class="text-break">{{ webmention.status_url }}</a>
+ {% if webmention.status_url | is_http_url %}
+ <a href="{{ webmention.status_url }}" class="text-break">{{ webmention.status_url }}</a>
+ {% else %}
+ <span class="text-break">{{ webmention.status_url }}</span>
+ {% endif %}
</div>
{% endif %}
</td>