From 89bff71238d06178528515e45cc00bcc8d70d663 Mon Sep 17 00:00:00 2001 From: Dennis Fink Date: Fri, 30 Oct 2026 12:17:04 +0100 Subject: fix(sender): prevent duplicate canonical source URLs Keep persisted sources, including deleted ones, as owners of their canonical URLs so newly scanned aliases cannot claim the same source identity. Skip duplicate canonical paths without blocking unrelated sources from being saved or queued for delivery. --- webmentions_ssg/tasks/scanner.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'webmentions_ssg/tasks/scanner.py') diff --git a/webmentions_ssg/tasks/scanner.py b/webmentions_ssg/tasks/scanner.py index 4bb6736..e8149ba 100644 --- a/webmentions_ssg/tasks/scanner.py +++ b/webmentions_ssg/tasks/scanner.py @@ -439,6 +439,10 @@ def scan_sources() -> None: sa.select(Source).options(selectinload(Source.sent_webmentions)) ) } + # Existing sources retain their canonical URLs even when marked deleted. + # Reserve these URLs before scanning so an alias cannot claim one just + # because it is discovered earlier than its persisted owner. + paths_by_url = {source.url: source.path for source in sources_by_path.values()} seen_paths: set[str] = set() scanned_count = 0 @@ -470,6 +474,17 @@ def scan_sources() -> None: ) continue + if (owner_path := paths_by_url.get(scanned.url)) is not None and ( + owner_path != scanned.path + ): + current_app.logger.warning( + "Skipping source %s: duplicate canonical URL %r (already used by %s)", + index_path, + scanned.url, + owner_path, + ) + continue + try: if (source := sources_by_path.get(scanned.path)) is None: source = create_source(scanned, scan_time) @@ -478,6 +493,7 @@ def scan_sources() -> None: source = update_source(source, scanned, scan_time) sources_by_path[source.path] = source + paths_by_url[source.url] = source.path scanned_count += 1 except SourceScanError as exc: current_app.logger.warning("Could not scan source %s: %s", index_path, exc) -- cgit v1.3.1