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>
This commit is contained in:
Ullrich Schäfer 2026-07-13 22:58:42 +02:00
parent 3bd1f87e63
commit 57696286e4
No known key found for this signature in database
GPG key ID: A32FF691A0F752D9
9 changed files with 234 additions and 7 deletions

View file

@ -439,6 +439,18 @@ export const federationProcessedActivities = journalSchema.table("federation_pro
receivedAtIdx: index("federation_processed_activities_received_at_idx").on(t.receivedAt),
}));
// Instance blocklist (spec: federation-operations "Instance blocklist").
// One row per blocked domain, matched exactly by host. Enforced at three
// boundaries: inbox (activities silently dropped), delivery enqueue
// (recipients filtered), and outbox poll / actor fetch (refused). v1
// management is a documented SQL insert/delete (see FEDERATION.md); the
// table is the API a future admin UI can sit on.
export const federationBlockedInstances = journalSchema.table("federation_blocked_instances", {
domain: text("domain").primaryKey(),
reason: text("reason"),
createdAt: timestamp("created_at", { withTimezone: true }).notNull().defaultNow(),
});
// Cache of remote ActivityPub actors we interact with (spec:
// social-federation). One row per actor IRI: display fields for feed
// cards, inbox/outbox URLs for delivery and polling, the public key for