Skip to content

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

fix(composio): sort secrets longest-first before redacting

oxoxDeveebd943f71d7
diff --git a/crates/openhuman-core/src/integrations/composio/tools/redact.rs b/crates/openhuman-core/src/integrations/composio/tools/redact.rs
index 4925291f4c..e28679e2ee 100644
--- a/crates/openhuman-core/src/integrations/composio/tools/redact.rs
+++ b/crates/openhuman-core/src/integrations/composio/tools/redact.rs
@@ -28,7 +28,7 @@ pub(crate) fn composio_secrets(config: &Config) -> Vec<String> {
}
}
secrets.retain(|s| s.len() >= MIN_SECRET_LEN);
- secrets.sort();
+ secrets.sort_by(|a, b| b.len().cmp(&a.len()).then_with(|| a.cmp(b)));
secrets.dedup();
secrets
}
diff --git a/crates/openhuman-core/src/integrations/composio/tools_redact_tests.rs b/crates/openhuman-core/src/integrations/composio/tools_redact_tests.rs
new file mode 100644
index 0000000000..de615b0f8d
--- /dev/null
+++ b/crates/openhuman-core/src/integrations/composio/tools_redact_tests.rs
@@ -0,0 +1,48 @@
+//! Regression coverage for `redact.rs` gaps flagged by review on PR #6689.
+
+use crate::config::{Config, ComposioHostCredential};
+use crate::integrations::composio::tools::redact_composio_outcome;
+
+const SHORT_KEY: &str = "abcdefgh";
+const LONG_KEY: &str = "abcdefghi";
+
+fn config_with_overlapping_secrets() -> Config {
+ let tmp = tempfile::tempdir().expect("tempdir for config_with_overlapping_secrets");
+ let mut config = Config::default();
+ config.config_path = tmp.path().join("config.toml");
+ config.composio.api_key = Some(LONG_KEY.to_string());
+ config
+ .composio
+ .pin_host_credential(ComposioHostCredential::direct(SHORT_KEY));
+ std::mem::forget(tmp);
+ config
+}
+
+/// Before the fix, `composio_secrets` lexicographically sorted
+/// `[SHORT_KEY, LONG_KEY]` (`SHORT_KEY` sorts first since it's a prefix)
+/// and redacted in that order, replacing `SHORT_KEY` everywhere first —
+/// including inside `LONG_KEY` — and leaving the trailing `i` behind
+/// instead of a clean `[REDACTED]`.
+#[test]
+fn overlapping_secrets_redact_longest_first() {
+ let config = config_with_overlapping_secrets();
+ let outcome = redact_composio_outcome(
+ &config,
+ Ok(tinytools::ToolResult::success(format!(
+ "token {LONG_KEY} in transit"
+ ))),
+ )
+ .unwrap();
+ let text = outcome
+ .content
+ .iter()
+ .filter_map(|c| match c {
+ tinytools::ToolContent::Text { text } => Some(text.as_str()),
+ _ => None,
+ })
+ .collect::<Vec<_>>()
+ .join(" ");
+ assert!(!text.contains(LONG_KEY), "{text}");
+ assert!(!text.contains(SHORT_KEY), "{text}");
+ assert_eq!(text, "token [REDACTED] in transit");
+}
diff --git a/crates/openhuman-core/src/integrations/composio/tools_tests.rs b/crates/openhuman-core/src/integrations/composio/tools_tests.rs
index ca6912e9e6..adf7127035 100644
--- a/crates/openhuman-core/src/integrations/composio/tools_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/tools_tests.rs
@@ -138,3 +138,5 @@ mod direct_mode_routing_tests;
mod host_credential_tests;
#[path = "tools_metadata_and_sandbox_tests.rs"]
mod metadata_and_sandbox_tests;
+#[path = "tools_redact_tests.rs"]
+mod redact_tests;