fix: don't send webmentions to this site or WEBMENTION_SKIP_HOSTS (v2.18.3)

Links to the site itself, and to self-hosted apps like Gitea, timed out
from inside the container and sat in the admin Log. They are now skipped
when queueing; already queued or failed ones are dropped at worker start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
PhilandClaude Opus 5.5 committed 2026-11-12 13:40:27 -07:00
1 parent 52ecf0f713
commit b9e5321df2
10 files changed
+223 -5

No files matched your search

+27 -2
View File
@@ -22,6 +22,22 @@ from urllib.parse import urlparse
logger = logging.getLogger(__name__)
SKIPPED_NOTE = "Not sent: links to this site and WEBMENTION_SKIP_HOSTS are skipped"
def skipped_hosts(config) -> set[str]:
"""Hosts that never get webmentions: this site and WEBMENTION_SKIP_HOSTS (v2.18.3)"""
hosts = set(config.get("WEBMENTION_SKIP_HOSTS") or [])
site = urlparse(config.get("SITE_URL") or "").hostname
if site:
hosts.add(site.lower())
return hosts
def is_skipped(url: str, hosts: set[str]) -> bool:
"""True if url is on one of the skipped hosts (exact host, any port)"""
return (urlparse(url).hostname or "").lower() in hosts
def extract_links_from_html(html_content: str, exclude_code_blocks: bool = True) -> list[str]:
"""
@@ -189,17 +205,26 @@ def queue_webmentions_for_note(
Returns:
Number of webmentions queued
"""
# Links to this site or a skipped host are dropped before the cap (v2.18.3):
# this site only takes webmentions for its posts, and its own public
# address may not be reachable from inside the container
from flask import current_app, has_app_context
hosts = skipped_hosts(current_app.config) if has_app_context() else set()
def wanted(urls):
return [u for u in urls if not is_skipped(u, hosts)]
# Targets for the current content: reply target first, then links in
# document order, at most 10
links = extract_links_from_html(content_html) if content_html else []
current = _dedupe(([in_reply_to] if in_reply_to else []) + links)[:10]
current = wanted(_dedupe(([in_reply_to] if in_reply_to else []) + links))[:10]
if old_content_html is not None:
# Update (spec 3.1.4): also re-send to every target notified before,
# and to links the edit removed, so they can update or remove the
# mention. These are not capped.
removed = [u for u in extract_links_from_html(old_content_html) if u not in links]
target_urls = _dedupe(current + previous_targets(db_path, note_id) + removed)
target_urls = _dedupe(current + wanted(previous_targets(db_path, note_id) + removed))
else:
target_urls = current