Skip to content

fix(relay): enforce channel owner precedence - #9592

Merged
tellaho merged 3 commits into
mainfrom
tho/channel-owner-precedence
Nov 17, 2026
Merged

tellaho merged 3 commits into
mainfrom
tho/channel-owner-precedence

Conversation

@tellaho

@tellaho tellaho commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Category: fix
User Impact: Channel admins can manage the conversation while owners retain control of ownership and owner membership.

Problem: Channel admins can currently grant themselves ownership, change another owner's role, or remove an owner when another owner remains. A racing promotion can stop a removal after admission while its command is still stored and reported successful.

Solution: Reserve ownership grants, owner role changes, and owner removal for channel owners, enforced during validation and under the database membership lock. Persist each removal and its signed command together so a locked refusal rejects the receipt without storing or broadcasting the refused command; this applies equally to people and agents, with no new role, migration or protocol field.

File changes

crates/buzz-core/src/channel.rs
Constrain the shared role policy and member admission decision. Keep same-role additions idempotent and preserve ordinary guest-promotion rules; extend the existing role matrix and cover ownership grants through admission.

crates/buzz-db/src/store/channel_members.rs
Reject non-owner removal of an owner under the existing membership lock, including removal of an agent the actor owns. Reuse those locked checks when storing a removal command and its membership change atomically. Retain database coverage for escalation denials, ordinary owner/admin powers and concurrency; move the target-promotion race to the ingest journey below.

crates/buzz-relay/src/handlers/channel_authz.rs
Make removal authorization aware of the target's role and expose an ownership-specific role-change refusal. Extend the existing authorization tables.

crates/buzz-relay/src/handlers/side_effects.rs
Pass the removal target into admission authorization. Persist removals atomically, then run cache invalidation, eviction and best-effort notices only after commit; duplicates run no second removal or notices.

crates/buzz-relay/src/handlers/ingest.rs
Route kind 9001 through atomic persistence and return locked membership refusals as client rejection before dispatch.

crates/buzz-relay/src/handlers/remove_user_postgres_tests.rs
Exercise the real ingest race with a membership-lock barrier: target promotion causes rejection, leaves the Owner intact and stores/publishes no command. Then verify legitimate removal and duplicate replay after rejoin. This replaces the DB-only target-promotion test rather than duplicating it.

crates/buzz-relay/src/handlers/mod.rs
Register the new PostgreSQL ingest journey for automatic discovery.

NOSTR.md
Document owner precedence, including the agent-owner exception's boundary.

Try it

  1. Run the updated relay and create a disposable channel with two owners, one admin, and one ordinary member. Two owners ensure the last-owner guard cannot mask the new permission check.
  2. As the admin, attempt to promote yourself or another member to owner. Both requests should be refused.
  3. As the admin, attempt to demote or remove either owner. Both requests should be refused and their memberships should remain unchanged.
  4. Confirm the admin can still rename the channel and manage ordinary members/admins.
  5. As an owner, confirm ownership delegation and co-owner demotion/removal still work. The sole remaining owner must still be unable to demote or remove themselves.
  6. Run the PostgreSQL lane's membership regressions and removal_receipt_tracks_the_locked_membership_write. The controlled race must return rejection with the target still Owner and no stored/published removal; the same command must succeed once authorized, and its later replay must preserve a rejoined member.

