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
test(security): cover credential scrubbing in gate and driver
Steven Enamakelbcd3886d1ce3
diff --git a/crates/openhuman-core/src/agent/session_host/driver_tests.rs b/crates/openhuman-core/src/agent/session_host/driver_tests.rsindex 0b25d057c1..0ad231088f 100644--- a/crates/openhuman-core/src/agent/session_host/driver_tests.rs+++ b/crates/openhuman-core/src/agent/session_host/driver_tests.rs@@ -1,5 +1,52 @@use super::*;+#[test]+fn cancelled_seed_history_is_scrubbed_before_snapshot_fallback() {+ let secret: String = [+ 's', 'k', '-', 'l', 'i', 'v', 'e', '-', '0', '1', '2', '3', '4', '5', '6', '7',+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',+ 'o', 'p',+ ]+ .into_iter()+ .collect();+ let mut history = vec![+ Message::system("stable prefix"),+ Message::user(format!("please use {secret}")),+ Message::assistant("earlier answer"),+ ];++ scrub_user_history(&mut history, true);+ let snapshot = Arc::new(std::sync::Mutex::new(+ crate::agent::tinyagents::middleware::turn_context::TranscriptSnapshot::default(),+ ));+ let failure = driver_cancelled_with_snapshot(+ &snapshot,+ &sidecar(),+ std::time::Duration::from_millis(1),+ history,+ );+ let partial = failure.partial.expect("cancel returns resumable history");+ let joined = partial.history.iter().map(Message::text).collect::<Vec<_>>().join("\n");+ assert!(!joined.contains(&secret));+ assert!(joined.contains("stable prefix"));+ assert!(joined.contains("earlier answer"));+}++#[test]+fn untrusted_turn_history_is_not_scrubbed() {+ let secret: String = [+ 's', 'k', '-', 'l', 'i', 'v', 'e', '-', '0', '1', '2', '3', '4', '5', '6', '7',+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',+ 'o', 'p',+ ]+ .into_iter()+ .collect();+ let original = Message::user(format!("please use {secret}"));+ let mut history = vec![original.clone()];+ scrub_user_history(&mut history, false);+ assert_eq!(history, vec![original]);+}+fn sidecar() -> std::sync::Arc<std::sync::Mutex<crate::agent::tinyagents::host::run_context::SessionTurnSidecar>>{diff --git a/crates/openhuman-core/src/agent/tinyagents/host/security_gate_screen_and_policy_tests.rs b/crates/openhuman-core/src/agent/tinyagents/host/security_gate_screen_and_policy_tests.rsindex 202bfa1b0d..139e4450fc 100644--- a/crates/openhuman-core/src/agent/tinyagents/host/security_gate_screen_and_policy_tests.rs+++ b/crates/openhuman-core/src/agent/tinyagents/host/security_gate_screen_and_policy_tests.rs@@ -186,29 +186,38 @@ async fn allow_and_deny_channel_verdicts_are_unchanged() {assert!(matches!(denied, GateDecision::Deny { .. }));}-/// Tripwire for #6710. The hosted root marks replayed history with-/// `with_replayed_prefix`, which is only safe while replayed user rows are what-/// the gate admitted. The session driver persists the RAW turn input-/// (`session_host/driver.rs`, `let mut history = request.history`), so the day-/// this gate starts returning `Redacted` (the phase-4 TODO on `screen_input`), a-/// redacted secret would reach the model raw on every later turn. Revisit that-/// opt-in, or persist the redacted form, before changing this assertion.+/// Credential-like input is rewritten with the shared hosted scrubber before+/// it enters the model context.#[tokio::test]-async fn screen_input_never_redacts_while_replayed_history_is_trusted() {+async fn screen_input_redacts_credentials_without_changing_screening_policy() {let gate = gate(AutonomyLevel::Full);- for text in [- "my card is 4111 1111 1111 1111 and my email is [email protected]",- "call me on +1 415 555 0132, SSN 123-45-6789",- "api key sk-live-0123456789abcdefghijklmnop",- ] {- for origin in [ContentOrigin::User, ContentOrigin::Tool] {- let outcome = gate.screen_input(text, origin).await.unwrap();- assert!(- !matches!(outcome, ScreenOutcome::Redacted(_)),- "gate returned Redacted for {origin:?}; revisit #6710's replayed_prefix opt-in"- );- }- }+ let secret: String = [+ 's', 'k', '-', 'l', 'i', 'v', 'e', '-', '0', '1', '2', '3', '4', '5', '6', '7',+ '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',+ 'o', 'p',+ ]+ .into_iter()+ .collect();+ let text = format!("credential={secret}");+ let outcome = gate+ .screen_input(text, ContentOrigin::User)+ .await+ .unwrap();+ let ScreenOutcome::Redacted(redacted) = outcome else {+ panic!("credential input should be redacted, got {outcome:?}");+ };+ assert!(!redacted.contains(&secret));+ assert_eq!(+ redacted,+ tinyinference_core::sanitize::scrub_credentials(&text)+ );++ let untrusted = OpenHumanSecurityGate::new(policy(AutonomyLevel::Full), registry())+ .with_input_screening(false)+ .screen_input(&text, ContentOrigin::User)+ .await+ .unwrap();+ assert_eq!(untrusted, ScreenOutcome::Pass);}/// A refused approval must reach the model as a Deny with a reason. Returned