Skip to content

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

fix(mcp): redact short query credentials without corrupting unrelated words

Steven Enamakelc1535c197075
diff --git a/crates/openhuman-core/src/tools/impl/network/mcp.rs b/crates/openhuman-core/src/tools/impl/network/mcp.rs
index c8a3eae4c3..ddf8dacbd7 100644
--- a/crates/openhuman-core/src/tools/impl/network/mcp.rs
+++ b/crates/openhuman-core/src/tools/impl/network/mcp.rs
@@ -339,8 +339,26 @@ impl SecretScrubber {
.iter()
.any(|needle| name.contains(needle));
let value = value.into_owned();
- (credential_like && value.len() >= MIN_QUERY_SECRET_LEN).then_some(value)
+ credential_like.then_some(value)
}));
+ // Retain the spelling supplied in the endpoint: form decoding turns
+ // '+' into a space, which ordinary URL encoding does not recreate.
+ if let Some(query) = url.query() {
+ for pair in query.split('&') {
+ if let Some((name, value)) = pair.split_once('=') {
+ let decoded_name = url::form_urlencoded::parse(name.as_bytes())
+ .next()
+ .map(|(name, _)| name.to_ascii_lowercase())
+ .unwrap_or_default();
+ if CREDENTIAL_QUERY_PARAM_NEEDLES
+ .iter()
+ .any(|needle| decoded_name.contains(needle))
+ {
+ raw.push(value.to_string());
+ }
+ }
+ }
+ }
}
}
@@ -364,7 +382,28 @@ impl SecretScrubber {
fn scrub(&self, text: &str) -> String {
let mut out = text.to_string();
for secret in &self.secrets {
- if out.contains(secret.as_str()) {
+ if secret.len() < MIN_QUERY_SECRET_LEN {
+ // Short credentials are common words or field-name fragments;
+ // only replace a complete token so unrelated text stays usable.
+ let mut next = String::with_capacity(out.len());
+ let mut cursor = 0;
+ for (start, _) in out.match_indices(secret.as_str()) {
+ if start < cursor {
+ continue;
+ }
+ let end = start + secret.len();
+ let word_char = |ch: char| ch.is_alphanumeric() || ch == '_';
+ let before = out[..start].chars().next_back().is_some_and(word_char);
+ let after = out[end..].chars().next().is_some_and(word_char);
+ if !before && !after {
+ next.push_str(&out[cursor..start]);
+ next.push_str(REDACTED);
+ cursor = end;
+ }
+ }
+ next.push_str(&out[cursor..]);
+ out = next;
+ } else if out.contains(secret.as_str()) {
out = out.replace(secret.as_str(), REDACTED);
}
}
diff --git a/crates/openhuman-core/src/tools/impl/network/mcp_tests.rs b/crates/openhuman-core/src/tools/impl/network/mcp_tests.rs
index 2170018fde..0d751c8fec 100644
--- a/crates/openhuman-core/src/tools/impl/network/mcp_tests.rs
+++ b/crates/openhuman-core/src/tools/impl/network/mcp_tests.rs
@@ -373,6 +373,31 @@ async fn endpoint_query_secrets_are_redacted_from_errors() {
assert!(!rendered.contains(SECRET), "{rendered}");
}
+#[tokio::test]
+async fn encoded_query_secrets_are_redacted_from_successful_results() {
+ let echo = "a+b%2Fc";
+ let server = echoing_server(echo, None).await;
+ let registry = registry_with(
+ &format!("{}/mcp?api_key={echo}", server.uri()),
+ crate::config::McpAuthConfig::None,
+ );
+ for result in [
+ call_tool(registry.clone())
+ .execute_with_options(call_args(), ToolCallOptions { prefer_markdown: true })
+ .await
+ .expect("call"),
+ McpListToolsTool::new(registry)
+ .execute(json!({ "server": "docs" }))
+ .await
+ .expect("list"),
+ ] {
+ let rendered = full_output(&result);
+ assert!(!result.is_error, "{rendered}");
+ assert!(rendered.contains(REDACTED), "{rendered}");
+ assert!(!rendered.contains(echo), "{rendered}");
+ }
+}
+
#[test]
fn scrubber_redacts_url_encoded_secrets_and_ignores_empty_values() {
let scrubber = SecretScrubber::new(
@@ -422,6 +447,19 @@ fn scrubber_redacts_credential_query_value() {
);
}
+#[test]
+fn scrubber_redacts_short_query_credentials_without_rewriting_words() {
+ let scrubber = SecretScrubber::new(
+ &McpDefinitionAuth::None,
+ "https://example.com/mcp?api_key=abc&v=2",
+ );
+ assert_eq!(
+ scrubber.scrub("abc is a credential; alphabet and abc_def are not"),
+ "[redacted] is a credential; alphabet and abc_def are not"
+ );
+ assert_eq!(scrubber.scrub("v=2"), "v=2");
+}
+
#[test]
fn scrub_value_keeps_both_entries_when_keys_collide_after_redaction() {
let scrubber = SecretScrubber::new(