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
fix(embed): sanitize credentials from URLs in Debug output
Steven Enamakel74e09a22755b
diff --git a/src/embed/agent.rs b/src/embed/agent.rsindex 522e271cbb..4624cc1054 100644--- a/src/embed/agent.rs+++ b/src/embed/agent.rs@@ -69,15 +69,34 @@ pub struct Route {impl std::fmt::Debug for Route {fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {- // The bearer is a credential; a derived Debug would spill it into- // `Provider`'s Debug and from there into host logs and error paths.+ // The bearer is a credential, and the base URL can itself carry+ // userinfo (`https://user:pass@host`) or query credentials; a derived+ // Debug would spill both into `Provider`'s Debug and from there into+ // host logs and error paths.f.debug_struct("Route")- .field("base_url", &self.base_url)+ .field("base_url", &sanitize_url_for_display(&self.base_url)).field("api_key", &"<redacted>").finish()}}+/// A URL safe to surface in logs/diagnostics: userinfo and query/fragment are+/// stripped, so `https://user:pass@host/v1?key=secret` renders as+/// `https://host/v1`. Falls back to the raw string only when it does not parse+/// as an absolute URL (e.g. a bare host or protocol-relative value), since+/// those carry no credential-bearing components to redact.+pub(crate) fn sanitize_url_for_display(url: &str) -> String {+ let Ok(parsed) = url::Url::parse(url) else {+ return url.to_string();+ };+ let mut out = parsed;+ let _ = out.set_username("");+ let _ = out.set_password(None);+ out.set_query(None);+ out.set_fragment(None);+ out.to_string()+}+impl Route {/// An OpenAI-compatible endpoint and the bearer that authenticates it.pub fn openai_compatible(base_url: impl Into<String>, api_key: impl Into<String>) -> Self {diff --git a/src/embed/harness/mcp.rs b/src/embed/harness/mcp.rsindex e78460bf6f..7af664d4ad 100644--- a/src/embed/harness/mcp.rs+++ b/src/embed/harness/mcp.rs@@ -39,7 +39,12 @@ impl std::fmt::Debug for McpServer {let cfg = &self.0;f.debug_struct("McpServer").field("name", &cfg.name)- .field("endpoint", &cfg.endpoint)+ // The endpoint can itself embed credentials (userinfo/query); show+ // a sanitized form so it cannot leak into host logs.+ .field(+ "endpoint",+ &crate::embed::agent::sanitize_url_for_display(&cfg.endpoint),+ ).field("command", &cfg.command).field("args", &cfg.args).field("env_redacted", &(!cfg.env.is_empty()))diff --git a/src/embed/harness/mcp_tests.rs b/src/embed/harness/mcp_tests.rsindex 49b064793e..77448b02f3 100644--- a/src/embed/harness/mcp_tests.rs+++ b/src/embed/harness/mcp_tests.rs@@ -89,3 +89,20 @@ fn debug_redacts_credentials() {);assert!(debug.contains("redacted"));}++#[test]+fn debug_redacts_credentials_embedded_in_the_endpoint() {+ // The endpoint can itself carry userinfo or query credentials; Debug must+ // strip them rather than print them verbatim.+ let server = McpServer::http(+ "remote",+ "https://user:[email protected]/v1?api_key=leaky",+ );+ let debug = format!("{server:?}");++ assert!(+ !debug.contains("s3cret") && !debug.contains("leaky"),+ "endpoint credentials leaked into Debug: {debug}"+ );+ assert!(debug.contains("mcp.example"), "origin stays readable");+}