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(logging): scrub snake_case and JSON-quoted tokens, failed inbound details, and query-char passwords
M3gA-Mind556182aa8023
diff --git a/crates/openhuman-core/src/config/schema/storage.rs b/crates/openhuman-core/src/config/schema/storage.rsindex 7edf34f76e..84fca80ae9 100644--- a/crates/openhuman-core/src/config/schema/storage.rs+++ b/crates/openhuman-core/src/config/schema/storage.rs@@ -79,15 +79,19 @@ impl std::fmt::Debug for StorageConfig {/// query string and fragment dropped (they can carry tokens, such as MongoDB's/// `authMechanismProperties`).pub fn redact_url(url: &str) -> String {- let end = url.find(['?', '#']).unwrap_or(url.len());- let (base, trimmed) = (&url[..end], end < url.len());- let mut out = match (base.find("://"), base.rfind('@')) {- (Some(scheme), Some(at)) if at > scheme => {- format!("{}://***@{}", &base[..scheme], &base[at + 1..])- }- _ => base.to_string(),+ // Userinfo ends at the LAST `@`, so an unencoded `?`, `#` or `/` in the+ // password can't end it early. A query that holds an `@` hides the host+ // too, which errs on the safe side.+ let (mut out, rest) = match url.split_once("://") {+ Some((scheme, rest)) => match rest.rsplit_once('@') {+ Some((_, host)) => (format!("{scheme}://***@"), host),+ None => (format!("{scheme}://"), rest),+ },+ None => (String::new(), url),};- if trimmed {+ let end = rest.find(['?', '#']).unwrap_or(rest.len());+ out.push_str(&rest[..end]);+ if end < rest.len() {out.push_str("?***");}outdiff --git a/crates/openhuman-core/src/config/schema/storage_tests.rs b/crates/openhuman-core/src/config/schema/storage_tests.rsindex cfad7748a2..b86675c077 100644--- a/crates/openhuman-core/src/config/schema/storage_tests.rs+++ b/crates/openhuman-core/src/config/schema/storage_tests.rs@@ -51,3 +51,14 @@ fn journal_retention_defaults_to_thirty_days_and_reads_from_toml() {let set: StorageConfig = toml::from_str("journal_retention_days = 7").unwrap();assert_eq!(set.journal_retention_days, 7);}++#[test]+fn redact_hides_userinfo_when_the_password_has_a_query_char() {+ for url in [+ "mongodb://app:[email protected]/oh",+ "mongodb://app:p#[email protected]/oh",+ "mongodb://app:p/[email protected]/oh",+ ] {+ assert_eq!(redact_url(url), "mongodb://***@db.internal/oh", "{url}");+ }+}diff --git a/crates/openhuman-core/src/core/log_redaction.rs b/crates/openhuman-core/src/core/log_redaction.rsindex a8af0a1c0d..2389faad1e 100644--- a/crates/openhuman-core/src/core/log_redaction.rs+++ b/crates/openhuman-core/src/core/log_redaction.rs@@ -16,14 +16,16 @@ static SECRET_PATTERNS: Lazy<Vec<(Regex, &'static str)>> = Lazy::new(|| {vec![// Matches "Bearer <token>" and redacts the token.(Regex::new(r"(?i)(bearer\s+)\S+").unwrap(), "${1}[REDACTED]"),- // Matches "api-key: <key>" or "api_key=<key>" and redacts the key.+ // Matches a named credential key and redacts its value: `api_key=…`,+ // `access_token=…`, and JSON-quoted `"token":"…"`. The key list is an+ // allowlist so `cancellation_token=` and the like stay intact.(- Regex::new(r"(?i)(api[_-]?key[=:\s]+)\S+").unwrap(),- "${1}[REDACTED]",+ Regex::new(r#"(?i)\b((?:access_|refresh_|id_|auth_|session_|bearer_)?token|api[_-]?key|client_secret|password)("?\s*[=:]\s*"?)[^\s"&,;}]+"#).unwrap(),+ "${1}${2}[REDACTED]",),- // \b anchor prevents matching `cancellation_token=` etc.+ // HTTP Basic credentials.(- Regex::new(r"(?i)\b(token[=:\s]+)\S+").unwrap(),+ Regex::new(r"(?i)(basic\s+)[A-Za-z0-9+/=]{8,}").unwrap(),"${1}[REDACTED]",),// Anthropic keys (sk-ant-api03-...) contain hyphens the genericdiff --git a/crates/openhuman-core/src/core/log_redaction_tests.rs b/crates/openhuman-core/src/core/log_redaction_tests.rsindex 4055fe29f4..0871003c1b 100644--- a/crates/openhuman-core/src/core/log_redaction_tests.rs+++ b/crates/openhuman-core/src/core/log_redaction_tests.rs@@ -38,3 +38,20 @@ fn leaves_plain_diagnostics_intact() {let msg = "profile 42: derived rate clamp exceeded (max_iterations=8)";assert_eq!(scrub_secrets(msg), msg);}++#[test]+fn scrubs_snake_case_and_json_quoted_tokens() {+ let out = scrub_secrets("cb?access_token=abc123&refresh_token=def456");+ assert!(!out.contains("abc123") && !out.contains("def456"), "{out}");+ let out = scrub_secrets(r#"{"token":"ghi789","api_key":"jkl012"}"#);+ assert!(!out.contains("ghi789") && !out.contains("jkl012"), "{out}");+ assert_eq!(+ scrub_secrets("Authorization: Basic dXNlcjpwYXNzd29yZA=="),+ "Authorization: Basic [REDACTED]"+ );+ // Only named credential keys: a cancellation token is not a secret.+ assert_eq!(+ scrub_secrets("cancellation_token=abc"),+ "cancellation_token=abc"+ );+}diff --git a/crates/openhuman-core/src/inbound/pinned.rs b/crates/openhuman-core/src/inbound/pinned.rsindex 2e66b7ebde..bee5d554f1 100644--- a/crates/openhuman-core/src/inbound/pinned.rs+++ b/crates/openhuman-core/src/inbound/pinned.rs@@ -382,7 +382,11 @@ impl Pinned {/// Store `turn_id` as failed with `detail` and publish/// `InboundTurnFailed`.pub fn fail(&self, turn_id: &str, detail: &str) {- let detail: String = detail.chars().take(MAX_DETAIL_CHARS).collect();+ // Scrub before truncating so a cut secret can't slip past the patterns.+ let detail: String = crate::core::log_redaction::scrub_secrets(detail)+ .chars()+ .take(MAX_DETAIL_CHARS)+ .collect();match self.results.finish(turn_id, Err(detail.clone()), now_ms()) {Ok(Some(stored)) => {tracing::warn!(turn = %turn_id, detail = %detail, "[inbound] pinned turn failed");diff --git a/crates/openhuman-core/src/inbound/pinned_tests.rs b/crates/openhuman-core/src/inbound/pinned_tests.rsindex 359b710945..298cac510b 100644--- a/crates/openhuman-core/src/inbound/pinned_tests.rs+++ b/crates/openhuman-core/src/inbound/pinned_tests.rs@@ -108,3 +108,29 @@ fn the_turn_events_belong_to_the_inbound_domain_and_say_what_ran() {Some("x:mentions/mentions turn t1: provider down"));}++#[tokio::test]+async fn a_failed_turn_stores_its_detail_scrubbed() {+ let results = memory_results();+ results+ .start(&Stored::running(+ "t-fail",+ "x:mentions",+ "mentions",+ "teeny-mentions",+ vec!["1".into()],+ "msg",+ 5,+ ))+ .unwrap();+ let agent = ScriptedAgent::new([]);+ let pinned = Pinned::new(agent as Arc<dyn PinnedAgent>, results.clone());+ pinned.fail(+ "t-fail",+ "provider said 401 for Bearer sk-live-SECRETSECRETSECRET1234",+ );+ let stored = results.get("t-fail").unwrap().unwrap();+ let error = stored.result.error.unwrap();+ assert!(!error.contains("SECRETSECRET"), "{error}");+ assert!(error.contains("[REDACTED]"), "{error}");+}