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(agent): redact credential values in a listed shell command before it is stored
killbillca904d5b6ae4
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rsindex 50cd155db3..f33afbf6e1 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/repeated_failure.rs@@ -235,7 +235,7 @@ const RENDERED_FAILURES: usize = 8;/// whitespace-collapsed and bounded so a heredoc or payload cannot swamp it.fn render_call(tool: &str, arguments: &serde_json::Value) -> String {let raw = match arguments.get("command").and_then(serde_json::Value::as_str) {- Some(command) => command.to_owned(),+ Some(command) => redact_command_credentials(command),None if arguments.is_null() => tool.to_owned(),None => strip_url_queries(&crate::security::approval::redact_args(arguments)).to_string(),};@@ -244,6 +244,38 @@ fn render_call(tool: &str, arguments: &serde_json::Value) -> String {crate::util::truncate_with_ellipsis(&scrubbed, RENDERED_CALL_CHARS).to_string()}+/// A shell command with the values that follow credential-bearing flags,+/// headers and assignments replaced: `--password=…`, `--token …`,+/// `-H 'Authorization: Bearer …'`, `x-api-key: …`, `API_SECRET=…`. The flag,+/// header name or variable name stays, so the summary still says what the+/// command did; the value does not travel into the session. This is the+/// command-side counterpart of `redact_args` for the other tools; the+/// general scrubber still runs over the result for key shapes it knows.+fn redact_command_credentials(command: &str) -> String {+ use std::sync::LazyLock;+ static HEADER: LazyLock<regex::Regex> = LazyLock::new(|| {+ regex::Regex::new(+ r#"(?i)((?:authorization|x-api-key|api-key|x-auth-token|x-access-token|cookie|proxy-authorization)\s*:\s*)([^'\"\s][^'\"]*)"#,+ )+ .expect("static regex")+ });+ static FLAG: LazyLock<regex::Regex> = LazyLock::new(|| {+ regex::Regex::new(+ r#"(?i)(--?(?:password|passwd|pass|pwd|token|api[-_]?key|apikey|secret|auth|bearer|access[-_]?key|private[-_]?key|client[-_]?secret)(?:=|\s+))(['\"]?)([^\s'\"]+)"#,+ )+ .expect("static regex")+ });+ static ASSIGN: LazyLock<regex::Regex> = LazyLock::new(|| {+ regex::Regex::new(+ r#"(?i)\b([A-Z0-9_]*(?:KEY|TOKEN|SECRET|PASSWORD|PASSWD|CREDENTIAL)[A-Z0-9_]*=)(['\"]?)([^\s'\"]+)"#,+ )+ .expect("static regex")+ });+ let out = HEADER.replace_all(command, "${1}[REDACTED]");+ let out = FLAG.replace_all(&out, "${1}${2}[REDACTED]");+ ASSIGN.replace_all(&out, "${1}${2}[REDACTED]").into_owned()+}+/// `text` with every URL in it cut at its query or fragment, wherever the URL/// sits: at the start of a word, after `url=` or a quote, inside prose or a/// JSON string. The URL ends at the first whitespace or closing quote, bracketdiff --git a/crates/openhuman-core/src/agent/tinyagents/middleware_command_exit_failure_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware_command_exit_failure_tests.rsindex dbdd04b71d..de97776e50 100644--- a/crates/openhuman-core/src/agent/tinyagents/middleware_command_exit_failure_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/middleware_command_exit_failure_tests.rs@@ -399,11 +399,12 @@ async fn six_different_failing_commands_are_investigation_not_a_loop() {"apt-get install -y g++",exit_report(100, "", "E: Unable to locate package"),),- (- "pip download fasttext --no-deps",- exit_report(1, "", "network unreachable"),- ),];+ // Six distinct commands, each a different non-zero exit. None of them+ // feeds the no-progress ladder: a different command's exit report is+ // information, and only a *repeat* of the previous failing command counts+ // (see `last_exit_report`), so no number of distinct failing commands+ // reaches a threshold.for (i, (command, report)) in attempts.iter().enumerate() {run_shell(&mw,@@ -560,3 +561,50 @@ async fn queries_are_cut_from_urls_anywhere_in_an_argument() {"host, path and the surrounding text remain: {summary}");}++/// A shell command is stored for the halt summary with credential-bearing+/// values redacted before any other scrubbing: header values, `--password`+/// and `--token` style flags and `KEY=value` assignments with secret-looking+/// names, so a command that carries a secret in a shape the general scrubber+/// does not know is still not persisted with it.+#[tokio::test]+async fn a_listed_shell_command_never_carries_a_credential_value() {+ let handle = SteeringHandle::allow_all();+ let slot = std::sync::Arc::new(std::sync::Mutex::new(None));+ let mw = RepeatedToolFailureMiddleware::new(handle.clone(), 3, slot.clone());+ let commands = [+ "curl -H 'Authorization: Bearer hunter2token' https://example.test/a",+ "curl -H 'x-api-key: plainkeyvalue' https://example.test/b",+ "mysql --password=swordfish -e 'select 1'",+ "deploy --token tok_value_here --dry-run",+ "API_SECRET=s3cr3tvalue python go.py",+ "export DB_PASSWORD='pw-value'; ./migrate",+ ];+ for (i, command) in commands.iter().enumerate() {+ run_shell(+ &mw,+ &format!("sec-{i}"),+ command,+ failing_result("shell", "boom"),+ )+ .await;+ }+ let summary = slot+ .lock()+ .unwrap()+ .clone()+ .expect("six varied failures halt");+ for leaked in [+ "hunter2token",+ "plainkeyvalue",+ "swordfish",+ "tok_value_here",+ "s3cr3tvalue",+ "pw-value",+ ] {+ assert!(!summary.contains(leaked), "{leaked} leaked: {summary}");+ }+ for kept in ["curl -H", "mysql", "deploy --", "python go.py", "./migrate"] {+ assert!(summary.contains(kept), "{kept} missing: {summary}");+ }+}