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(socket): stop trusting client-supplied profile on thread subscribe
Steven Enamakel31eb90cbeb22
diff --git a/app/src/services/socketService.ts b/app/src/services/socketService.tsindex 95eb3a7338..e361842f3d 100644--- a/app/src/services/socketService.ts+++ b/app/src/services/socketService.ts@@ -240,10 +240,7 @@ class SocketService {roomThreadIds.add(threadState.selectedThreadId);}for (const threadId of roomThreadIds) {- this.socket?.emit('thread:subscribe', {- thread_id: threadId,- profile_id: getCoreStateSnapshot().snapshot.auth.profileId ?? undefined,- });+ this.socket?.emit('thread:subscribe', { thread_id: threadId });}});@@ -474,17 +471,10 @@ class SocketService {socketWarn('Thread room subscription not acknowledged', { threadId });finish(false);}, timeoutMs);- socket.emit(- 'thread:subscribe',- {- thread_id: threadId,- profile_id: getCoreStateSnapshot().snapshot.auth.profileId ?? undefined,- },- () => {- clearTimeout(timer);- finish(true);- }- );+ socket.emit('thread:subscribe', { thread_id: threadId }, () => {+ clearTimeout(timer);+ finish(true);+ });});}diff --git a/crates/openhuman-core/src/plan_review/gate_tests.rs b/crates/openhuman-core/src/plan_review/gate_tests.rsindex fa7af65ef1..a8920f4e43 100644--- a/crates/openhuman-core/src/plan_review/gate_tests.rs+++ b/crates/openhuman-core/src/plan_review/gate_tests.rs@@ -267,30 +267,3 @@ async fn parked_reviews_are_isolated_by_tenant() {));assert_eq!(parked.await, PlanReviewResolution::Approve);}--#[test]-fn socket_replay_tenant_uses_the_sockets_profile_in_saas() {- let ambient = Tenant {- profile: Some("ambient-profile".into()),- agent: None,- };- let replay_tenant = socket_tenant(Some("socket-profile"), Ok(ambient), true)- .expect("socket profile must identify its review scope");- assert_eq!(replay_tenant.profile.as_deref(), Some("socket-profile"));-}--#[test]-fn socket_replay_tenant_fails_closed_without_a_saas_profile() {- assert!(socket_tenant(None, Ok(Tenant::default()), true).is_none());-}--#[test]-fn non_saas_socket_replay_keeps_the_host_tenant() {- let ambient = Tenant {- profile: Some("host-profile".into()),- agent: None,- };- let replay_tenant = socket_tenant(Some("untrusted-socket-hint"), Ok(ambient.clone()), false)- .expect("host tenant remains available");- assert_eq!(replay_tenant, ambient);-}diff --git a/crates/openhuman-rpc/src/server/socketio.rs b/crates/openhuman-rpc/src/server/socketio.rsindex e2b3e499c0..f248c69c9b 100644--- a/crates/openhuman-rpc/src/server/socketio.rs+++ b/crates/openhuman-rpc/src/server/socketio.rs@@ -222,6 +222,7 @@ struct ChatCancelPayload {}#[derive(Debug, Deserialize)]+#[serde(deny_unknown_fields)]struct ThreadSubscribePayload {thread_id: String,}diff --git a/crates/openhuman-rpc/src/server/socketio_tests.rs b/crates/openhuman-rpc/src/server/socketio_tests.rsindex 36e0707fb4..6fe079f076 100644--- a/crates/openhuman-rpc/src/server/socketio_tests.rs+++ b/crates/openhuman-rpc/src/server/socketio_tests.rs@@ -1,17 +1,50 @@use super::{channel_connection_update_payload, event_alias, origin_is_allowed_with_extra,- publish_companion_state_changed, subscribe_companion_state_changed, ThreadSubscribePayload,+ publish_companion_state_changed, subscribe_companion_state_changed,+ tenant_for_socket_connection, ThreadSubscribePayload,};#[test]-fn thread_subscribe_carries_the_sockets_profile_for_review_replay() {- let payload: ThreadSubscribePayload = serde_json::from_value(serde_json::json!({+fn thread_subscribe_cannot_choose_a_profile_for_review_replay() {+ let payload = serde_json::from_value::<ThreadSubscribePayload>(serde_json::json!({"thread_id": "thread-1",- "profile_id": "socket-profile",- }))- .expect("thread subscribe payload");- assert_eq!(payload.thread_id, "thread-1");- assert_eq!(payload.profile_id.as_deref(), Some("socket-profile"));+ "profile_id": "victim-profile",+ }));+ assert!(+ payload.is_err(),+ "tenant selection is not a client payload field"+ );+}++#[test]+fn socket_review_replay_uses_the_profile_captured_from_server_context() {+ let authenticated_profile = crate::core_host::core::runtime::tenant::Tenant {+ profile: Some("socket-profile".into()),+ agent: None,+ };+ let socket_tenant = tenant_for_socket_connection(Ok(authenticated_profile.clone()), true)+ .expect("server-scoped profile is bound to the socket");+ assert_eq!(socket_tenant, authenticated_profile);+}++#[test]+fn local_socket_review_replay_preserves_the_active_profile() {+ let active_profile = crate::core_host::core::runtime::tenant::Tenant {+ profile: Some("active-profile".into()),+ agent: None,+ };+ let socket_tenant = tenant_for_socket_connection(Ok(active_profile.clone()), false)+ .expect("local socket keeps its active profile");+ assert_eq!(socket_tenant, active_profile);+}++#[test]+fn socket_review_replay_fails_closed_without_saas_server_context() {+ assert!(tenant_for_socket_connection(+ Err(crate::core_host::core::runtime::tenant::NoTenant),+ true,+ )+ .is_none());}#[test]