Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

chore(core): restrict socket auto-connect and token provider to user sessions

Steven Enamakel278834277940
diff --git a/crates/openhuman-core/src/backend/client.rs b/crates/openhuman-core/src/backend/client.rs
index cccb7ed1dc..651e76cb1f 100644
--- a/crates/openhuman-core/src/backend/client.rs
+++ b/crates/openhuman-core/src/backend/client.rs
@@ -680,17 +680,8 @@ impl BackendClient {
url.path(),
);
} else {
- // Enrich the report with the two fields triage needs to pin a
- // non-2xx's origin: the outbound `host` and a PII-safe `body_shape`
- // (top-level JSON key names only — never values; see
- // `backend_api_body_shape`). `report_error` previously logged only
- // `response_body_len`, leaving us blind when a client hits a
- // non-canonical backend (custom BACKEND_URL / proxy / foreign
- // host) — TAURI-RUST-8C: 12k `GET /teams/me/usage` 404s from one
- // user whose 91-byte body matched no route this backend emits,
- // un-diagnosable because neither host nor shape was captured.
- // `host_str()` carries no scheme/path/query/token. Telemetry only
- // — the error still propagates below (no suppression).
+ // Record the host and JSON key names to locate misrouted
+ // backend errors without sending response values (TAURI-RUST-8C).
let host = url.host_str().unwrap_or("");
let body_shape = backend_api_body_shape(&text);
crate::core::observability::report_error(
diff --git a/crates/openhuman-core/src/core/runtime/services.rs b/crates/openhuman-core/src/core/runtime/services.rs
index 80d4b0b7bd..5d7e493806 100644
--- a/crates/openhuman-core/src/core/runtime/services.rs
+++ b/crates/openhuman-core/src/core/runtime/services.rs
@@ -427,7 +427,7 @@ pub fn spawn_socket_auto_connect(
services: ServiceSet,
socket_mgr: std::sync::Arc<crate::platform::socket::SocketManager>,
) {
- if services.socketio {
+ if services.socketio && crate::backend::transport::is_installed() {
tokio::spawn(async move {
log::info!("[socket] Checking for stored session to auto-connect...");
let config = match Config::load_or_init().await {
@@ -441,9 +441,8 @@ pub fn spawn_socket_auto_connect(
log::debug!("[socket] No backend transport or base URL — skipping auto-connect");
return;
};
- // The API key when one is stored, else the session token.
let initial_token =
- match crate::security::credentials::session_support::backend_bearer_secret(&config)
+ match crate::security::credentials::session_support::get_session_token(&config)
{
Ok(Some(t)) => t,
Ok(None) => {
diff --git a/crates/openhuman-core/src/platform/socket/ops.rs b/crates/openhuman-core/src/platform/socket/ops.rs
index 9ac2ad2e02..737ff73ff6 100644
--- a/crates/openhuman-core/src/platform/socket/ops.rs
+++ b/crates/openhuman-core/src/platform/socket/ops.rs
@@ -53,10 +53,12 @@ pub async fn connect_with_session(manager: &SocketManager) -> Result<SocketState
log::info!("[socket:rpc] connect_with_session — resolving credentials");
let config = std::sync::Arc::new(crate::config::rpc::load_config_with_timeout().await?);
let api_url = crate::backend::require_base_url(&config.api_url)?;
- // The API key when one is stored, else the session token.
- let token = crate::security::credentials::session_support::backend_bearer_secret(&config)
+ let token = crate::security::credentials::session_support::get_session_token(&config)
.map_err(|e| format!("failed to read session token: {e}"))?
- .ok_or("no session token stored — user must log in first or set an API key")?;
+ .ok_or("no session token stored — user must log in first")?;
+ if crate::security::credentials::session_support::is_local_session_token(&token) {
+ return Err("offline local session cannot connect to hosted socket".to_string());
+ }
let provider =
super::token_provider::token_provider_from_config(std::sync::Arc::clone(&config));
diff --git a/crates/openhuman-core/src/platform/socket/token_provider.rs b/crates/openhuman-core/src/platform/socket/token_provider.rs
index 0259d755b4..c1d9a95a3b 100644
--- a/crates/openhuman-core/src/platform/socket/token_provider.rs
+++ b/crates/openhuman-core/src/platform/socket/token_provider.rs
@@ -67,20 +67,17 @@ pub(super) fn static_token_provider(token: String) -> TokenProvider {
})
}
-/// Build a provider that reads the latest backend credential from the profile
-/// store on every call: the TinyHumans API key when one is stored, else the
-/// session token. The backend's handshake accepts either as `auth.token`.
+/// Build a provider that reads the latest app-session token from the profile
+/// store on every call. The channel relay requires a user session.
///
/// This is the **live-refresh** path used by `handle_connect_with_session`:
/// when the loop retries after a disconnect it will see any token that was
/// refreshed or re-stored since the previous attempt.
pub(crate) fn token_provider_from_config(config: Arc<crate::config::Config>) -> TokenProvider {
Arc::new(move || {
- let token = crate::security::credentials::session_support::backend_bearer_secret(&config)
+ let token = crate::security::credentials::session_support::get_session_token(&config)
.map_err(|e| format!("failed to read session token: {e}"))?
- .ok_or_else(|| {
- "no session token stored — user must log in first or set an API key".to_string()
- })?;
+ .ok_or_else(|| "no session token stored — user must log in first".to_string())?;
if crate::security::credentials::session_support::is_local_session_token(&token) {
return Err("offline local session cannot connect to hosted socket".to_string());
}
diff --git a/crates/openhuman-embed/README.md b/crates/openhuman-embed/README.md
index c581303469..8836ed7fe6 100644
--- a/crates/openhuman-embed/README.md
+++ b/crates/openhuman-embed/README.md
@@ -148,7 +148,8 @@ its own `Provider` (BYOK) never touches the key.
The key covers every hosted feature the core reaches: managed inference, cloud
embeddings, voice (STT, TTS, the realtime voice agent), web search, media
generation, the Jev ranker, Composio and the other `/agent-integrations/*`
-tools, channel delivery, referral, webhooks, and the Socket.IO connection. Callers that
+tools, referral, and webhooks. Channel delivery and the Socket.IO relay require
+a signed-in user session. Callers that
can only send a bearer (the vendored STT and embedding clients, the connector
module's proxy route, TinyCortex's Composio sync) send the key as
`Authorization: Bearer`, which the backend accepts because it recognises the