Skip to content

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

fix(security): honour only absolute trusted roots

M3gA-Mindf7326678bd14
diff --git a/crates/openhuman-core/src/config/ops/agent.rs b/crates/openhuman-core/src/config/ops/agent.rs
index 4197b557af..cf276383b8 100644
--- a/crates/openhuman-core/src/config/ops/agent.rs
+++ b/crates/openhuman-core/src/config/ops/agent.rs
@@ -110,6 +110,15 @@ 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 0c04bdc708..15582c4857 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
@@ -467,3 +467,29 @@ async fn apply_agent_settings_updates_timeout_and_persists_snapshot() {
// With no env override, the live runtime now reflects the saved value.
assert_eq!(crate::tools::timeout::tool_execution_timeout_secs(), 300);
}
+
+#[tokio::test]
+async fn apply_autonomy_settings_rejects_a_relative_or_empty_trusted_root() {
+ let _g = ENV_LOCK.lock().await;
+ for root in ["", " ", ".", "rel/dir"] {
+ let tmp = tempdir().unwrap();
+ let mut cfg = tmp_config(&tmp);
+ let err = apply_autonomy_settings(
+ &mut cfg,
+ AutonomySettingsPatch {
+ trusted_roots: Some(vec![crate::security::TrustedRoot {
+ path: root.into(),
+ access: crate::security::TrustedAccess::ReadWrite,
+ }]),
+ ..Default::default()
+ },
+ )
+ .await
+ .expect_err("a non-absolute trusted root must be refused");
+ assert!(
+ err.contains("absolute"),
+ "expected validation error, got: {err}"
+ );
+ assert!(cfg.autonomy.trusted_roots.is_empty());
+ }
+}
diff --git a/crates/openhuman-core/src/security/policy/path_checks.rs b/crates/openhuman-core/src/security/policy/path_checks.rs
index 6b48350b97..b230516ff7 100644
--- a/crates/openhuman-core/src/security/policy/path_checks.rs
+++ b/crates/openhuman-core/src/security/policy/path_checks.rs
@@ -568,6 +568,12 @@ impl SecurityPolicy {
return false;
}
let root_path = PathBuf::from(self.expand_tilde(&root.path));
+ // `Path::starts_with("")` is true for every path, and a relative
+ // root resolves against the process CWD: only an absolute root
+ // grants anything.
+ if !root_path.is_absolute() {
+ return false;
+ }
let canonical_root = root_path
.canonicalize()
.unwrap_or_else(|_| root_path.clone());
diff --git a/crates/openhuman-core/src/security/policy/policy_trusted_roots_tests.rs b/crates/openhuman-core/src/security/policy/policy_trusted_roots_tests.rs
index c0df8164bf..7449801c56 100644
--- a/crates/openhuman-core/src/security/policy/policy_trusted_roots_tests.rs
+++ b/crates/openhuman-core/src/security/policy/policy_trusted_roots_tests.rs
@@ -699,3 +699,20 @@ async fn validate_parent_path_uses_same_cache_as_validate_path() {
"validate_path must reuse the cache hydrated by validate_parent_path"
);
}
+
+#[test]
+fn an_empty_or_relative_trusted_root_grants_nothing() {
+ for root in ["", ".", "rel/dir"] {
+ let policy = trusted_policy(
+ StdPathBuf::from("/ws"),
+ vec![TrustedRoot {
+ path: root.into(),
+ access: TrustedAccess::ReadWrite,
+ }],
+ );
+ assert!(
+ !policy.is_within_trusted_root(StdPath::new("/usr/local/x"), true),
+ "trusted root {root:?} must not cover an unrelated absolute path"
+ );
+ }
+}