diff options
| author | Dennis Fink | 2026-10-30 12:17:04 +0100 |
|---|---|---|
| committer | Dennis Fink | 2026-10-30 12:17:04 +0100 |
| commit | 89bff71238d06178528515e45cc00bcc8d70d663 (patch) | |
| tree | 6899568277685ec83ef984afe84fcffdf785441b /webmentions_ssg/tasks/scanner.py | |
| parent | d6ac8fb9768352fbb8a5633c6f357d877512bb5f (diff) | |
| download | webmentions-ssg-89bff71238d06178528515e45cc00bcc8d70d663.tar.gz webmentions-ssg-89bff71238d06178528515e45cc00bcc8d70d663.zip | |
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.
Diffstat (limited to 'webmentions_ssg/tasks/scanner.py')
| -rw-r--r-- | webmentions_ssg/tasks/scanner.py | 16 |
1 files changed, 16 insertions, 0 deletions
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) |
