Files
buzz/crates
Logan Johnson 4bf7d8a9b0 relay: refuse a reaction or deletion whose h names another channel (#9006)
## Summary

A reaction, or a deletion that targets a message, belongs to the target
message's channel. The relay works out that channel from the target and
stores the event there. But every read and every live delivery matches
the event's own channel (`h`) tags. So if a client puts a *different*
channel in the `h` tag, the event is stored in one channel and only ever
matches another:

- No one ever receives it.
- It still takes a slot when a client asks for "the latest N events" of
the real channel. A catch-up can then return fewer events than exist
while it looks complete, because the relay removes the stray event after
it applies the limit. This is one of the known gaps in
https://github.com/block/buzz-app/pull/2206.

The relay now refuses such an event. The rule:

| Event's `h` tags | Before | After |
|---|---|---|
| none | accepted | accepted |
| include the target's channel | accepted | accepted |
| only other channels | accepted, never delivered | refused |

The refusal uses the same "target not found" text as the existing
refusals for these kinds. So it tells the sender nothing about where the
target is.

No first-party client sends a mismatched `h`. buzz-app uses the target
message's channel, and desktop, mobile and the SDK send no `h` on
reactions. So no current client is affected.

### Details

- The check covers kind:7 reactions and kind:5 deletions that name their
target with an `e` tag. These are the two kinds whose channel comes from
a target. A kind:5 that names an addressable event (`a` tag) is not
affected.
- The check runs only when the target is in a channel, so a reaction to
a global event keeps any `h`. A tag must be the channel's UUID exactly
as the relay writes it (lowercase, hyphenated), the same way `#h`
filters match.
- The check runs after the token, membership and archive checks. If it
ran first, it would skip their database reads, and the response time
could tell someone who cannot read a private channel whether a guessed
`h` names the channel that holds a message.
- Events already stored with a stray `h` are not changed. They can still
take a slot under the limit.
- NOSTR.md now says that an optional `#h` on these kinds must name the
target's channel. It also says kind:5 takes its channel from its `#e`
target (the old text said it used `#h`).

### Related issue
None found. Follow-up to the known gaps listed in
https://github.com/block/buzz-app/pull/2206.

### Testing
- New `reaction_and_deletion_h_must_name_the_target_channel` test, as a
member of the target's channel. A reaction whose `h` names only another
channel is refused and not stored. A reaction with no `h`, or with both
channels, is accepted, and so is a reaction with any `h` on a global
event. A deletion of that reaction is refused and not stored with
another channel's `h`. It is accepted with the target's `h` or with no
`h`. A non-member's wrong guess still reaches the membership check. On a
private channel, a right guess and a wrong guess both end at the same
membership denial.
- I removed the check, and the test failed. I also moved it back before
the membership check, and the test failed.
- On a local relay over WebSocket: the same refusals and acceptances,
with the same messages, and a reaction to a global event keeps its `h`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)



Human test: Logan asked to take this to team review without a separate
hand test (2026-11-17).

buzz-review-completed

Signed-off-by: Logan Johnson <loganj@squareup.com>
Co-authored-by: Larry <627498bd4bd1f281a16431e3c6cce3b5c25b6692798c78672298aefbf2f8f8b5@buzz.block.builderlab.xyz>
2026-11-17 20:03:02 -05:00
..