Validation and remaining checks

  • At e7a8fe405, all 2,048 infrastructure-free tests across the complete buzz-db/buzz-relay package inventory pass with nextest process isolation, plus all five package doctests. The monolithic Cargo run stalled in shared-process configuration tests; the same package inventory passes with the repository's preferred isolated runner, without exclusions or assertion changes.
  • The new ingest journey fails on the original implementation with accepted:true after the locked refusal, and passes with atomic removal. Its positive controls verify actual publication for a legitimate removal and no repeated removal/publication after rejoin. The existing demoted-actor lock test retains direct-call concurrency coverage.
  • At the same head, all 1,425 PostgreSQL cases across both packages pass through the per-test isolation wrapper (PostgreSQL 17.12, UTC; hosted CI uses 16). A rebuilt isolated native relay passes 24 signed WebSocket operations plus persisted-state and subscriber checks, including the real promotion/removal race, later legitimate retry and replay after rejoin. Temporary services are stopped; Git/media behavior was not exercised. All mandatory push hooks pass, including the broad Rust suite (709.20s) and native/desktop checks (302.32s).
  • Test churn is 420 lines (+399/-21); non-test churn is 196 lines (186 source, 10 maintained docs), versus 279/69 at the preceding head. The new 207-line ingest journey and two-line registration replace the 68-line DB-only target-promotion race; no other authorization or concurrency coverage is removed.
  • The implementation tree passed 298 core library tests, 1,979 database/relay library tests, and 76 binary/integration-target tests: 2,353 total. Infrastructure-dependent ignored tests were excluded. These runs preceded publication; the publication commit has the identical source tree, with only its commit subject amended.
  • Disabling the ownership-grant guard made the admission regression fail with Ok(Owner); restoring the guard returned all 298 core tests to green.
  • At follow-up head 6d4622d3e, all 769 PostgreSQL tests in the buzz-db package profile passed using the repository's per-test database isolation wrapper (PostgreSQL 17.12, UTC; 245 cases outside the selected profile skipped). This includes both new regressions and the existing owner-management journey retained after removing two repeated positive checks.
  • An isolated native relay passed 18 signed WebSocket operations plus persisted-state checks: admin escalation, co-owner demotion/removal, retained admin management, owner delegation/demotion/removal, and last-owner protection. This membership workflow used local PostgreSQL and Redis; Git/media behavior was not exercised.
  • PostgreSQL test discovery, formatting, and hosted CI passed at 6d4622d3e. Maintainer approval and human acceptance remain pending.

This relay permission change does not require a client update.

Related history: #3017 established bidirectional elevated-role checks and last-owner protection; #8143 introduced the current shared role predicate. This PR adds the Owner-over-Admin distinction to those rules.

tellaho and others added 2 commits November 16, 2026 13:51
Only channel owners may grant ownership, change another owner's role,
or remove an owner. Enforce the same boundary during relay validation
and inside the serialized database membership write, including owned
agents and concurrent target promotions.

Keep ordinary admin management and the existing last-owner protections.
Add role-matrix and persistence/concurrency regressions, and document
the hierarchy in the protocol guide.

Co-authored-by: Carl <acda9e433d19dcd0e6b6840f7f4b98f3a56f1fab98049d444c087019e6d36560@feedback.communities.buzz.xyz>
Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
Drop repeated ownership delegation and co-owner demotion checks from the
admin precedence journey. The existing owner management journey already
verifies both writes and their persisted roles.

Keep the new denied escalation, owned-agent removal, ordinary admin
management, last-owner removal, and concurrent target promotion cases.

Co-authored-by: Carl <acda9e433d19dcd0e6b6840f7f4b98f3a56f1fab98049d444c087019e6d36560@feedback.communities.buzz.xyz>
Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
@tellaho
tellaho marked this pull request as ready for review November 16, 2026 22:54
@tellaho
tellaho requested a review from a team as a code owner November 16, 2026 22:54
@github-actions github-actions Bot added the codex-security-review-current The posted Codex security review matches its recorded range. label Nov 16, 2026
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

🔐 Codex Security Review

Note: This is an automated, security-focused review generated by Codex.
Use it as a supplement to human review; false positives are possible.

Scope

  • Exact PR diff: f315c7f31f0e8ac73763ce253c03e509a0631f2c...e7a8fe40565ddcb5bc731ad7a59e28cd44497f0a
  • Model: gpt-6.1-sol

💡 Click "edited" above to see earlier reviews for this PR.


Review Summary

Overall Risk: NONE

No concrete findings after tracing the changed authorization rules, atomic removal persistence, replay handling, and post-commit effects.

Findings

No concrete security, correctness, or reliability findings were identified.

Notes

  • Review used read-only source and history inspection. Builds and tests were not run, as requested.

Generated by Codex Security Review |
Requested by: @tellaho |
Workflow run

@wesbillman wesbillman left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Star Lord: changes recommended at 6d4622d for one removal-receipt race. Source review only; two first-pass review lanes timed out.

@jmecom jmecom left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 jm-astra, AI reviewer: Independently reviewed 6d4622d3e0b1a3d93806e9677e4bfe4950f11152, including source integration with main f315c7f31f0e8ac73763ce253c03e509a0631f2c.

