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
refactor(security): delegate home path redaction to tinyredact
Steven Enamakel0eaa20387f37
diff --git a/crates/openhuman-core/src/security/approval/redact.rs b/crates/openhuman-core/src/security/approval/redact.rsindex 7f3d44fdcd..64912618e3 100644--- a/crates/openhuman-core/src/security/approval/redact.rs+++ b/crates/openhuman-core/src/security/approval/redact.rs@@ -96,7 +96,7 @@ fn walk(value: &Value) -> Value {match value {Value::Object(map) => Value::Object(walk_object(map)),Value::Array(items) => Value::Array(items.iter().map(walk).collect()),- Value::String(s) => Value::String(scrub_paths(s)),+ Value::String(s) => Value::String(tinyredact::redact_home_paths(s)),other => other.clone(),}}@@ -131,79 +131,6 @@ fn redact_value(value: &Value) -> Value {}}-/// Strip absolute home paths so the action summary cannot leak the-/// user's username on multi-tenant log shipping.-///-/// Handles both Unix (`/Users/<name>/…`, `/home/<name>/…`) and-/// Windows (`C:\Users\<name>\…`) shapes — `MAIN_SEPARATOR` alone-/// would miss the Windows case in a Unix-built artifact looking at-/// log payloads that originated on Windows, or vice versa.-fn scrub_paths(input: &str) -> String {- // Fast-path bailout: if `input` contains neither "users" nor "home" it holds- // no home prefix for `match_home_prefix` to find, so skip the walk. This- // guard MUST be case-insensitive to match the matcher below, which folds case- // via `eq_ignore_ascii_case`. A case-sensitive check let non-canonical- // casings like `c:\users\alice` or `/HOME/alice` short-circuit here and get- // returned verbatim, leaking the OS username into the durable approval audit- // row instead of redacting it to `<HOME>`. Scan the bytes in place with a- // sliding window rather than allocating a full lowercase copy — tool args can- // be large (source/file contents), and the common case bails without a match.- let bytes = input.as_bytes();- let has_users = bytes.windows(5).any(|w| w.eq_ignore_ascii_case(b"users"));- let has_home = bytes.windows(4).any(|w| w.eq_ignore_ascii_case(b"home"));- if !has_users && !has_home {- return input.to_string();- }- let mut out = String::with_capacity(input.len());- let mut i = 0;- while i < input.len() {- if let Some(prefix_len) = match_home_prefix(&input[i..]) {- out.push_str("<HOME>");- i += prefix_len;- // Skip past the username segment up to the next path- // separator (or end of input).- let rest = &input[i..];- match rest.find(['/', '\\']) {- Some(end) => i += end,- None => i = input.len(),- }- } else {- // Push one char and advance — char-safe so we don't- // split a multi-byte UTF-8 codepoint.- let ch = input[i..].chars().next().unwrap();- out.push(ch);- i += ch.len_utf8();- }- }- out-}--/// Detects the start of an absolute home path at the front of `s`.-/// Returns the byte length of the marker (so `s[len..]` is the-/// username's first character) when matched, `None` otherwise.-fn match_home_prefix(s: &str) -> Option<usize> {- let bytes = s.as_bytes();- let starts_with_ci = |needle: &str| -> bool {- bytes.len() >= needle.len() && bytes[..needle.len()].eq_ignore_ascii_case(needle.as_bytes())- };- if starts_with_ci("/Users/") {- return Some(7);- }- if starts_with_ci("/home/") {- return Some(6);- }- // Windows — accept any drive letter + `:\Users\`- if bytes.len() >= 9- && bytes[0].is_ascii_alphabetic()- && bytes[1] == b':'- && bytes[2] == b'\\'- && bytes[3..9].eq_ignore_ascii_case(b"Users\\")- {- return Some(9);- }- None-}-/// Build a short human-readable summary of an approval-bound tool/// call. Pulls a handful of safe fields (`action`, `tool_slug`,/// `integration`, etc.) and tacks on a redacted-byte-count hint sodiff --git a/crates/openhuman-core/src/security/approval/redact_tests.rs b/crates/openhuman-core/src/security/approval/redact_tests.rsindex 7a050efc7b..88e9695bc3 100644--- a/crates/openhuman-core/src/security/approval/redact_tests.rs+++ b/crates/openhuman-core/src/security/approval/redact_tests.rs@@ -164,90 +164,6 @@ fn array_field_redacts_to_count_marker() {);}-#[test]-fn home_path_in_unredacted_string_is_scrubbed() {- let args = json!({ "action": "list", "cwd": "/Users/oxoxdev/work/openhuman" });- let red = redact_args(&args);- let cwd = red["cwd"].as_str().unwrap();- assert!(!cwd.contains("oxoxdev"), "got {cwd}");- assert!(cwd.contains("<HOME>"));- assert!(cwd.ends_with("/work/openhuman"));-}--#[test]-fn windows_home_path_is_scrubbed() {- let args = json!({ "action": "list", "cwd": "C:\\Users\\oxoxdev\\work\\openhuman" });- let red = redact_args(&args);- let cwd = red["cwd"].as_str().unwrap();- assert!(!cwd.contains("oxoxdev"), "got {cwd}");- assert!(cwd.contains("<HOME>"));- assert!(cwd.ends_with("\\work\\openhuman"));-}--#[test]-fn linux_home_path_is_scrubbed() {- let args = json!({ "action": "list", "cwd": "/home/jane/project" });- let red = redact_args(&args);- let cwd = red["cwd"].as_str().unwrap();- assert!(!cwd.contains("jane"), "got {cwd}");- assert!(cwd.contains("<HOME>"));- assert!(cwd.ends_with("/project"));-}--#[test]-fn lowercase_windows_home_path_is_scrubbed() {- // Regression: the fast-path guard was case-sensitive while the matcher is- // case-insensitive, so a lowercase drive/`users` casing slipped through- // unredacted and leaked the username.- let args = json!({ "action": "list", "cwd": "c:\\users\\alice\\work" });- let red = redact_args(&args);- let cwd = red["cwd"].as_str().unwrap();- assert!(!cwd.contains("alice"), "got {cwd}");- assert!(cwd.contains("<HOME>"));- assert!(cwd.ends_with("\\work"));-}--#[test]-fn uppercase_linux_home_path_is_scrubbed() {- let args = json!({ "action": "list", "cwd": "/HOME/alice/work" });- let red = redact_args(&args);- let cwd = red["cwd"].as_str().unwrap();- assert!(!cwd.contains("alice"), "got {cwd}");- assert!(cwd.contains("<HOME>"));- assert!(cwd.ends_with("/work"));-}--#[test]-fn mixed_case_home_path_is_scrubbed() {- let args = json!({ "action": "list", "cwd": "/Home/alice/work" });- let red = redact_args(&args);- let cwd = red["cwd"].as_str().unwrap();- assert!(!cwd.contains("alice"), "got {cwd}");- assert!(cwd.contains("<HOME>"));- assert!(cwd.ends_with("/work"));-}--#[test]-fn non_path_string_without_home_marker_is_unchanged() {- // The guard's fast-path must still return unrelated strings verbatim.- let args = json!({ "action": "run", "command": "echo hello world" });- let red = redact_args(&args);- assert_eq!(red["command"].as_str().unwrap(), "echo hello world");-}--#[test]-fn multiple_home_paths_in_same_string_all_scrubbed() {- let args = json!({- "action": "list",- "summary": "from /Users/alice/a.txt to /Users/bob/b.txt",- });- let red = redact_args(&args);- let summary = red["summary"].as_str().unwrap();- assert!(!summary.contains("alice"));- assert!(!summary.contains("bob"));- assert_eq!(summary.matches("<HOME>").count(), 2);-}-#[test]fn file_handoff_links_are_redacted() {// A presigned storage link is a bearer capability: anyone holding thediff --git a/crates/openhuman-core/src/security/approval/store_persistence_tests.rs b/crates/openhuman-core/src/security/approval/store_persistence_tests.rsindex a9c36e6dba..1ff59549ea 100644--- a/crates/openhuman-core/src/security/approval/store_persistence_tests.rs+++ b/crates/openhuman-core/src/security/approval/store_persistence_tests.rs@@ -10,6 +10,23 @@ fn insert_then_list_returns_pending_row() {assert_eq!(rows[0].tool_name, "composio");}+#[test]+fn approval_payload_home_path_is_redacted_before_persistence() {+ let (config, _dir) = test_config();+ let mut pending = sample("home-path", "sess-A");+ pending.args_redacted = crate::security::approval::redact_args(&json!({+ "action": "list",+ "cwd": "/Users/approval-user/work/openhuman",+ }));++ insert_pending(&config, &pending, "sess-A").unwrap();+ let stored = list_pending(&config).unwrap();+ let cwd = stored[0]["args_redacted"]["cwd"].as_str().unwrap();+ assert!(!cwd.contains("approval-user"), "stored {cwd}");+ assert!(cwd.contains("<HOME>"), "stored {cwd}");+ assert!(cwd.ends_with("/work/openhuman"), "stored {cwd}");+}+#[test]fn list_pending_returns_rows_from_every_session() {let (config, _dir) = test_config();