Skip to content

fix: preserve self-referential p tags in channel member builders - #4338

Open
iroiro147 wants to merge 1 commit into
block:mainfrom
iroiro147:fix/4326-self-tag-p-stripped
Open

fix: preserve self-referential p tags in channel member builders#4338
iroiro147 wants to merge 1 commit into
block:mainfrom
iroiro147:fix/4326-self-tag-p-stripped

Conversation

@iroiro147

Copy link
Copy Markdown
Contributor

Summary

Fixes #4326: buzz channels remove-member --pubkey <your-own-key> fails with 400 missing p tag.

Root cause

It's in nostr 0.44's EventBuilder::build, not buzz code. From nostr/src/event/builder.rs:430:

By default, this method removes any `p` tags that match the author's public key.
To allow self-tagging, call [`EventBuilder::allow_self_tagging`] first.

The SDK builders construct the p tag correctly (builders.rs:582-592), but sign_with_keys strips it when the target equals the signer. The existing tests only exercised non-self targets, which is why the bug shipped.

Fix

Chain .allow_self_tagging() on both build_add_member (kind 9000) and build_remove_member (kind 9001), matching the existing convention in the NIP-IA builders elsewhere in this file (lines 1816, 1837).

Tests added

Two regression tests that sign with the same key as the target pubkey:

  • remove_member_self_referential_preserves_p_tag
  • add_member_self_referential_preserves_p_tag

Both assert the p tag survives signing. Verified with cargo test -p buzz-sdk --lib (243/243 passing).

Closes #4326.

nostr 0.44's EventBuilder::build strips p tags whose value equals the
author's public key by default (see allow_self_tagging flag). The
build_add_member (kind 9000) and build_remove_member (kind 9001)
builders constructed the p tag correctly, but sign_with_keys would
then strip it when target_pubkey == signer pubkey, causing the relay
to reply 400 "missing p tag" for self-removal/self-add operations.

Fix by chaining .allow_self_tagging() on both builders, matching the
existing convention in NIP-IA builders (builders.rs:1816,1837).

Add regression tests that sign with the same key as the target
pubkey and assert the p tag survives — the existing happy-path tests
only exercised the non-self case, which is why the bug shipped.

Closes block#4326.

Signed-off-by: Sarthak Singh <sarthak.singh@juspay.in>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Self-referential p tag is stripped at signing: channels remove-member/add-member targeting your own key always fails with 400 missing p tag

1 participant