I confirm the existing P2 removal-receipt finding: when an admin's removal validates before the target becomes an owner, the locked database check correctly rejects removal, but ingest retains/broadcasts the command and returns success. Owner membership remains protected; the receipt does not reflect the result. No additional actionable findings in the reviewed ownership and concurrency paths, so I have not duplicated that inline comment.

Validation at the reviewed head: 550 core/database library and integration tests passed; 769 database infrastructure tests were ignored. The full relay library run stalled in configuration/audio tests with mutex waits and was terminated, so there is no complete relay-suite pass. The clean merge was inspected from source. The promotion/removal race was traced through validation, persistence and dispatch, not reproduced through a live relay.

Persist kind 9001 and its membership removal in one admitted transaction. Return locked refusals through ingest without storing or broadcasting the command, and keep post-commit notices best-effort.

Replace the database-only target-promotion race with an ingest journey covering rejection, atomic event absence, publication, legitimate removal and replay after rejoin.

Co-authored-by: Carl <acda9e433d19dcd0e6b6840f7f4b98f3a56f1fab98049d444c087019e6d36560@feedback.communities.buzz.xyz>
Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
@github-actions github-actions Bot added codex-security-review-current The posted Codex security review matches its recorded range. and removed codex-security-review-current The posted Codex security review matches its recorded range. labels Nov 17, 2026
@tellaho
tellaho merged commit 833c418 into main Nov 17, 2026
90 checks passed
@tellaho
tellaho deleted the tho/channel-owner-precedence branch November 17, 2026 01:13
johnmatthewtennant added a commit that referenced this pull request Nov 17, 2026
…ransparency

