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
feat(backend): validate credential endpoint before making requests
Steven Enamakele7d6a21c186d
diff --git a/crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs b/crates/openhuman-core/src/inference/provider/openhuman_backend_model.rsindex f292e5ee6a..dd7664a875 100644--- a/crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs+++ b/crates/openhuman-core/src/inference/provider/openhuman_backend_model.rs@@ -60,13 +60,12 @@ pub(crate) fn is_safe_endpoint_for_managed_bearer(endpoint: &str) -> bool {if url.scheme() != "http" {return false;}- let Some(host) = url.host_str() else {- return false;- };- matches!(- host,- "127.0.0.1" | "localhost" | "::1" | "[::1]" | "[0:0:0:0:0:0:0:1]" | "0:0:0:0:0:0:0:1"- ) || host.starts_with("127.")+ url.host_str().is_some_and(|host| {+ host == "localhost"+ || host+ .parse::<std::net::IpAddr>()+ .is_ok_and(|address| address.is_loopback())+ })}/// API keys belong to TinyHumans. A loopback endpoint is permitted for local@@ -82,7 +81,12 @@ pub(crate) fn is_managed_endpoint_for_api_key(endpoint: &str) -> bool {url.host_str(),Some("api.tinyhumans.ai" | "staging-api.tinyhumans.ai")) && url.scheme() == "https"- || matches!(url.host_str(), Some("localhost" | "127.0.0.1" | "::1"))+ || url.host_str().is_some_and(|host| {+ host == "localhost"+ || host+ .parse::<std::net::IpAddr>()+ .is_ok_and(|address| address.is_loopback())+ })}/// The managed OpenHuman backend as a crate [`ChatModel`]. Holds the backenddiff --git a/crates/openhuman-core/src/integrations/client/construct.rs b/crates/openhuman-core/src/integrations/client/construct.rsindex 685a3614aa..fa9066f950 100644--- a/crates/openhuman-core/src/integrations/client/construct.rs+++ b/crates/openhuman-core/src/integrations/client/construct.rs@@ -95,10 +95,25 @@ impl IntegrationClient {/// (binary download, raw DELETE): `Authorization: Bearer` for a session,/// `x-api-key` for an API key.pub(crate) fn auth_headers(&self) -> anyhow::Result<reqwest::header::HeaderMap> {+ self.validate_credential_endpoint()?;crate::backend::transport::credential_headers(&self.credential).map_err(|e| anyhow::anyhow!("invalid backend credential header: {e}"))}+ pub(super) fn validate_credential_endpoint(&self) -> anyhow::Result<()> {+ let endpoint = &self.backend_url;+ if self.uses_api_key()+ && !crate::inference::provider::openhuman_backend_model::is_managed_endpoint_for_api_key(endpoint)+ {+ anyhow::bail!("TinyHumans API key requires the managed backend or a loopback endpoint");+ }+ if !crate::inference::provider::openhuman_backend_model::is_safe_endpoint_for_managed_bearer(endpoint)+ {+ anyhow::bail!("backend credential requires HTTPS or a loopback HTTP endpoint");+ }+ Ok(())+ }+fn new_inner(backend_url: String,credential: crate::security::credentials::session_support::BackendCredential,diff --git a/crates/openhuman-core/src/integrations/client/download.rs b/crates/openhuman-core/src/integrations/client/download.rsindex 1a46974fbd..36f4a84788 100644--- a/crates/openhuman-core/src/integrations/client/download.rs+++ b/crates/openhuman-core/src/integrations/client/download.rs@@ -52,6 +52,7 @@ impl IntegrationClient {&self,path: &str,) -> anyhow::Result<(bytes::Bytes, Option<String>, Option<String>)> {+ self.validate_credential_endpoint()?;enforce_backend_egress(path)?;emit_backend_egress(path);self.ensure_budget_available(path).await?;diff --git a/crates/openhuman-core/src/integrations/client/requests.rs b/crates/openhuman-core/src/integrations/client/requests.rsindex 669121720a..857d2deb76 100644--- a/crates/openhuman-core/src/integrations/client/requests.rs+++ b/crates/openhuman-core/src/integrations/client/requests.rs@@ -118,6 +118,7 @@ impl IntegrationClient {path: &str,body: Option<&serde_json::Value>,) -> anyhow::Result<T> {+ self.validate_credential_endpoint()?;reject_privileged_backend_path(method.as_str(), path)?;enforce_backend_egress(path)?;emit_backend_egress(path);@@ -161,6 +162,7 @@ impl IntegrationClient {path: &str,form: reqwest::multipart::Form,) -> anyhow::Result<T> {+ self.validate_credential_endpoint()?;reject_privileged_backend_path("POST", path)?;enforce_backend_egress(path)?;emit_backend_egress(path);diff --git a/crates/openhuman-core/src/platform/socket/url_tests.rs b/crates/openhuman-core/src/platform/socket/url_tests.rsindex 038ca76436..4a965ec4d6 100644--- a/crates/openhuman-core/src/platform/socket/url_tests.rs+++ b/crates/openhuman-core/src/platform/socket/url_tests.rs@@ -10,6 +10,7 @@ fn credential_socket_endpoint_requires_tls_or_loopback() {"ws://api.tinyhumans.ai/socket.io/"));assert!(!is_safe_socket_endpoint("ws://example.com/socket.io/"));+ assert!(!is_safe_socket_endpoint("ws://127.attacker.example/socket.io/"));}#[test]diff --git a/crates/openhuman-embed/README.md b/crates/openhuman-embed/README.mdindex 8836ed7fe6..da77cde126 100644--- a/crates/openhuman-embed/README.md+++ b/crates/openhuman-embed/README.md@@ -148,7 +148,7 @@ its own `Provider` (BYOK) never touches the key.The key covers every hosted feature the core reaches: managed inference, cloudembeddings, voice (STT, TTS, the realtime voice agent), web search, mediageneration, the Jev ranker, Composio and the other `/agent-integrations/*`-tools, referral, and webhooks. Channel delivery and the Socket.IO relay require+tools, channel delivery, referral, and webhooks. The Socket.IO relay requiresa signed-in user session. Callers thatcan only send a bearer (the vendored STT and embedding clients, the connectormodule's proxy route, TinyCortex's Composio sync) send the key as