Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ jobs:
filters: |
rust:
- 'crates/**'
# The core mention-group limit is coupled to the mobile push gate.
- 'mobile/lib/shared/push/push_contract.dart'
- 'migrations/**'
- 'schema/**'
- 'Cargo.toml'
Expand Down
58 changes: 58 additions & 0 deletions crates/buzz-core/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,41 @@ impl FromStr for ChannelJoinRole {
}
}

/// Why an agent's channel-add policy refused a third-party add.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ChannelAddPolicyDenied {
/// Owner-only admission was requested but no owner is recorded.
OwnerMissing,
/// The actor differs from the recorded owner.
OwnerOnly,
/// The target refuses all third-party channel additions.
Nobody,
}

/// Evaluate an agent's channel-add policy for a third-party add.
///
/// Callers bypass this check for self-adds and targets without a policy row.
/// Unknown values preserve the existing allow behavior; the database enum
/// constrains stored values. Both relay validation and admitted mutations use
/// this decision so their policy rules cannot diverge.
pub fn decide_channel_add_policy(
policy: &str,
owner: Option<&[u8]>,
actor: &[u8],
) -> Result<(), ChannelAddPolicyDenied> {
match policy {
"owner_only" => {
let owner = owner.ok_or(ChannelAddPolicyDenied::OwnerMissing)?;
if actor != owner {
return Err(ChannelAddPolicyDenied::OwnerOnly);
}
Ok(())
}
"nobody" => Err(ChannelAddPolicyDenied::Nobody),
_ => Ok(()),
}
}

/// The facts a kind:9000 add or role change is decided on, for
/// [`decide_member_put`]. Every field must come from one consistent read: the
/// relay validator reads them for a fast, client-visible answer, and
Expand Down Expand Up @@ -561,6 +596,29 @@ impl FromStr for MemberRole {

#[cfg(test)]
mod tests {
#[test]
fn third_party_add_policy_requires_the_recorded_owner_only_when_requested() {
use super::{decide_channel_add_policy, ChannelAddPolicyDenied::*};
let actor = [1; 32];
let other = [2; 32];
for (policy, owner, expected) in [
("owner_only", None, Err(OwnerMissing)),
("owner_only", Some(other.as_slice()), Err(OwnerOnly)),
("owner_only", Some(actor.as_slice()), Ok(())),
("nobody", None, Err(Nobody)),
("nobody", Some(actor.as_slice()), Err(Nobody)),
("everyone", None, Ok(())),
("everyone", Some(other.as_slice()), Ok(())),
("unknown", None, Ok(())),
] {
assert_eq!(
decide_channel_add_policy(policy, owner, &actor),
expected,
"{policy}"
);
}
}

use super::{
canonical_channel_name, channel_name_error, channel_type_from_group_state_tags,
decide_member_put, group_state_identity_tags, parse_channel_labels, ChannelJoinRole,
Expand Down
19 changes: 18 additions & 1 deletion crates/buzz-core/src/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ pub const RELAY_ADMIN_REMOVE_MEMBER: u32 = 9031;
pub const RELAY_ADMIN_CHANGE_ROLE: u32 = 9032;
/// Buzz: Set the workspace profile (icon). Admin/owner-signed command.
pub const RELAY_ADMIN_SET_WORKSPACE_PROFILE: u32 = 9033;
/// NIP-MG: Set the community mention-group management policy.
pub const RELAY_ADMIN_SET_MENTION_GROUP_POLICY: u32 = 47002;
/// NIP-MG: Create or replace a community mention group using a version precondition.
pub const RELAY_ADMIN_PUT_MENTION_GROUP: u32 = 47000;
/// NIP-MG: Delete a community mention group using a version precondition.
pub const RELAY_ADMIN_DELETE_MENTION_GROUP: u32 = 47001;
// NIP-43 relay membership announcement events (relay-signed)
/// NIP-43: Relay membership list snapshot (relay-signed, replaceable by convention).
pub const KIND_NIP43_MEMBERSHIP_LIST: u32 = 13534;
Expand Down Expand Up @@ -498,6 +504,9 @@ pub const KIND_MEMBERSHIP_SNAPSHOT: u32 = 39008;
/// NIP-CL: request-bound public membership overlay; query-time only, never stored.
pub const KIND_MEMBERSHIP_PUBLIC: u32 = 39009;

/// NIP-MG: Relay-signed community mention-group state or management settings.
pub const KIND_MENTION_GROUP_STATE: u32 = 39010;

/// Workflow definition (parameterized replaceable, d=workflow_uuid).
pub const KIND_WORKFLOW_DEF: u32 = 30620;

Expand Down Expand Up @@ -747,6 +756,9 @@ pub const ALL_KINDS: &[u32] = &[
RELAY_ADMIN_REMOVE_MEMBER,
RELAY_ADMIN_CHANGE_ROLE,
RELAY_ADMIN_SET_WORKSPACE_PROFILE,
RELAY_ADMIN_SET_MENTION_GROUP_POLICY,
RELAY_ADMIN_PUT_MENTION_GROUP,
RELAY_ADMIN_DELETE_MENTION_GROUP,
KIND_NIP43_MEMBERSHIP_LIST,
KIND_NIP43_MEMBER_ADDED,
KIND_NIP43_MEMBER_REMOVED,
Expand All @@ -765,6 +777,7 @@ pub const ALL_KINDS: &[u32] = &[
KIND_THREAD_WINDOW_BOUNDS,
KIND_MEMBERSHIP_SNAPSHOT,
KIND_MEMBERSHIP_PUBLIC,
KIND_MENTION_GROUP_STATE,
KIND_PRESENCE_UPDATE,
KIND_TYPING_INDICATOR,
KIND_AGENT_PRESENCE,
Expand Down Expand Up @@ -881,14 +894,17 @@ pub const fn is_workflow_execution_kind(kind: u32) -> bool {
}

/// Returns `true` if `kind` is a NIP-43 relay membership admin command (9030–9032)
/// or the Buzz workspace-profile admin command (9033).
/// or a Buzz workspace-profile or mention-group command.
pub const fn is_relay_admin_kind(kind: u32) -> bool {
matches!(
kind,
RELAY_ADMIN_ADD_MEMBER
| RELAY_ADMIN_REMOVE_MEMBER
| RELAY_ADMIN_CHANGE_ROLE
| RELAY_ADMIN_SET_WORKSPACE_PROFILE
| RELAY_ADMIN_SET_MENTION_GROUP_POLICY
| RELAY_ADMIN_PUT_MENTION_GROUP
| RELAY_ADMIN_DELETE_MENTION_GROUP
)
}

Expand Down Expand Up @@ -935,6 +951,7 @@ pub const fn is_relay_only_kind(kind: u32) -> bool {
| KIND_THREAD_WINDOW_BOUNDS
| KIND_MEMBERSHIP_SNAPSHOT
| KIND_MEMBERSHIP_PUBLIC
| KIND_MENTION_GROUP_STATE
)
}

Expand Down
2 changes: 2 additions & 0 deletions crates/buzz-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ pub mod git_perms;
pub mod invite;
/// Buzz kind number registry — custom event type constants.
pub mod kind;
/// NIP-MG community mention-group command validation and normalized values.
pub mod mention_group;
/// Network utilities — SSRF-safe IP classification.
pub mod network;
/// NIP-10 thread-marker parsing — shared `root`/`reply` marker resolver.
Expand Down
Loading
Loading