Skip to content

Commit 3056641

Browse files
Close remaining authz gaps in PR #320
Fix authorization holes identified during crossfire security review: 1. trigger_workflow: require workflow ownership for channel workflows. Previously any channel member could trigger any workflow in that channel, executing actions attributed to the workflow owner. 2. list_run_approvals: require workflow ownership. Previously any channel member could read approval records (including actionable token hashes) for any workflow in the channel. 3. REQ handler: block global subscriptions for channel-restricted tokens. The fan_out() path delivers global events to all global subscriptions without per-connection channel filtering, so restricted tokens must not register global subscriptions. 4. GET /api/events/:id: block global event access for channel- restricted tokens. Matches the policy already enforced by the search endpoints (no globals for restricted tokens). 5. list_workflow_runs: fix misleading error string ('trigger' -> 'view runs for').
1 parent 87d3f85 commit 3056641

3 files changed

Lines changed: 19 additions & 5 deletions

File tree

‎crates/sprout-relay/src/api/events.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ pub async fn get_event(
6565
.await
6666
.map_err(|_| not_found("event not found"))?;
6767
} else {
68+
// Channel-restricted tokens must not access global events — they are
69+
// scoped to specific channels and global events fall outside that scope.
70+
if ctx.channel_ids.is_some() {
71+
return Err(not_found("event not found"));
72+
}
73+
6874
// Global event — scope-aware allowlist.
6975
let event_kind = event_kind_u32(&stored_event.event);
7076

‎crates/sprout-relay/src/api/workflows.rs‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ pub async fn list_workflow_runs(
399399
check_token_channel_access(&ctx, &channel_id)?;
400400
check_channel_access(&state, channel_id, &pubkey_bytes).await?;
401401
}
402-
require_workflow_owner(&workflow, &pubkey_bytes, "trigger")?;
402+
require_workflow_owner(&workflow, &pubkey_bytes, "view runs for")?;
403403

404404
let limit = params.limit.unwrap_or(20).min(100) as i64;
405405
let runs = state
@@ -439,9 +439,8 @@ pub async fn list_run_approvals(
439439
if let Some(channel_id) = workflow.channel_id {
440440
check_token_channel_access(&ctx, &channel_id)?;
441441
check_channel_access(&state, channel_id, &pubkey_bytes).await?;
442-
} else if workflow.owner_pubkey != pubkey_bytes {
443-
return Err(forbidden("not authorized to access this workflow"));
444442
}
443+
require_workflow_owner(&workflow, &pubkey_bytes, "view approvals for")?;
445444

446445
let approvals = state
447446
.db
@@ -478,9 +477,8 @@ pub async fn trigger_workflow(
478477
if let Some(channel_id) = workflow.channel_id {
479478
check_token_channel_access(&ctx, &channel_id)?;
480479
check_channel_access(&state, channel_id, &pubkey_bytes).await?;
481-
} else if workflow.owner_pubkey != pubkey_bytes {
482-
return Err(forbidden("not authorized to access this workflow"));
483480
}
481+
require_workflow_owner(&workflow, &pubkey_bytes, "trigger")?;
484482

485483
let trigger_ctx = sprout_workflow::executor::TriggerContext {
486484
channel_id: workflow

‎crates/sprout-relay/src/handlers/req.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,16 @@ pub async fn handle_req(
142142
}
143143
}
144144

145+
// Channel-restricted tokens must not open global subscriptions — they would
146+
// receive events outside the token's channel allowlist.
147+
if channel_id.is_none() && token_channel_ids.is_some() {
148+
conn.send(RelayMessage::closed(
149+
&sub_id,
150+
"restricted: channel-scoped tokens cannot open global subscriptions",
151+
));
152+
return;
153+
}
154+
145155
// Check channel access BEFORE registering the subscription.
146156
if let Some(ch_id) = channel_id {
147157
if !accessible_channels.contains(&ch_id) {

0 commit comments

Comments
 (0)