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(security): enforce approval gate for shell tool commands
Steven Enamakelfbdb485d3158
diff --git a/crates/openhuman-core/src/security/approval/gate_intercept.rs b/crates/openhuman-core/src/security/approval/gate_intercept.rsindex 80b4a068df..34476203c9 100644--- a/crates/openhuman-core/src/security/approval/gate_intercept.rs+++ b/crates/openhuman-core/src/security/approval/gate_intercept.rs@@ -21,6 +21,17 @@ impl ApprovalGate {// `AgentTurnOrigin` around `run_turn`. Unlabelled callers map to// `Unknown`, which is denied — the gate refuses to execute an// external_effect tool from an unlabelled call site.+ // SaaS has no per-user approval surface: never park, allow only what+ // the deployment's sandboxed tool groups open.+ if crate::core::runtime::is_saas() {+ let outcome = match crate::user_agents::tools::gate_verdict(tool_name) {+ Ok(()) => GateOutcome::Allow,+ Err(why) => GateOutcome::Deny {+ reason: format!("{POLICY_DENIED_MARKER} {why}"),+ },+ };+ return (outcome, None);+ }let origin = turn_origin::current().unwrap_or(AgentTurnOrigin::Unknown);if forced&& !matches!(diff --git a/crates/openhuman-core/src/security/policy/enforcement.rs b/crates/openhuman-core/src/security/policy/enforcement.rsindex 4f0a421004..5f70003c07 100644--- a/crates/openhuman-core/src/security/policy/enforcement.rs+++ b/crates/openhuman-core/src/security/policy/enforcement.rs@@ -131,11 +131,14 @@ impl SecurityPolicy {// channels-startup injection is skipped on cores with no listening// integrations (web-chat-only), and a freshly reloaded config wouldn't// carry an in-memory edit anyway. A user-granted entry is left as-is.+ // SaaS: the projects home and `/tmp/openhuman` are shared by every user+ // of the process, so neither is granted there.+ let saas = crate::core::runtime::is_saas();let mut trusted_roots = autonomy_config.trusted_roots.clone();let projects_path = crate::config::default_projects_dir().to_string_lossy().to_string();- if !trusted_roots.iter().any(|r| r.path == projects_path) {+ if !saas && !trusted_roots.iter().any(|r| r.path == projects_path) {trusted_roots.push(TrustedRoot {path: projects_path,access: TrustedAccess::ReadWrite,@@ -200,7 +203,7 @@ impl SecurityPolicy {// is ever trusted — never `/tmp` itself. Created here with restrictive// perms and refused if it exists as a symlink (TOCTOU hardening, since// `/tmp` is world-writable and the name is predictable).- match ensure_openhuman_scratch_dir() {+ match ensure_openhuman_scratch_dir().filter(|_| !saas) {Some(scratch) => {let scratch_str = scratch.to_string_lossy().to_string();if trusted_roots.iter().any(|r| r.path == scratch_str) {diff --git a/crates/openhuman-core/src/tools/impl/system/shell.rs b/crates/openhuman-core/src/tools/impl/system/shell.rsindex d27ff62155..9df9d78038 100644--- a/crates/openhuman-core/src/tools/impl/system/shell.rs+++ b/crates/openhuman-core/src/tools/impl/system/shell.rs@@ -362,6 +362,25 @@ impl ShellTool {);}+ // SaaS: every command runs in the user's container, whatever the+ // agent's sandbox mode says, and never on the host.+ if crate::core::runtime::is_saas() {+ let action_dir = self.effective_action_dir_for_context(context);+ return match crate::user_agents::tools::sandbox_policy(+ &action_dir,+ &self.security.workspace_dir,+ ) {+ Ok(policy) => {+ self.run_in_policy(policy, command, requested_timeout, &action_dir)+ .await+ }+ Err(why) => {+ tracing::warn!(reason = %why, "[shell] SaaS sandbox refused the command");+ (true, ToolResult::error(format!("Sandbox unavailable: {why}")))+ }+ };+ }+// When the agent's sandbox mode is `Sandboxed`, route execution// through the sandbox backend (Docker or OS-level jail) instead// of the normal runtime. Security checks above still apply.@@ -488,16 +507,27 @@ impl ShellTool {requested_timeout: Option<u64>,action_dir: &Path,) -> (bool, ToolResult) {- use crate::sandbox;-let config = crate::config::RuntimeConfig::default();- let policy = sandbox::resolve_sandbox_policy(+ let policy = crate::sandbox::resolve_sandbox_policy(crate::agent::harness::definition::SandboxMode::Sandboxed,action_dir,&self.security.workspace_dir,&config,false,);+ self.run_in_policy(policy, command, requested_timeout, action_dir)+ .await+ }++ /// Execute a command under a resolved sandbox `policy`.+ async fn run_in_policy(+ &self,+ policy: crate::sandbox::SandboxPolicy,+ command: &str,+ requested_timeout: Option<u64>,+ action_dir: &Path,+ ) -> (bool, ToolResult) {+ use crate::sandbox;tracing::debug!(backend = ?policy.backend,@@ -506,8 +536,12 @@ impl ShellTool {);let mut extra_env = std::collections::HashMap::new();- if let Some(path) = self.runtime_path_for_command(command).await {- extra_env.insert("PATH".into(), path.into());+ // A managed runtime's PATH names host directories, which a SaaS+ // container cannot see.+ if !crate::core::runtime::is_saas() {+ if let Some(path) = self.runtime_path_for_command(command).await {+ extra_env.insert("PATH".into(), path.into());+ }}// Apply the same Git config hardening to local and sandboxed shells.