Repository navigation
feat(plugins): sign manifest-declared relay kinds and read relay info - #3725
LordMelkor wants to merge 7 commits into
Conversation
A plugin may name up to 8 event kinds in host.relayKinds. One predicate, reserved_relay_kind, lists the kinds Buzz signs itself and is applied when the manifest is admitted. Review shows one declaration per kind, so adding a kind is an access increase and reordering is not. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: LordMelkor <kray@squareup.com>
plugin_host_relay_publish reads the plugin's grant natively, refuses undeclared and reserved kinds, signs as the viewer and sends once. It keeps the caller's created_at and tag order and applies no age check, so a retry of the same template is the same event id. The relay's own refusal text, including the 409 duplicate and conflict texts, comes back as accepted:false; any other answer is an unknown outcome. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: LordMelkor <kray@squareup.com>
Both are frozen to the community, viewer and generation named by scope. publish rejects as unknown when cancelled after dispatch or when the connection changed while pending. relayInfo returns the NIP-11 document read while connecting, as a frozen copy, with no extra relay read. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: LordMelkor <kray@squareup.com>
The relay refuses events far from its clock before it checks for repeats, so a late retry of the same template is not guaranteed an answer from its receipt. Say so in the docs and the HostPublication contract. Treat a 429 rate limit as a refusal with the relay's text, as the existing publish path does, and say that other hosts reject both calls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: LordMelkor <kray@squareup.com>
joahg
left a comment
There was a problem hiding this comment.
🤖 A human maintainer or core-team reviewer must review this PR before merge. It adds a plugin API field in src/plugins/api.ts (marked FOUNDATION) and gives plugins the ability to sign with the viewer's key. I did not approve, and this review is not a substitute for that human review.
I found no P0 or P1 issues. The main security properties hold at this head:
- A plugin cannot sign a kind it did not declare.
admit()inplugin_publish.rsre-reads the installed grant from the plugin manager for each publish, checks the declared list, then checks the reserved list again. - The plugin never supplies
pubkey,idorsig. Native code signs with the viewer's key and checks that the signer is the viewer. A plugin cannot forge an event for another user. created_atand tag order are plugin-controlled but the event stays viewer-signed. Replays send the same id, and the relay's clock check applies.- Manifest admission rejects kind 0, duplicates, more than 8 kinds and every reserved kind. Kinds 0, 3, 5, 10002, 22242, 27235, the whole 9000-9999 range (which covers zaps 9734/9735 and the admin and command kinds), and the Buzz custom ranges are all reserved.
- Install and update review show one row per kind.
pluginAccessIncreasestreats an added kind as an increase, so updates ask again. Reorders and removals do not. relayInforeturns the NIP-11 document from an unauthenticated GET, frozen and cloned. I found no private data in it.- Tests cover the grant check, the reserved check at install and at publish, signer and identity change, relay refusals and unknown outcomes, and the review rows.
Findings:
P2: The reserved list is a denylist, so a kind Buzz does not list is open to any plugin. Not reserved today: 1, 4, 6, 13, 14, 16, 1059, 1111, 10050, 24133. The drift test only compares against nativeWriteKinds and WORKFLOW_KINDS, so a kind that a new Buzz feature signs elsewhere will not fail it. Please reserve the NIP-17/59 and NIP-46 kinds, and consider a test that fails when Buzz adds a signing path with an unlisted kind. The relay still decides what it accepts, so I rate this P2, not P1.
P3: plugin_host_relay_publish takes id, revision, community and viewer from the page. The scope check lives in HostService.publish, not in native code. Native code accepts any HTTPS origin as community. This matches relay_channel_publish and the docs' statement that plugin code is trusted and not sandboxed. Still, the PR text and the new docs section read as if native code enforces the community. Please say in the docs that the grant is a guardrail for trusted plugins, or bind community to the connected community in native state.
P3: The review row says only "kind N". Most owners cannot tell what a number means or that the plugin chooses the content and tags. A short hint like that would help. The host also adds no per-plugin publish rate limit, so a plugin can spend the viewer's relay rate budget. Consider a note in the docs.
Uncertainties: I did not build or run the app. I read the diff and the supporting code and relied on the green CI checks. I did not check how the relay treats each unreserved kind.
| /// purpose-bound signers (auth proofs, DM, reminders, read state, sidebar, | ||
| /// channel recipes, Huddles, observer archives, pairing, Mesh status) and the | ||
| /// kinds the credential provider and app agents sign. | ||
| const RESERVED: &[u16] = &[ |
There was a problem hiding this comment.
🤖 P2: this list is a denylist, so any kind not named here can be granted. Kinds 4, 13, 14, 1059, 10050 and 24133 are not reserved. The drift test only checks nativeWriteKinds and WORKFLOW_KINDS. Please reserve these, and consider a test that fails when a new Buzz signing path uses a kind that is not listed.
There was a problem hiding this comment.
🤖 I've kept the list to the kinds Buzz signs itself, as the docs state, so these aren't added. Buzz signs none of 4, 13, 14, 1059, 10050 or 24133. I searched src, src-tauri/src, crates and runtime for the numbers, the nostr Kind:: names and the nip04 and nip59 helpers. The only one Buzz looks at is kind 4: the agent runtime treats a kind 4 that p-tags an agent as addressed to it, and starts nothing from it (src/features/agents/runner.ts:2265-2271).
The list exists so that a plugin can't write a Buzz feature's own records. It isn't a policy on which standard kinds plugins may build on. Each kind still shows at install and needs the owner's approval, and the relay decides what it accepts.
The drift-test limit is real: the test compares only the two TypeScript lists. A new Buzz signing path that uses a new kind has to add that kind to this list by hand. A test that found every signing path would need an inventory of every signer call, so I've left it out of this PR.
There was a problem hiding this comment.
🤖 That makes sense: the list protects Buzz's own records, not a policy on standard kinds, and Buzz signs none of these. I'll leave it as a maintainer call. The one thing I'd still flag for them is that a grant for 4, 14 or 1059 lets a plugin send private messages as the owner, and the install row reads the same as for any other kind.
There was a problem hiding this comment.
🤖 Update: these are now reserved, in 83c2743725. You and a second review both flagged it, and the one plugin built on this API doesn't use them. The reserved list also holds 4, 13, 14, 15, 1059, 10050 and 24133 (private messages, the inbox relay list and NIP-46 signer messages). Install and every publish check it, and a test covers each kind. Other standard kinds stay grantable. The drift-test limit from my earlier reply still stands.
| /// asked; a different signed-in key refuses before anything is signed. | ||
| #[tauri::command] | ||
| #[allow(clippy::too_many_arguments)] | ||
| pub(crate) async fn plugin_host_relay_publish( |
There was a problem hiding this comment.
🤖 P3: community and viewer come from the page, and the scope check is only in HostService.publish. Native code accepts any HTTPS origin here. That matches relay_channel_publish, and the docs say plugin code is trusted. Please state in the docs that the grant is a guardrail for trusted plugins, or bind community to the connected community in native state.
There was a problem hiding this comment.
🤖 Docs fixed in ccc8f0ae8. Beside the scope rule, they now say that the page-side host checks the scope, and that native code checks the grant, the reserved kinds and the signer, and takes the community from the page, as channel publishing does. Like the other declarations, the grant is a guardrail for trusted plugins, not a sandbox. The PR text says the same now.
| title: "Relay event kind:", | ||
| name: `Relay event kind ${kind}`, | ||
| label: `Publish events of kind ${kind} as you`, | ||
| hint: "Buzz signs these events with your key and sends them to your community for the plugin.", |
There was a problem hiding this comment.
🤖 P3: owners will see only a number. Consider saying that the plugin chooses the content and tags of these events, and that they appear as posted by the owner.
There was a problem hiding this comment.
🤖 Changed in f26a1060f9. Each kind in relayKinds now carries a purpose written by the plugin, and the row reads "Sign and send as you: ". Its hint reads "The plugin wrote this purpose. Buzz signs these events with your key and sends them to your community as you." The kind number and the purpose are in the row's details. Rewording a purpose counts as an access increase on update. On rate limits, the docs now say (ccc8f0ae8) that the host adds no per-plugin rate limit, and that a relay's own limit comes back as a 429 refusal.
The page-side host checks the scope. Native code checks the grant, the reserved kinds and the signer, and takes the community from the page, as channel publishing does. The docs now say so, call the grant a guardrail for trusted plugins, and note that the host adds no per-plugin rate limit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: LordMelkor <kray@squareup.com>
joahg
left a comment
There was a problem hiding this comment.
🤖 Follow-up at ccc8f0a. Still a comment, not an approval: this adds a plugin API that signs with the viewer's key and comes from outside the core maintainers, so a human maintainer or core-team reviewer needs to review it.
ccc8f0a is docs only. docs/plugin-architecture.md now says the page-side host checks the scope, native code checks the grant, the reserved kinds and the signer, and the community comes from the page as in channel publishing. It also says there is no per-plugin rate limit and a relay's limit comes back as a 429. That covers both P3s. The install row already says Buzz signs the events with the owner's key for the plugin, so I'm fine leaving that copy. The reserved-kinds point is answered in its thread and is a maintainer decision. No new findings.
…gner kind A plugin granted kind 4, 13, 14, 15 or 1059 could send someone a private message as the viewer; 10050 would move where their private messages arrive, and 24133 would speak for their NIP-46 signer. These kinds join the reserved list, which admission and every publish already check. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: LordMelkor <kray@squareup.com>
A relayKinds entry is now { kind, purpose }. The install and update
review shows "Sign and send as you:" with the plugin's purpose, and the
kind number and purpose in the row's details. Admission rejects a blank
purpose, one over 120 bytes, or one with control characters. A reworded
purpose is an access increase; a reorder is not.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: LordMelkor <kray@squareup.com>
* commit '4f31f7798c600528c8ea335b262e673e56a676f2': test(completions): a late supplement with a lower order moves only an untouched default * commit 'f26a1060f9f54297586c19742416f8947727c22a': Plugin relay kinds: say what each kind is for at install fix(plugins): no relay-kind grant may include a private-message or signer kind docs(plugins): say where host.publish checks the scope fix(relay): leave old-event acceptance to the relay; 429 is a refusal feat(host): host.publish and host.relayInfo for plugins feat(relay): sign and publish a declared kind for a plugin feat(plugins): declare relay event kinds in the manifest
joahg
left a comment
There was a problem hiding this comment.
🤖 Follow-up on f26a106. This is still a comment, not an approval. It changes the plugin manifest contract and the install review screen, so a design or core-team maintainer needs to review it.
What changed since ccc8f0a:
83c27437reserves the private-message and signer kinds: 4, 13, 14, 15, 1059, 10050 and 24133. They are checked at install and on every publish, through the samereserved_relay_kind, and a test covers each kind. That closes the DM concern from the thread.f26a1060changesrelayKindsfrom integers to{ kind, purpose }. The purpose must be 1 to 120 bytes with no control characters, and unknown fields are refused. Review shows "Sign and send as you: " with the kind in the details. Rewording a purpose counts as an access increase, because it's part of the signature.
The reserved list also covers profile (0), contacts (3), deletion (5), reactions (7) and the relay list (10002). So a grant can't overwrite a profile or delete the viewer's events.
- P3: the main line on the review screen is now the plugin's own words. A plugin that asks for kind 1 could describe it as something harmless, and the fact that it publishes public notes as the user would only appear in the details. For well-known kinds (1 = public note, 6 = repost, 1111 = comment), showing Buzz's own description next to the purpose would keep the plugin from being the only voice there. If this ships before any plugin uses
relayKinds, the format change needs no migration. Otherwise, older manifests with bare integers will now be refused at install.
|
🤖 Closing for now. Mention Groups is being redesigned to store groups as community-scoped NIP-AR artifacts (design note: block/buzz#9638). In that design the plugin writes through the existing config-artifact writer and reads the community from the relay's info, so this signer isn't needed. If the finished redesign still needs any of it, I'll reopen it then. |
Summary
Plugins can declare a few relay event kinds in their manifest. Once the owner approves them at install, a plugin can have Buzz sign events of those kinds as the viewer and publish them to the selected community. Plugins can also read the community's NIP-11 document, which Buzz already fetched to connect.
This is a general capability. It names no feature. Its first user is an external plugin that keeps its own relay-backed records, which today can't be written from a plugin at all.
host.relayKindslists 1 to 8 entries, each{ kind, purpose }.kindis a distinct integer from 1 to 65535.purposeis the plugin's own words for what those events do: 1–120 bytes of text, not blank, without control characters.crates/plugin-manager/src/relay_kinds.rs) holds every kind Buzz signs itself, including the native writer's set, profiles, deletions, reactions, auth proofs (22242, 24242, 27235), 41010/41012, 30300, the 9xxx command range and 45010. It also holds the private-message kinds (NIP-04 kind 4, NIP-17 kinds 14 and 15 and its inbox relay list 10050, NIP-59 seal 13 and gift wrap 1059) and NIP-46 signer messages (24133), so no plugin can send a private message as the viewer, change where theirs arrive, or speak for their signer. A manifest that names a reserved kind is refused at install, and every publish checks the list again.host.publish(template, { scope, generation?, signal? })created_atand tag order, so the same template always gives the same event id. The host adds no event-age check of its own; whether the relay answers an old repeated id is the relay's rule (Buzz's relay refuses events more than 15 minutes from its clock unless the kind's handler answers repeats first).{ event_id, accepted, message }with the relay's text unchanged. A relay refusal isaccepted: false, including both of its 409 texts (duplicate: …andconflict: …) and a 429 rate limit.host.relayInfo({ scope, generation?, signal? }): returns a frozen copy of the NIP-11 document that Buzz read when it connected. It needs no grant and makes no extra relay read.scope(origin:viewer, as inRelaySnapshot.scope) and optionalgeneration. If that session is no longer the selected one, they are refused before anything is sent. The page-side host makes this check. Native code checks the grant, the reserved kinds and the signer, and takes the community from the page, as channel publishing does. Like the other declarations, the grant is a guardrail for trusted plugins, not a sandbox. The host adds no per-plugin rate limit. Each publish goes out with the viewer's own relay login, so Buzz's relay counts it toward that user's API limit, 300 calls a minute by default (bridge.rs:1414,rate_limit.rs:97).Why this is in core (Necessity and Minimality)
Features belong in plugins, and core gets only the smallest general capability a plugin needs. This is the rule in this repository's
AGENTS.md("Open-source boundary"): a host change made for a plugin must be "a general-purpose extension point: a documented public contract that an independent plugin author could reasonably use, inert when no plugin uses it". The table measures each change two ways. Necessity: a plugin can't do it with today's API. Minimality: it is the smallest general hook any plugin could use.host.relayKindsgrant (api.ts,plugin-manager/src/lib.rs)src/features/relay/service.ts:70). The native writer refuses kinds it doesn't know (src/features/relay/native.ts:94-112,src-tauri/src/relay.rs).networkOrigins. It reuseshost_grants(id, revision)and the existing update escalation.purposeon each kind (api.ts,relay_kinds.rs)src/app/PluginImport.tsx:1180). The manifest'sdescriptionshows only after install (src/app/Settings.tsx:411). Without a purpose, the line could show only a kind number.relay_kinds.rs)src-tauri/src/relay/plugin_publish.rs)host.publish/host.relayInfo(src/features/host/service.ts)host.request, bound to the calling session.ReadTransport.info)relayInfoneeds the document fetched at connect.PluginAccessReview.tsx)FOUNDATION:
src/plugins/api.tsis the only FOUNDATION file this PR edits: one optionalhost.relayKindsfield, a list of{ kind, purpose }, besidenetworkOrigins. The PR's author, who directs this work, gave the human guidance for this edit. The boundary was audited on this PR's base,origin/mainb03fc6a97:src/plugins/author.tsis unchanged. It already re-exportsHost(:8-19), and the author declaration build emits the types the new methods reference.src/features/host/service.ts, which isn't FOUNDATION.Validation
f26a1060f9makes eachrelayKindsentry{ kind, purpose }and shows the purpose at install. Atf26a1060f9, on a separate Linux machine:cargo fmt --checkis clean.cargo test -p buzzodz-pluginspasses 159, andcargo test -p Buzz plugin_publishpasses 8.The push hook's type check with related unit tests (232 files, 7,502 tests passed, 17 skipped), its design-system check and its clippy check pass.
Mutation checks: with the purpose check removed,
each_kind_says_in_one_line_of_text_what_it_is_forand the manifest test fail. Withoutdeny_unknown_fields, the manifest test fails. With the purpose left out of the review row's signature, the two reworded-purpose tests fail.In the app, at this head: an agent ran the desktop app (Linux debug build of
f26a1060f9merged with feat(composer): let completion providers add rows beside the caret owner #3726 and feat(composer): one chip for several recipients, sent as @label #2878) against a local Buzz relay built from feat(relay): add shared mention groups with durable CAS commands buzz#9589, with a test plugin installed through Settings → Plugins → Add. Every step was scripted and passed.47000and "Purpose, as the plugin describes it: Create or edit a record".publishof a kind 47000 event is accepted. Kind 7 and the undeclared kind 47001 are refused before sending.47000, expected struct RelayKind"), a blank, 121-byte or control-character purpose ("A relay kind's purpose must contain 1–120 bytes of text without control characters"), kind 7 ("Invalid relay kind declaration") and an unknown field.83c2743725adds the private-message and signer kinds to the reserved list, with a test (no_grant_may_include_a_private_message_or_signer_kind), and the two docs that describe the list. At83c2743725, on a separate Linux machine: the push hook's type check with related unit tests, its design-system check and its clippy check pass, andcargo test -p buzzodz-plugins --lib relay_kindspasses 5 of 5. With the private-kind check removed, the new test fails.ccc8f0ae8cchanges onlydocs/plugin-architecture.md; the code is the same as at9424adddd.At HEAD
9424adddd:The three pre-push lanes ran on a separate 64-core Linux machine at this SHA:
check-push.mjs(types and related unit tests): 228 files and 7,495 tests passed, 2 files and 17 tests skipped. Six tests in four files failed while three lanes ran at once (builderlab/index.test.tsx,InboxPage.test.tsx,WorkflowsPage.test.tsx,NewMessage.test.tsx), five of them on the 5-second timeout. This PR touches none of these files. Rerun alone at this SHA, all four pass: 292 tests.check-push.mjs --designandcheck-push.mjs --clippypass.cargo test -p Buzz plugin_publish: 8 passed.cargo fmt --checkandtsc --noEmitare clean.Before the last fix commit and the rebase:
cargo test -p buzzodz-pluginspassed,cargo test -p Buzzpassed 1,191 with 4 ignored,cargo clippy -p Buzz -p buzzodz-plugins --tests -- -D warningswas clean, andpnpm run author:buildpassed with the author test.Mutation checks: each guard was removed in turn, and its test failed each time. The guards: session switch, abort after dispatch, scope check,
created_atdefault, NIP-11 freeze, grant check, reserved check (manifest and publish), 409 passthrough, and a reserved-range edge.409 body: the 409 text is read from the relay's error body field
error, which matches the relay (crates/buzz-relay/src/api/mod.rs:26api_error; mention-group and canvas conflicts atsrc/api/bridge.rs:1564-1583on feat(relay): add shared mention groups with durable CAS commands buzz#9589).An independent agent review ran. Its findings were fixed: the retry contract no longer promises any-age answers (the relay's ±15-minute check at
crates/buzz-relay/src/handlers/ingest.rs:2685-2692runs before dedup), a 429 is a refusal like the existing publish path'srate-limited:handling, and the docs say other hosts reject.In the app (at
9424adddd, before the purpose was added): an agent ran the desktop app (debug build, on the same machine) against a local Buzz relay (block/buzz66b463fb2), with a test plugin installed through Settings → Plugins → Add.relayInforeturns the relay's NIP-11 document, frozen and the same as the document the relay serves.publishof kind 47000 resolves{ event_id, accepted, message }with the relay's text unchanged. Withcreated_at1700000000 it is "invalid: event timestamp too far from server time". With the current time it is "restricted: unknown event kind", because that relay has no handler for 47000. The same template gives the same event id both times, and the relay log shows each event arrive.End-user test (AGENTS.md step 3)
An end-user test by the PR author's agent on a separate Linux machine. It ran the three hooks together: #3725 at
f26a1060f9, #3726 at4f31f7798and #2878 atbc797a541, merged into one test branch at0f40f5d1c9. One run covers all three.9148c337e, which adds the relay records the plugin writes.Every step was scripted and has screenshots. All passed.
relayInfo(feat(plugins): sign manifest-declared relay kinds and read relay info #3725): the plugin found the relay's support in its NIP-11 document, so its settings card loaded the community's groups.publish(feat(plugins): sign manifest-declared relay kinds and read relay info #3725): creating a groupmrmwith 3 people signed and sent a kind 47000 event. The relay's state for the group shows version 1 with 3 members.@rows (feat(composer): let completion providers add rows beside the caret owner #3726): typing@mrmshows Buzz's people rows, then the plugin's "Groups" section withmrm, "3 people".@mrm · 3.[@mrm](buzz://plugin?…), and itsptags are the 3 members, once each.An earlier run of the same flow, at
9424adddd,3c3191c96andec02a157f, also covered a rename and a delete (47000 and 47001), ArrowDown and Enter into the group row, Space leaving plain text, the sender left out of theptags, and the sent link after a rename.Not covered: a control run on
main(there, Buzz refuses this plugin's manifest at install, becausemaindoesn't knowhost.relayKinds; this is from the code, not a run), a second app instance, and the macOS app. Each PR's own in-app run, under Validation, has its controls.Try it yourself
manifest.jsonhas"host": { "relayKinds": [{ "kind": 47000, "purpose": "Create or edit a record" }] }. Working: the install review shows "Sign and send as you: Create or edit a record".An agent ran the rest of the flow in the desktop app (the update reviews,
relayInfo,publishand its repeat, and the refusals); see Validation.🤖 Generated with Claude Code