Skip to content

fix(peering): run feed events through the relay's admission policy #1397

In review

Description

@Ferryx349

What happened

Events received over a peering feed are written with the bulk-import persister, which skips the admission checks the normal EVENT path performs. A configured peer can therefore push content the relay would reject if a client published it directly.

Relay version

3.17.1

Deployment

docker compose

OS

Linux

NIPs involved

No response

Logs

## Affected code

- `src/app/peering-sync-worker.ts:187` — `createEventBatchPersister(...)`
- `src/services/event-import-service.ts:136+` — `createEventBatchPersister`
- For contrast: `src/handlers/event-message-handler.ts` (PoW, size, created_at, blocklist, NIP-05, spam checks)

## Why it's wrong

The sync worker persists through the import path:


this.persistEvents = createEventBatchPersister(eventRepository, {
  userRepository: options.userRepository,
  relayUrl: settings().info?.relay_url,
})


`createEventBatchPersister` applies vanish/delete semantics and drops ephemerals, but none of the write policy: minimum PoW, content and tag limits, `created_at` bounds, blocked/banned pubkeys, NIP-05 or whitelist gating.

`acceptEvents` does verify shape, scope, expiry, event id and signature — that is *transport* validation, not *policy* validation. Live feed events are then rebroadcast to local subscribers (`broadcastEvent`), so the bypass is visible to readers, not just to storage.

Reproduction steps

  1. Configure a peer scope that covers kind 1.
  2. On the peer, publish a kind-1 event from a pubkey on the receiving relay's blocklist (or below minPowDifficulty, or over the content limit).
  3. The receiving relay stores and broadcasts it.
  4. Publish the same event directly to the receiving relay — it is rejected.

Additional context

Impact

Moderation and admission settings do not apply to peering traffic. Operators who configure blocklists, PoW floors or content limits will reasonably assume they cover all writes.

Proposed fix

Extract the admission decision out of EventMessageHandler into a shared admitEvent(event, context) and call it from the sync worker before persistEvents. Keep the batch persister for the historical backfill path only, where skipping policy is intentional.


For whoever picks this up

  • What is wrong: Events a configured peer sends over a peering feed are written with the bulk-import persister and then rebroadcast to local subscribers, without the admission policy the normal EVENT path applies, so a peer can store and fan out events from blocked pubkeys, below the PoW floor, or over the content and tag limits that a local client would be refused for.
  • Done looks like: the live feed path applies the same admission decision as EventMessageHandler.handleMessage() before persistEvents, so a live event that violates the receiving relay's policy is neither stored nor broadcast, while the historical backfill keeps the policy-free batch persister. Add it('refuses a live peering event that the local admission policy rejects') to test/unit/app/peering-sync-worker.spec.ts: offer a live event over the configured content limit (or from a blocked pubkey) and assert localEvents does not gain it; it fails today because PeeringPeerSession.acceptEvents() persists it. A second case should assert an event inside the limits is still stored, so the gate is not a blanket refusal.
  • Where it lives: src/app/peering-sync-worker.ts — PeeringPeerSession.acceptEvents(), which persists through the createEventBatchPersister built in the session constructor and rebroadcasts live writes; the checks to share are EventMessageHandler.handleMessage(), isEventValid(), canAcceptEvent(), isBlockedByRequestToVanish(), isUserAdmitted() and checkNip05Verification() in src/handlers/event-message-handler.ts. The persister is createEventBatchPersister() in src/services/event-import-service.ts. All on main (943fd7a); the Rust tree has peering identity only and no feed-sync code, so this fix and its tests land in the TypeScript tree.
  • Intent: Relay peering: advertise terms in NIP-11, authenticate peers, handle feeds distinctly from clients #931 — peering keeps operator-configured admission and moderation in force for what the relay stores, so a peer feed must not become a hole in those settings.

Activity

  1. self-assigned this
    on Dec 5, 2026
  2. added
    bug
    on Dec 5, 2026
  3. chappie-daemon commented on Dec 6, 2026

    @chappie-daemon
    Collaborator

    Delivery date: Friday 2026-12-18.

    A PR that is green and ready for review by then keeps this row yours. If nothing is up by Monday 2026-12-21 we take the row back into our own queue, because the v4 cutover on 2026-12-31 cannot wait on it.

    Your PR #1417 is already up, so this is a checkpoint rather than a start.

    If that date does not work, say so here and we will set one — a stated date is only useful if it is one you can meet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugpeering

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions