Skip to content

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

fix(security): validate trusted roots first; grant a relative action dir absolutely

M3gA-Mind49b03d9adb80
diff --git a/crates/openhuman-core/src/config/ops/agent.rs b/crates/openhuman-core/src/config/ops/agent.rs
index cf276383b8..141f0a0d4d 100644
--- a/crates/openhuman-core/src/config/ops/agent.rs
+++ b/crates/openhuman-core/src/config/ops/agent.rs
@@ -85,6 +85,18 @@ pub async fn apply_autonomy_settings(
) -> Result<Outcome<serde_json::Value>, String> {
use crate::security::AutonomyLevel;
+ // Validate before changing anything, so a rejected patch leaves `config` as it was.
+ if let Some(root) = update
+ .trusted_roots
+ .iter()
+ .flatten()
+ .find(|root| !std::path::Path::new(&super::expand_tilde(&root.path)).is_absolute())
+ {
+ return Err(format!(
+ "trusted root must be an absolute path (got {:?})",
+ root.path
+ ));
+ }
if let Some(enabled) = update.enabled {
config.autonomy.enabled = enabled;
}
@@ -110,15 +122,6 @@ pub async fn apply_autonomy_settings(
config.autonomy.forbidden_paths = forbidden_paths;
}
if let Some(trusted_roots) = update.trusted_roots {
- if let Some(root) = trusted_roots
- .iter()
- .find(|root| !std::path::Path::new(&super::expand_tilde(&root.path)).is_absolute())
- {
- return Err(format!(
- "trusted root must be an absolute path (got {:?})",
- root.path
- ));
- }
config.autonomy.trusted_roots = trusted_roots;
}
if let Some(allow_tool_install) = update.allow_tool_install {
diff --git a/crates/openhuman-core/src/config/ops_voice_and_autonomy_tests.rs b/crates/openhuman-core/src/config/ops_voice_and_autonomy_tests.rs
index 15582c4857..c2b17decd4 100644
--- a/crates/openhuman-core/src/config/ops_voice_and_autonomy_tests.rs
+++ b/crates/openhuman-core/src/config/ops_voice_and_autonomy_tests.rs
@@ -474,9 +474,12 @@ async fn apply_autonomy_settings_rejects_a_relative_or_empty_trusted_root() {
for root in ["", " ", ".", "rel/dir"] {
let tmp = tempdir().unwrap();
let mut cfg = tmp_config(&tmp);
+ let enabled_before = cfg.autonomy.enabled;
let err = apply_autonomy_settings(
&mut cfg,
AutonomySettingsPatch {
+ // A rejected patch must not half-apply its other fields.
+ enabled: Some(!enabled_before),
trusted_roots: Some(vec![crate::security::TrustedRoot {
path: root.into(),
access: crate::security::TrustedAccess::ReadWrite,
@@ -491,5 +494,6 @@ async fn apply_autonomy_settings_rejects_a_relative_or_empty_trusted_root() {
"expected validation error, got: {err}"
);
assert!(cfg.autonomy.trusted_roots.is_empty());
+ assert_eq!(cfg.autonomy.enabled, enabled_before, "patch half-applied");
}
}
diff --git a/crates/openhuman-core/src/security/policy/enforcement.rs b/crates/openhuman-core/src/security/policy/enforcement.rs
index 183905d966..27dcaaffc8 100644
--- a/crates/openhuman-core/src/security/policy/enforcement.rs
+++ b/crates/openhuman-core/src/security/policy/enforcement.rs
@@ -150,7 +150,23 @@ impl SecurityPolicy {
// 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 mut trusted_roots = autonomy_config.trusted_roots.clone();
+ // A relative or empty root grants nothing (`is_within_trusted_root`), so
+ // drop it here too: the turn prompt lists these roots as grants.
+ let mut trusted_roots: Vec<TrustedRoot> = autonomy_config
+ .trusted_roots
+ .iter()
+ .filter(|root| {
+ let absolute = Path::new(&crate::config::expand_tilde(&root.path)).is_absolute();
+ if !absolute {
+ log::warn!(
+ "[openhuman:policy] ignoring non-absolute trusted root {:?}",
+ root.path
+ );
+ }
+ absolute
+ })
+ .cloned()
+ .collect();
let projects_path = crate::config::default_projects_dir()
.to_string_lossy()
.to_string();
@@ -180,8 +196,13 @@ impl SecurityPolicy {
// `is_always_forbidden` are checked *before* that shortcut and still
// hold, but the `forbidden_paths` bypass is not something a working
// directory should buy, so skip the grant in that shape.
- let action_path = action_dir.to_string_lossy().to_string();
- let action_covers_workspace = workspace_dir.starts_with(action_dir);
+ // Path checks resolve tool paths against `action_dir` (absolute after
+ // canonicalising), so a relative action dir is granted as its absolute
+ // form; only an absolute trusted root matches anything.
+ let action_root =
+ std::path::absolute(action_dir).unwrap_or_else(|_| action_dir.to_path_buf());
+ let action_path = action_root.to_string_lossy().to_string();
+ let action_covers_workspace = workspace_dir.starts_with(&action_root);
if action_path.is_empty() || action_covers_workspace {
tracing::debug!(
action_dir = %action_dir.display(),
diff --git a/crates/openhuman-core/src/security/policy/policy_action_dir_tests.rs b/crates/openhuman-core/src/security/policy/policy_action_dir_tests.rs
index 1c8b2f2c47..1c58e32da0 100644
--- a/crates/openhuman-core/src/security/policy/policy_action_dir_tests.rs
+++ b/crates/openhuman-core/src/security/policy/policy_action_dir_tests.rs
@@ -125,3 +125,58 @@ async fn tool_result_artifacts_are_readable_by_absolute_path_under_workspace_onl
.await
.is_err());
}
+
+/// A relative action dir is still the agent's working root (tool paths are
+/// resolved against it), so it is granted as its absolute form; a relative
+/// trusted root itself grants nothing.
+#[test]
+fn from_config_grants_a_relative_action_dir_as_its_absolute_path() {
+ let tmp = tempfile::tempdir().expect("tempdir");
+ let workspace = tmp.path().join("workspace");
+ fs::create_dir_all(&workspace).unwrap();
+ let action = std::path::Path::new("relative-action-dir");
+
+ let policy = SecurityPolicy::from_config(
+ &crate::config::AutonomyConfig::default(),
+ &workspace,
+ action,
+ );
+ let absolute = std::path::absolute(action)
+ .unwrap()
+ .to_string_lossy()
+ .to_string();
+ assert!(
+ policy
+ .trusted_roots
+ .iter()
+ .any(|r| r.path == absolute && matches!(r.access, TrustedAccess::ReadWrite)),
+ "relative action dir not granted as {absolute}; got: {:?}",
+ policy.trusted_roots
+ );
+}
+
+/// Non-absolute configured roots are dropped from the policy, so nothing
+/// (the turn prompt included) presents them as grants.
+#[test]
+fn from_config_drops_non_absolute_trusted_roots() {
+ let tmp = tempfile::tempdir().expect("tempdir");
+ let cfg = crate::config::AutonomyConfig {
+ trusted_roots: ["", ".", "rel/dir"]
+ .into_iter()
+ .map(|path| TrustedRoot {
+ path: path.into(),
+ access: TrustedAccess::ReadWrite,
+ })
+ .collect(),
+ ..crate::config::AutonomyConfig::default()
+ };
+ let policy = SecurityPolicy::from_config(&cfg, tmp.path(), tmp.path());
+ assert!(
+ policy
+ .trusted_roots
+ .iter()
+ .all(|r| std::path::Path::new(&r.path).is_absolute()),
+ "non-absolute roots kept: {:?}",
+ policy.trusted_roots
+ );
+}