The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(events): scope SaaS event streams to the requesting user
Steven Enamakelc04c323e6ad6
diff --git a/crates/openhuman-rpc/src/server/http/events.rs b/crates/openhuman-rpc/src/server/http/events.rsindex 0a06ad3a08..d9015acdcc 100644--- a/crates/openhuman-rpc/src/server/http/events.rs+++ b/crates/openhuman-rpc/src/server/http/events.rs@@ -51,6 +51,24 @@ pub(super) async fn events_handler(.map(openhuman_core::core::auth::verify_bearer_token).unwrap_or(false);+ // SaaS: the stream belongs to the user the gateway scoped this request to,+ // and carries only that user's events. No user scope, or a browser bind+ // token instead of the gateway's bearer, is refused outright.+ let saas_agent = if openhuman_core::core::runtime::is_saas() {+ let agent = openhuman_core::core::runtime::CoreContext::current()+ .and_then(|ctx| ctx.session_agent().map(str::to_owned));+ match agent {+ Some(agent) if bearer_ok => Some(agent),+ _ => {+ log::warn!("[events] reject subscribe: SaaS streams need a gateway user scope");+ return (StatusCode::NOT_FOUND, Json(json!({ "error": "not found" })))+ .into_response();+ }+ }+ } else {+ None+ };+if !bearer_ok {let supplied_token = query.token@@ -99,6 +117,11 @@ pub(super) async fn events_handler(if event.client_id != client_id {return None;}+ if let Some(agent) = saas_agent.as_deref() {+ if !openhuman_core::web_chat::event_belongs_to(&event, agent) {+ return None;+ }+ }let data = serde_json::to_string(&event).ok()?;Some(Ok(Event::default().event(event.event).data(data)))},diff --git a/crates/openhuman-rpc/src/server/saas_gateway.rs b/crates/openhuman-rpc/src/server/saas_gateway.rsindex a2002a69be..2ce1792057 100644--- a/crates/openhuman-rpc/src/server/saas_gateway.rs+++ b/crates/openhuman-rpc/src/server/saas_gateway.rs@@ -4,8 +4,9 @@//! every request it://!//! 1. answers `404` for routes a SaaS core never serves — the OpenAI-compatible-//! `/v1`, every `/events` stream, the WebSockets, `/dev/connect` and the MCP-//! OAuth callback;+//! `/v1`, the `/events/*` debug streams, the WebSockets, `/dev/connect` and+//! the MCP OAuth callback — and for the `/events` chat stream outside a+//! user's scope;//! 2. with no `X-OpenHuman-User`, runs it on the operator plane (the bearer//! check downstream still applies);//! 3. with one, checks the service bearer **first** — so an unauthenticated@@ -29,7 +30,7 @@ use openhuman_core::user_agents::gateway::{/// Route prefixes a SaaS core never serves.pub(crate) const CLOSED_IN_SAAS: &[&str] = &["/v1",- "/events",+ "/events/","/ws/","/socket.io","/dev/connect",@@ -68,6 +69,10 @@ pub(crate) async fn saas_gateway(operator: Arc<CoreContext>, req: Request, next:}let Some(user) = header_str(&req, USER_HEADER).map(str::to_owned) else {+ // The chat event stream is a user's; the operator has none.+ if path == "/events" {+ return refuse(404, "not found");+ }return CoreContext::scope(operator, next.run(req)).await;};