Skip to content

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

fix(composio): handle missing credential fields gracefully

Steven Enamakel44538cac9456
diff --git a/crates/openhuman-core/src/integrations/composio/client/credential.rs b/crates/openhuman-core/src/integrations/composio/client/credential.rs
new file mode 100644
index 0000000000..ecad25f059
--- /dev/null
+++ b/crates/openhuman-core/src/integrations/composio/client/credential.rs
@@ -0,0 +1,167 @@
+//! The key and base URL a direct-mode read is made with.
+//!
+//! Direct reads run in the `tinyconnectors` module over the bus
+//! (`ListConnectionsDirect` / `ListToolsDirect`). The module owns the HTTP, the
+//! paths and the response reshaping; this type is only what the host decides
+//! and validates before a call: which key, and which base URL, refusing
+//! anything that could send the key over plain HTTP to a remote host.
+
+use tinyconnectors_bus::ComposioDirectCredential;
+
+/// Composio's production v3 API root. The module's own default is the same
+/// URL, so a credential on it sends no override.
+const COMPOSIO_API_BASE_V3: &str = "https://backend.composio.dev/api/v3";
+
+pub(super) fn ensure_https(url: &str) -> anyhow::Result<()> {
+ if !url.starts_with("https://") {
+ anyhow::bail!(
+ "Refusing to transmit sensitive data over non-HTTPS URL: URL scheme must be https"
+ );
+ }
+ Ok(())
+}
+
+pub(super) fn is_loopback_http_url(url: &str) -> bool {
+ // Parse rather than prefix-match: a raw `starts_with("http://127.0.0.1:")`
+ // is fooled by userinfo smuggling like
+ // `http://127.0.0.1:[email protected]/api/v3/tools`, which an HTTP client routes
+ // to the *parsed* host (`evil.com`). Verify the actual scheme + host and
+ // reject any embedded credentials so the insecure-loopback path can never
+ // leak the `x-api-key` header to a non-loopback host.
+ let Ok(parsed) = url::Url::parse(url) else {
+ return false;
+ };
+ if parsed.scheme() != "http" {
+ return false;
+ }
+ if !parsed.username().is_empty() || parsed.password().is_some() {
+ return false;
+ }
+ match parsed.host() {
+ Some(url::Host::Domain(host)) => host.eq_ignore_ascii_case("localhost"),
+ Some(url::Host::Ipv4(ip)) => ip.is_loopback(),
+ Some(url::Host::Ipv6(ip)) => ip.is_loopback(),
+ None => false,
+ }
+}
+
+pub(super) fn is_loopback_http_base(url: &str) -> bool {
+ is_loopback_http_url(&format!("{}/", url.trim_end_matches('/')))
+}
+
+/// A Composio API key and the v3 base URL to use it against.
+///
+/// Held by [`super::ComposioRoute::Direct`]. The key is never printed: `Debug`
+/// shows the base URL only.
+pub struct DirectCredential {
+ api_key: String,
+ /// `None` is Composio's production API; `Some` is a validated override (a
+ /// host-pinned tenant URL, or a loopback test server in debug builds).
+ base_v3: Option<String>,
+}
+
+// Manual `Debug`: never prints the key.
+impl std::fmt::Debug for DirectCredential {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("DirectCredential")
+ .field("base_v3", &self.base_v3)
+ .finish_non_exhaustive()
+ }
+}
+
+impl DirectCredential {
+ /// A credential for Composio's production API.
+ pub fn new(api_key: &str) -> Self {
+ Self::new_internal(api_key, None)
+ }
+
+ pub(crate) fn auth_key_fingerprint(&self) -> u64 {
+ crate::integrations::composio::direct_auth::fingerprint_api_key(&self.api_key)
+ }
+
+ /// Debug-test seam for raw integration coverage: a credential against
+ /// explicit v2/v3 base URLs. Non-HTTPS URLs are accepted only for loopback
+ /// hosts and only in debug builds.
+ ///
+ /// The v2 root is validated for the same safety rule but not kept: no
+ /// remaining request path uses it.
+ #[cfg(debug_assertions)]
+ pub fn new_with_base_urls_for_loopback(
+ api_key: &str,
+ base_v2: String,
+ base_v3: String,
+ ) -> anyhow::Result<Self> {
+ for base in [&base_v2, &base_v3] {
+ if !base.starts_with("https://") && !is_loopback_http_base(base) {
+ anyhow::bail!("debug Composio base URL must be HTTPS or loopback HTTP");
+ }
+ }
+ Ok(Self::new_internal(api_key, Some(base_v3)))
+ }
+
+ /// A credential against explicit v2/v3 API roots. Both must be HTTPS;
+ /// loopback HTTP is accepted only in debug builds.
+ pub fn new_with_base_urls(
+ api_key: &str,
+ base_v2: String,
+ base_v3: String,
+ ) -> anyhow::Result<Self> {
+ let allow_loopback = cfg!(debug_assertions);
+ for base in [&base_v2, &base_v3] {
+ let accepted =
+ base.starts_with("https://") || (allow_loopback && is_loopback_http_base(base));
+ if !accepted {
+ anyhow::bail!("Composio base URL must be HTTPS");
+ }
+ }
+ Ok(Self::new_internal(api_key, Some(base_v3)))
+ }
+
+ /// Test-only seam: a credential against an explicit v3 base so a test can
+ /// point the module's reads at a local mock instead of `backend.composio.dev`.
+ ///
+ /// `#[cfg(test)]`-gated on purpose: an injectable base must never carry a
+ /// non-HTTPS URL outside tests. Production reaches the module through
+ /// [`Self::new`] or the validated constructors above.
+ #[cfg(test)]
+ pub(crate) fn new_with_v3_base(api_key: &str, base_v3: String) -> Self {
+ Self::new_internal(api_key, Some(base_v3))
+ }
+
+ fn new_internal(api_key: &str, base_v3: Option<String>) -> Self {
+ let trimmed = api_key.trim();
+ if trimmed.len() != api_key.len() {
+ // The key carried leading/trailing whitespace that would otherwise
+ // reach Composio's `x-api-key` header verbatim and trip the
+ // server-side "Invalid API key format" 401 (Sentry TAURI-RUST-D3).
+ // We trim here so the request succeeds; logging the length delta
+ // (never the key itself) helps trace which credential source
+ // produced a dirty value without leaking the secret.
+ tracing::debug!(
+ original_len = api_key.len(),
+ trimmed_len = trimmed.len(),
+ "[composio] trimmed leading/trailing whitespace from api_key"
+ );
+ }
+ Self {
+ api_key: trimmed.to_string(),
+ base_v3,
+ }
+ }
+
+ /// The v3 base this credential reads from.
+ fn effective_base(&self) -> &str {
+ self.base_v3.as_deref().unwrap_or(COMPOSIO_API_BASE_V3)
+ }
+
+ /// What the module is handed for one read: this key, the base override if
+ /// there is one, and the host's proxy and TLS policy for that destination.
+ pub(super) fn module_credential(&self) -> ComposioDirectCredential {
+ ComposioDirectCredential {
+ api_key: self.api_key.clone(),
+ entity_id: None,
+ base_url: self.base_v3.clone(),
+ transport: super::network::module_transport(self.effective_base()),
+ }
+ }
+}
diff --git a/crates/openhuman-core/src/integrations/composio/client/network.rs b/crates/openhuman-core/src/integrations/composio/client/network.rs
new file mode 100644
index 0000000000..f3fe15394f
--- /dev/null
+++ b/crates/openhuman-core/src/integrations/composio/client/network.rs
@@ -0,0 +1,80 @@
+//! The host's proxy and TLS policy for Composio, as the module is told it.
+//!
+//! The module's HTTP client cannot read the host's runtime proxy settings or
+//! its TLS store, so the host resolves its policy for the `tool.composio`
+//! service for one destination and hands it over: through `Configure` for the
+//! configured route, and on every stateless direct read.
+//!
+//! The decision stays here. Whether a proxy applies at all
+//! (`ProxyConfig::should_apply_to_service`: enabled, and the scope covers this
+//! service), which URL serves a destination (`all_proxy` first, then the one
+//! for the destination's scheme, which is the order the host's own `reqwest`
+//! clients try them), and which hosts bypass it. The module only applies the
+//! result.
+
+use tinyconnectors_bus::{ComposioTlsRoots, ComposioTransportConfig};
+
+use crate::config::runtime_proxy_config;
+
+/// The proxy service key Composio traffic is scoped under.
+const SERVICE_KEY: &str = "tool.composio";
+
+fn usable(url: Option<&String>) -> Option<String> {
+ let url = url?.trim();
+ if url.is_empty() {
+ return None;
+ }
+ // The host's `reqwest` clients ignore a proxy URL they cannot parse (and
+ // warn); do the same instead of failing every Composio call over it.
+ match reqwest::Proxy::all(url) {
+ Ok(_) => Some(url.to_string()),
+ Err(error) => {
+ tracing::warn!(error = %error, "[composio-direct] ignoring an unusable proxy URL");
+ None
+ }
+ }
+}
+
+/// The network policy for a request to `base_url`, or `None` when it is the
+/// module's default (no proxy of the host's choosing, bundled roots).
+pub(super) fn module_transport(base_url: &str) -> Option<ComposioTransportConfig> {
+ let proxy = runtime_proxy_config();
+ let proxy_url = if proxy.should_apply_to_service(SERVICE_KEY) {
+ let https = base_url.trim().to_ascii_lowercase().starts_with("https://");
+ usable(proxy.all_proxy.as_ref()).or_else(|| {
+ if https {
+ usable(proxy.https_proxy.as_ref())
+ } else {
+ usable(proxy.http_proxy.as_ref())
+ }
+ })
+ } else {
+ None
+ };
+ let tls_roots = if cfg!(target_os = "windows") {
+ ComposioTlsRoots::Platform
+ } else {
+ ComposioTlsRoots::Bundled
+ };
+
+ let config = ComposioTransportConfig {
+ no_proxy: if proxy_url.is_some() {
+ proxy.normalized_no_proxy()
+ } else {
+ Vec::new()
+ },
+ proxy_url,
+ tls_roots,
+ };
+ tracing::debug!(
+ proxied = config.proxy_url.is_some(),
+ no_proxy_entries = config.no_proxy.len(),
+ platform_roots = config.tls_roots == ComposioTlsRoots::Platform,
+ "[composio-direct] module transport policy resolved"
+ );
+ (config != ComposioTransportConfig::default()).then_some(config)
+}
+
+#[cfg(test)]
+#[path = "network_tests.rs"]
+mod tests;