Compare commits
1 Commits
14fbd59e7b
...
bbc376aebc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbc376aebc |
@@ -15,6 +15,7 @@ On retry (at-least-once reaper), already-delivered inboxes are skipped.
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
from collections import defaultdict
|
||||
|
||||
import httpx
|
||||
@@ -44,16 +45,25 @@ def _build_activity_json(activity: APActivity, actor: ActorProfile, domain: str)
|
||||
|
||||
obj = dict(activity.object_data or {})
|
||||
|
||||
# Rewrite activity ID to match the delivery domain so Mastodon's
|
||||
# origin check passes (activity ID host must equal actor host).
|
||||
# The stored activity_id uses the federation domain; we replace
|
||||
# just the host portion for per-app delivery.
|
||||
# Rewrite all URLs from the federation domain to the delivery domain
|
||||
# so Mastodon's origin check passes (all IDs must match actor host).
|
||||
import re
|
||||
activity_id = re.sub(
|
||||
r"^https://[^/]+/", f"https://{domain}/", activity.activity_id,
|
||||
)
|
||||
fed_domain = os.getenv("AP_DOMAIN", "federation.rose-ash.com")
|
||||
|
||||
def _rewrite(url: str) -> str:
|
||||
if isinstance(url, str) and fed_domain in url:
|
||||
return url.replace(f"https://{fed_domain}", f"https://{domain}")
|
||||
return url
|
||||
|
||||
activity_id = _rewrite(activity.activity_id)
|
||||
object_id = activity_id + "/object"
|
||||
|
||||
# Rewrite any federation-domain URLs in object_data
|
||||
if "id" in obj:
|
||||
obj["id"] = _rewrite(obj["id"])
|
||||
if "attributedTo" in obj:
|
||||
obj["attributedTo"] = _rewrite(obj["attributedTo"])
|
||||
|
||||
if activity.activity_type == "Delete":
|
||||
obj.setdefault("id", object_id)
|
||||
obj.setdefault("type", "Tombstone")
|
||||
|
||||
Reference in New Issue
Block a user