Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(security): enforce approval gate for shell tool commands

Steven Enamakela1db4bcafa09
diff --git a/crates/openhuman-core/src/security/approval/gate_forced_tests.rs b/crates/openhuman-core/src/security/approval/gate_forced_tests.rs
index 4dc4ce70a2..ace1892917 100644
--- a/crates/openhuman-core/src/security/approval/gate_forced_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_forced_tests.rs
@@ -136,3 +136,29 @@ async fn forced_approval_still_denies_automation_and_channel_origins() {
}
assert!(gate.list_pending().unwrap().is_empty());
}
+
+#[test]
+fn saas_outcome_is_absent_outside_saas() {
+ assert!(saas_outcome_with(false, "shell").is_none());
+}
+
+#[test]
+fn saas_outcome_never_parks_and_denies_without_an_allowlisted_group() {
+ // No agent host is installed here, so no tool group is allowlisted.
+ match saas_outcome_with(true, "shell") {
+ Some(GateOutcome::Deny { reason }) => {
+ assert!(reason.starts_with(POLICY_DENIED_MARKER), "{reason}");
+ assert!(reason.contains("no approval surface"), "{reason}");
+ }
+ other => panic!("expected an immediate deny, got {other:?}"),
+ }
+}
+
+#[test]
+fn saas_outcome_maps_an_allowlisted_verdict_to_allow() {
+ use crate::user_agents::tools::{gate_verdict_with, SaasToolGroup};
+ let verdict = gate_verdict_with("shell", &[SaasToolGroup::HostShell]);
+ assert!(matches!(saas_outcome(verdict), GateOutcome::Allow));
+ let verdict = gate_verdict_with("shell", &[SaasToolGroup::HostFiles]);
+ assert!(matches!(saas_outcome(verdict), GateOutcome::Deny { .. }));
+}
diff --git a/crates/openhuman-core/src/tools/impl/system/shell.rs b/crates/openhuman-core/src/tools/impl/system/shell.rs
index f3e42c92ce..a93878aa0a 100644
--- a/crates/openhuman-core/src/tools/impl/system/shell.rs
+++ b/crates/openhuman-core/src/tools/impl/system/shell.rs
@@ -364,12 +364,17 @@ 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,
- ) {
+ let saas_action_dir = self.effective_action_dir_for_context(context);
+ if let Some(resolved) =
+ saas_sandbox_with(crate::core::runtime::is_saas(), || {
+ crate::user_agents::tools::sandbox_policy(
+ &saas_action_dir,
+ &self.security.workspace_dir,
+ )
+ })
+ {
+ let action_dir = saas_action_dir;
+ return match resolved {
Ok(policy) => {
self.run_in_policy(policy, command, requested_timeout, &action_dir)
.await
@@ -377,10 +382,7 @@ impl ShellTool {
Err(why) => {
tracing::warn!(reason = %why, "[shell] SaaS sandbox refused the command");
// Nothing ran: report it as not allowed.
- (
- false,
- ToolResult::error(format!("Sandbox unavailable: {why}")),
- )
+ saas_sandbox_refusal(&why)
}
};
}
@@ -542,7 +544,7 @@ impl ShellTool {
let mut extra_env = std::collections::HashMap::new();
// A managed runtime's PATH names host directories, which a SaaS
// container cannot see.
- if !crate::core::runtime::is_saas() {
+ if passes_runtime_path_with(crate::core::runtime::is_saas()) {
if let Some(path) = self.runtime_path_for_command(command).await {
extra_env.insert("PATH".into(), path.into());
}
@@ -736,6 +738,30 @@ fn versioned_executable(executable: &str, prefix: &str) -> bool {
.is_some_and(|suffix| !suffix.is_empty() && suffix.chars().all(|c| c.is_ascii_digit()))
}
+/// In SaaS, resolves the container policy every command must run in; `None`
+/// outside SaaS, where the agent's sandbox mode decides.
+pub(crate) fn saas_sandbox_with(
+ saas: bool,
+ resolve: impl FnOnce() -> Result<crate::sandbox::SandboxPolicy, String>,
+) -> Option<Result<crate::sandbox::SandboxPolicy, String>> {
+ saas.then(resolve)
+}
+
+/// The result for a SaaS command whose sandbox could not be set up: nothing
+/// ran, so it is reported as not allowed, and never falls back to the host.
+pub(crate) fn saas_sandbox_refusal(why: &str) -> (bool, ToolResult) {
+ (
+ false,
+ ToolResult::error(format!("Sandbox unavailable: {why}")),
+ )
+}
+
+/// Whether the managed runtime's `PATH` is passed into a sandboxed command.
+/// Not in SaaS: it names host directories a container cannot see.
+pub(crate) fn passes_runtime_path_with(saas: bool) -> bool {
+ !saas
+}
+
#[cfg(test)]
#[path = "shell_tests.rs"]
mod tests;