* origin/main: (85 commits)
  docs(mobile): add REVIEWING.md with mobile review principles (#9298)
  buzz-db: check workflow references in app code before FK retirement (#9399)
  fix(relay): enforce channel owner precedence (#9592)
  feat(relay): grow DMs in place, identified by their people (#9125)
  feat(workflow): implement send_dm action (#9402)
  perf(mobile): stop following presence for people no longer shown (#9480)
  [buzz] Classify HTTP event request metrics by event type (#9561)
  update feedback community invite link (#9588)
  fix(mobile): name the failing step in sign-in errors (#9263)
  fix(mobile): order same-second messages by millisecond offsets (#9541)
  fix(acp): saturate observer frame size estimates (#9494)
  feat(mobile): accept mentions with Tab and send with Enter on hardware keyboards (#8733)
  Fix remote Huddle ending cleanup (#9376)
  fix(mobile): host Duo long-press menus in native sheets (#9536)
  fix(mobile): keep the relay session across auth reloads (#9543)
  feat(deletion): clean up media for users and owned agents (#9365)
  Refuse opening a private channel that has other members (#9307)
  feat(auth): tolerate client clocks up to 120 s off (#9485)
  docs: name the required stop as a relay build, not a release (#9577)
  buzz-db: drop the created_at floor, community write-fence and migration-only NIP-RS triggers (contract) (#8326)
  ...

Signed-off-by: John Tennant <jtennant@squareup.com>
morgmart added a commit that referenced this pull request Nov 17, 2026
* morganm/task-conversations:
  buzz-db: check workflow references in app code before FK retirement (#9399)
  fix(relay): enforce channel owner precedence (#9592)

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
wpfleger96 added a commit that referenced this pull request Nov 17, 2026
…e-recovery

* origin/main: (60 commits)
  Clean up account records and refresh member lists (#9364)
  perf(mobile): save own thread interest once per unread catch-up (#9614)
  buzz-db: fix main (renumber the function drop to 0094, update_channel test call) (#9616)
  feat(relay): name the agent whose add policy refuses a DM (#9601)
  buzz-db: drop the community_deletion_lock_key and profile_name_fields functions (contract) (#9598)
  fix(deps): clear chrono, humantime and zip advisories from the dependency policy (#9609)
  docs: define mobile diagnostic reporting (#9600)
  build(mobile): link iOS plugins through Swift Package Manager (#9597)
  feat(push-gateway): enroll Android installations and send FCM wakes (#9560)
  perf(mobile): cache and animate custom emoji in the iOS picker (#9479)
  fix(ios): end each bold or strikethrough run at its first closing marker (#9559)
  Apply the private-to-open rule in update_channel too (#9581)
  Add real content cleanup for users and agents (#9363)
  Keep transparency in mobile avatar photo crops (#9319)
  fix(mobile): read presence for a person shown again while still covered (#9595)
  buzz-db: check membership, agent-owner and channel references in app code (#9404)
  buzz-db: enforce five single-table guards in app writers (phase 1) (#8320)
  docs(mobile): add REVIEWING.md with mobile review principles (#9298)
  buzz-db: check workflow references in app code before FK retirement (#9399)
  fix(relay): enforce channel owner precedence (#9592)
  ...

Signed-off-by: Will Pfleger <wpfleger@block.xyz>

# Conflicts:
#	mobile/lib/features/channels/channel_actions_sheet.dart
#	mobile/lib/shared/read_state/read_state_manager.dart
tellaho added a commit that referenced this pull request Nov 19, 2026
**Category:** improvement
**User Impact:** Solo chat owners can lower the access of any current
non-owner, including people and agents.

**Problem:** Using invitations to change Solo chat access can restore a
removed member, reject a downgrade because of the target’s invitation
policy, or show a join notice for a role change.

**Solution:** Add signed role updates that require an active member at
the expected role when the relay commits the change. A Solo owner can
downgrade any current non-owner. Moving a viewer to Participating
requires a verified agent, and granting Admin requires ownership of that
agent. The relay refreshes signed group state without emitting a join
notice.

Companion to
[block/buzz-app#3704](block/buzz-app#3704). The
[app
review](block/buzz-app#3704 (review))
identified the need for conditional writes, verified agent identity and
live relay validation. [#9592](#9592)
introduced the atomic removal that uses the same membership lock.

<details>
<summary>File changes</summary>

**crates/buzz-core/src/kind.rs**

Register signed Solo role updates as kind 9050.

**crates/buzz-db/src/store/channel_members.rs**

Authorize the transition under the channel membership lock and commit
the active row update and signed event together.

**crates/buzz-relay/src/handlers/event.rs**

Give the new command a bounded metrics label.

**crates/buzz-relay/src/handlers/ingest.rs**

Use the shared signed ingest path and require the channel administration
scope.

**crates/buzz-relay/src/handlers/mod.rs**

Register the command handler and its PostgreSQL test.

**crates/buzz-relay/src/handlers/solo_member_role.rs**

Parse the command, route it to the conditional write, and refresh signed
group state after commit.

**crates/buzz-relay/src/handlers/solo_member_role_postgres_tests.rs**

Exercise human and agent changes, restrictive invitation policy,
promotion authorization, stale and removed membership, duplicate
receipt, and signed roster updates through the relay’s production ingest
path.

**docs/solo-mobile-contract.md**

Describe the wire format, permitted transitions, and handling when an
older relay rejects the command.

</details>

### Try it

1. Run the updated relay and the companion app against a disposable Solo
chat with a current human and agent. Open **Chat access** as the owner.
2. Lower the human to **Viewing only**. Reopen **Chat access** and
confirm the saved role. A role change should produce no join notice.
3. Downgrade an agent with a restrictive invitation policy. Confirm its
role changes. Check that **Admin** can be granted only to your own
verified agent.
4. Run `solo_owner_edits_active_members_and_publishes_the_new_roster`
with PostgreSQL to check that a pending change for a removed member is
refused and the signed roster stays clear of that member.

### Validation

- The PostgreSQL regression passes at relay commit `405f7d1da`. It
covers role and invite-policy enforcement, signed roster refresh,
duplicate receipts, and rejection after removal.
- The companion app at `a470947dc6` passes 138 administration tests. Its
production command builder, validator, and signed roster reader also
passed over WebSocket against a local relay backed by PostgreSQL and
Redis. A human moved from Admin to Participating to Viewing only, then
was removed. The app preflight and relay both refused a further role
edit, and the signed roster still excluded the member.
- The live check exercised the app’s relay code headlessly. The UI
walkthrough is pending.

---------

Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
Signed-off-by: Tom Brow <tomb@block.xyz>
Co-authored-by: Carl <acda9e433d19dcd0e6b6840f7f4b98f3a56f1fab98049d444c087019e6d36560@feedback.communities.buzz.xyz>
Co-authored-by: Tom Brow <tomb@block.xyz>

This branch was previously deployed

1 inactive deployment
codex-review — e7a8fe40 Deployed Nov 17, 2026 by tellaho via Run Codex Security Review #15630
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codex-security-review-current The posted Codex security review matches its recorded range.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants