trails/openspec/changes/federation-hardening/tasks.md
Ullrich Schäfer 57696286e4
feat(journal): federation instance blocklist
Task group 3 of federation-hardening. There was no blocklist of any kind;
the only lever against a hostile instance was an IP/host block in Caddy.

- New `federation_blocked_instances` table (domain PK, reason,
  created_at). Additive → created by drizzle-kit push.
- `federation-blocklist.server.ts`: exact-host matching —
  `isBlockedDomain`, `isBlockedIri` (unparseable IRI ⇒ treated as
  blocked), and `filterBlockedDomains` for batch recipient filtering.
- Enforced at all three boundaries (spec: federation-operations
  "Instance blocklist"):
  - inbox — each of the 4 listeners silently drops a blocked actor's
    activity (202, no error oracle) before dedup/side effects;
  - delivery enqueue — `enqueueActivityDeliveries` filters blocked
    recipients in one batch query;
  - outbox poll / actor fetch — `pollRemoteActor` refuses a blocked host
    up front (`skipped: "blocked instance"`), before any network.
- Operator procedure (SQL insert/list/delete) documented in the
  deployment runbook's federation section.
- Tests: unit (hostOfIri) + integration against real Postgres covering
  the helper and the delivery + outbox boundaries; inbox uses the same
  tested isBlockedIri primitive.

Note: the inbox-drop *counter* (federation_inbox_dropped_total{reason})
lands with the other metrics in task 4.2; this commit is the enforcement.

Verified: db + journal typecheck + lint clean; drizzle-kit push creates
the table; blocklist integration tests green against real Postgres;
journal unit suite 357 passing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-13 22:59:11 +02:00

1.8 KiB

1. Durable queue

  • 1.1 Implement federation-queue.server.ts: Fedify MessageQueue over pg-boss (enqueue with delay, listen loop), mirroring the PostgresKvStore adapter pattern
  • 1.2 Swap InProcessMessageQueue for it in federation.server.ts; document the two-layer queueing (fan-out jobs + Fedify queue) in a code comment
  • 1.3 Tests: enqueue/delay/consume roundtrip; simulated restart (new listener picks up previously enqueued messages)

2. Replay defense

  • 2.1 Add federation_processed_activities table (activity IRI PK, received_at) + migration; insert-or-drop check in inbox handlers before side effects
  • 2.2 30-day TTL sweep in the jobs worker
  • 2.3 Tests: duplicate Like/Delete/Update dropped as no-ops; Create double-delivery still covered by remoteOriginIri constraint

3. Blocklist

  • 3.1 Add federation_blocked_instances table + migration; exact-host check helper
  • 3.2 Enforce at inbox (silent 202 drop + counter), delivery enqueue (filter recipients), and outbox poll/actor fetch (refuse)
  • 3.3 Document the operator procedure (SQL insert/delete) in the ops docs; tests for all three boundaries

4. Protocol doc & observability

  • 4.1 Write FEDERATION.md (repo root): NodeInfo, actors/WebFinger, object + activity types with JSON examples, addressing, signatures + dedup expectations, retry policy, moderation semantics; link from README and docs
  • 4.2 Add federation_delivery_total{outcome}, federation_queue_depth, federation_inbox_dropped_total{reason} metrics + journal dashboard row

5. Verification

  • 5.1 Staging check: queue a fan-out, restart the journal container, confirm deliveries complete; block a test domain and verify both directions
  • 5.2 Run pnpm typecheck && pnpm lint && pnpm test && pnpm test:e2e