From ae8076f2fe5e1ce4746627dca6b77462acdc186a Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Thu, 5 Nov 2026 21:26:40 +0530 Subject: [PATCH 1/8] test(config): refuse an autonomy policy TinySecurity cannot represent Red on main: config.update_autonomy_settings saves an enabled policy with a relative forbidden path or a command with arguments (TS-E2E-015). --- .../config/ops_voice_and_autonomy_tests.rs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) 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 c2b17decd4c..995a03c7cd3 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 @@ -266,6 +266,57 @@ async fn apply_autonomy_settings_rejects_zero() { ); } +/// TS-E2E-015: an enabled policy TinySecurity cannot represent is refused at +/// save time, the file is not written and the settings stay as they were. +#[cfg(feature = "security-module")] +#[tokio::test] +async fn apply_autonomy_settings_rejects_a_policy_tinysecurity_cannot_represent() { + let _g = ENV_LOCK.lock().await; + let tmp = tempdir().unwrap(); + let mut cfg = tmp_config(&tmp); + let prior = cfg.autonomy.clone(); + for (patch, expected) in [ + ( + AutonomySettingsPatch { + enabled: Some(true), + forbidden_paths: Some(vec!["relative/forbidden".into()]), + ..Default::default() + }, + "forbidden paths must be absolute", + ), + ( + AutonomySettingsPatch { + enabled: Some(true), + allowed_commands: Some(vec!["git status".into()]), + ..Default::default() + }, + "argument-free command names", + ), + ] { + let err = apply_autonomy_settings(&mut cfg, patch).await.unwrap_err(); + assert!(err.contains(expected), "expected {expected:?}, got: {err}"); + assert_eq!( + toml::to_string(&cfg.autonomy).unwrap(), + toml::to_string(&prior).unwrap(), + "a rejected patch leaves the settings as they were" + ); + assert!(!cfg.config_path.exists(), "a rejected patch is not saved"); + } + + apply_autonomy_settings( + &mut cfg, + AutonomySettingsPatch { + enabled: Some(true), + forbidden_paths: Some(vec![tmp.path().join("private").display().to_string()]), + allowed_commands: Some(vec!["git".into()]), + ..Default::default() + }, + ) + .await + .expect("a representable enabled policy is saved"); + assert!(cfg.autonomy.enabled); +} + #[tokio::test] async fn apply_autonomy_settings_accepts_unlimited_sentinel() { let _g = ENV_LOCK.lock().await; From 89f21b11feafac3538a6a7287e3d65290457de00 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Thu, 5 Nov 2026 21:26:40 +0530 Subject: [PATCH 2/8] fix(config): validate autonomy settings against TinySecurity's rules before saving apply_autonomy_settings saved allowed_commands and forbidden_paths without the check ensure_loaded applies on every TinySecurity call, so one relative path or "git status" entry under enabled autonomy was accepted and then refused at load. It now runs the same modules::security policy validation before saving, restores the previous autonomy settings and returns the reason. Fixes TS-E2E-015. --- crates/openhuman-core/src/config/ops/agent.rs | 12 ++++++++++++ crates/openhuman-core/src/modules/security/mod.rs | 1 + 2 files changed, 13 insertions(+) diff --git a/crates/openhuman-core/src/config/ops/agent.rs b/crates/openhuman-core/src/config/ops/agent.rs index c96855a2448..e3bc09b8607 100644 --- a/crates/openhuman-core/src/config/ops/agent.rs +++ b/crates/openhuman-core/src/config/ops/agent.rs @@ -71,6 +71,8 @@ pub async fn apply_autonomy_settings( ) -> Result, String> { use crate::security::AutonomyLevel; + #[cfg(feature = "security-module")] + let before = config.autonomy.clone(); // Validate before changing anything, so a rejected patch leaves `config` as it was. if let Some(root) = update .trusted_roots @@ -127,6 +129,16 @@ pub async fn apply_autonomy_settings( if let Some(auto_approve_all) = update.auto_approve_all { config.autonomy.auto_approve_all = auto_approve_all; } + // TinySecurity refuses an enabled policy it cannot represent (relative + // forbidden paths, commands with arguments). Saved, such a policy would make + // every TinySecurity call fail until the file was edited by hand, so refuse + // it here and leave the settings as they were. + #[cfg(feature = "security-module")] + if let Err(error) = crate::modules::security::validate_policy(config) { + log::debug!("[config][autonomy] patch rejected: {error}"); + config.autonomy = before; + return Err(format!("autonomy settings not saved: {error}")); + } config.save().await.map_err(super::config_save_error)?; diff --git a/crates/openhuman-core/src/modules/security/mod.rs b/crates/openhuman-core/src/modules/security/mod.rs index f61eb510fac..92151ef9089 100644 --- a/crates/openhuman-core/src/modules/security/mod.rs +++ b/crates/openhuman-core/src/modules/security/mod.rs @@ -28,6 +28,7 @@ mod tests; pub(crate) use client::SecurityProxy; pub use client::{Client, SecurityError}; pub use policy::policy_config; +pub(crate) use policy::validate as validate_policy; pub(super) use policy::{module_config, module_config_for_host, module_config_for_secret_scope}; pub(crate) use secret_cipher::Output as SecretCipherOutput; From 7e7e8029179dc998d991a582bc939282a3419e5a Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 11:46:07 +0530 Subject: [PATCH 3/8] fix(security): leave drive-less Unix roots out of the Windows policy The shipped default forbidden paths include /etc, /usr and the other Unix roots. On Windows these have no drive, so Path::is_absolute is false and validate (and the module) refused an enabled policy built from the defaults. They name no folder there, so the translation leaves them out on Windows; relative entries are still refused. --- .../src/modules/security/policy.rs | 25 ++++++++++---- .../src/modules/security/policy_tests.rs | 33 +++++++++++++++++++ 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/crates/openhuman-core/src/modules/security/policy.rs b/crates/openhuman-core/src/modules/security/policy.rs index 54ce59ac1dc..2f01efd9d40 100644 --- a/crates/openhuman-core/src/modules/security/policy.rs +++ b/crates/openhuman-core/src/modules/security/policy.rs @@ -26,18 +26,31 @@ pub fn policy_config(config: &Config) -> tinysecurity_bus::PolicyConfig { Vec::new() }, forbidden_paths: if config.autonomy.enabled { - config - .autonomy - .forbidden_paths - .iter() - .map(|path| crate::config::expand_tilde(path)) - .collect() + forbidden_paths(&config.autonomy.forbidden_paths, cfg!(windows)) } else { Vec::new() }, } } +/// The forbidden paths as the module receives them, `~` expanded. On Windows +/// a path rooted without a drive (`/etc`, `\usr`, the Unix roots in the +/// shipped defaults) is not absolute and names no system folder, and the +/// module would refuse the whole policy for it; it is left out there. +/// Relative entries are kept, so `validate` still refuses them. +fn forbidden_paths(paths: &[String], windows: bool) -> Vec { + paths + .iter() + .filter(|path| !(windows && is_drive_less_root(path))) + .map(|path| crate::config::expand_tilde(path)) + .collect() +} + +/// `/x` or `\x`, but not a UNC path (`\\server`, `//server`). +fn is_drive_less_root(path: &str) -> bool { + path.starts_with(['/', '\\']) && !path.starts_with("\\\\") && !path.starts_with("//") +} + /// Reject enabled host policy that the published module contract cannot /// represent. Disabled policy settings are inert and serialize empty above. pub fn validate(config: &Config) -> Result<(), &'static str> { diff --git a/crates/openhuman-core/src/modules/security/policy_tests.rs b/crates/openhuman-core/src/modules/security/policy_tests.rs index 8db711e4913..1fe8a646d57 100644 --- a/crates/openhuman-core/src/modules/security/policy_tests.rs +++ b/crates/openhuman-core/src/modules/security/policy_tests.rs @@ -25,6 +25,39 @@ fn enabled_policy_expands_home_relative_forbidden_paths() { .all(|path| std::path::Path::new(path).is_absolute())); } +/// TS-E2E-015 / #8575: the shipped defaults include Unix roots (`/etc`, …), +/// which have no drive on Windows. Enabling autonomy with the defaults must +/// still give the module a policy it accepts there. +#[test] +fn windows_policy_leaves_out_drive_less_unix_roots() { + let defaults = Config::default().autonomy.forbidden_paths; + assert!(defaults.iter().any(|path| path == "/etc"), "{defaults:?}"); + + let windows = forbidden_paths(&defaults, true); + assert!( + windows.iter().all(|path| !is_drive_less_root(path)), + "{windows:?}" + ); + assert!(windows.contains(&crate::config::expand_tilde("~/.ssh"))); + assert_eq!(forbidden_paths(&defaults, false).len(), defaults.len()); + + let kept = ["C:\\Secrets", "\\\\server\\share", "//server/share", "relative"]; + let kept: Vec = kept.iter().map(|path| path.to_string()).collect(); + assert_eq!(forbidden_paths(&kept, true), kept); +} + +/// The untouched defaults, enabled, validate on this OS. +#[test] +fn enabled_default_policy_validates() { + let root = tempfile::tempdir().unwrap(); + let mut config = Config::default(); + config.action_dir = root.path().join("action"); + config.workspace_dir = root.path().join("workspace"); + config.autonomy.enabled = true; + + assert_eq!(validate(&config), Ok(())); +} + #[test] fn enabled_policy_still_refuses_relative_forbidden_paths() { let mut config = Config::default(); From 29d8fec325239831bb65509aad2faaea0ba8143f Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 11:49:25 +0530 Subject: [PATCH 4/8] docs(security): the module already ignores drive-less roots on Windows; validate is what refused them --- crates/openhuman-core/src/modules/security/policy.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/openhuman-core/src/modules/security/policy.rs b/crates/openhuman-core/src/modules/security/policy.rs index 2f01efd9d40..9f1f5f7866e 100644 --- a/crates/openhuman-core/src/modules/security/policy.rs +++ b/crates/openhuman-core/src/modules/security/policy.rs @@ -35,9 +35,10 @@ pub fn policy_config(config: &Config) -> tinysecurity_bus::PolicyConfig { /// The forbidden paths as the module receives them, `~` expanded. On Windows /// a path rooted without a drive (`/etc`, `\usr`, the Unix roots in the -/// shipped defaults) is not absolute and names no system folder, and the -/// module would refuse the whole policy for it; it is left out there. -/// Relative entries are kept, so `validate` still refuses them. +/// shipped defaults) is not absolute and names no system folder; the module +/// already ignores such entries there, and `validate` would otherwise refuse +/// the whole policy for them, so they are left out. Relative entries are +/// kept, so `validate` still refuses them. fn forbidden_paths(paths: &[String], windows: bool) -> Vec { paths .iter() From 3e85254e5146627beca65df68e86bf5a41f85f56 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 12:25:28 +0530 Subject: [PATCH 5/8] test(security): compare the Windows policy with the defaults' home entries, not by prefix --- .../src/modules/security/policy_tests.rs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/crates/openhuman-core/src/modules/security/policy_tests.rs b/crates/openhuman-core/src/modules/security/policy_tests.rs index 1fe8a646d57..9a87707890a 100644 --- a/crates/openhuman-core/src/modules/security/policy_tests.rs +++ b/crates/openhuman-core/src/modules/security/policy_tests.rs @@ -33,15 +33,23 @@ fn windows_policy_leaves_out_drive_less_unix_roots() { let defaults = Config::default().autonomy.forbidden_paths; assert!(defaults.iter().any(|path| path == "/etc"), "{defaults:?}"); - let windows = forbidden_paths(&defaults, true); - assert!( - windows.iter().all(|path| !is_drive_less_root(path)), - "{windows:?}" - ); - assert!(windows.contains(&crate::config::expand_tilde("~/.ssh"))); + // Every default is a Unix root or a `~` path; on Windows only the `~` + // paths remain (checked on the input: `~` expands to `/home/...` here). + let home: Vec = defaults + .iter() + .filter(|path| path.starts_with('~')) + .map(|path| crate::config::expand_tilde(path)) + .collect(); + assert!(home.contains(&crate::config::expand_tilde("~/.ssh"))); + assert_eq!(forbidden_paths(&defaults, true), home); assert_eq!(forbidden_paths(&defaults, false).len(), defaults.len()); - let kept = ["C:\\Secrets", "\\\\server\\share", "//server/share", "relative"]; + let kept = [ + "C:\\Secrets", + "\\\\server\\share", + "//server/share", + "relative", + ]; let kept: Vec = kept.iter().map(|path| path.to_string()).collect(); assert_eq!(forbidden_paths(&kept, true), kept); } From 6edc0b8e73ab012a51a019ee8a750aeb6e53855a Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 13:53:38 +0530 Subject: [PATCH 6/8] test(config): a bad autonomy level or zero budget leaves the settings unchanged --- .../config/ops_voice_and_autonomy_tests.rs | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) 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 995a03c7cd3..a6e5cfc52eb 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 @@ -266,6 +266,46 @@ async fn apply_autonomy_settings_rejects_zero() { ); } +/// #8575: a bad level or a zero action budget is refused before any field of +/// the patch is applied, so a caller that keeps the `Config` can't save half +/// of a rejected patch. +#[tokio::test] +async fn apply_autonomy_settings_rejects_level_or_budget_before_changing_anything() { + let _g = ENV_LOCK.lock().await; + let tmp = tempdir().unwrap(); + let mut cfg = tmp_config(&tmp); + let prior = toml::to_string(&cfg.autonomy).unwrap(); + for (patch, expected) in [ + ( + AutonomySettingsPatch { + enabled: Some(true), + allowed_commands: Some(vec!["git".into()]), + max_actions_per_hour: Some(0), + ..Default::default() + }, + "max_actions_per_hour must be at least 1", + ), + ( + AutonomySettingsPatch { + enabled: Some(true), + allowed_commands: Some(vec!["git".into()]), + level: Some("sometimes".into()), + ..Default::default() + }, + "invalid autonomy level", + ), + ] { + let err = apply_autonomy_settings(&mut cfg, patch).await.unwrap_err(); + assert!(err.contains(expected), "expected {expected:?}, got: {err}"); + assert_eq!( + toml::to_string(&cfg.autonomy).unwrap(), + prior, + "a rejected patch leaves the settings as they were" + ); + assert!(!cfg.config_path.exists(), "a rejected patch is not saved"); + } +} + /// TS-E2E-015: an enabled policy TinySecurity cannot represent is refused at /// save time, the file is not written and the settings stay as they were. #[cfg(feature = "security-module")] From c74a64a9db3eaaf92765f6a491966af906cb9ba5 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 13:53:38 +0530 Subject: [PATCH 7/8] fix(config): check the autonomy level and action budget before applying the patch --- crates/openhuman-core/src/config/ops/agent.rs | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/crates/openhuman-core/src/config/ops/agent.rs b/crates/openhuman-core/src/config/ops/agent.rs index e3bc09b8607..05a59fd87f7 100644 --- a/crates/openhuman-core/src/config/ops/agent.rs +++ b/crates/openhuman-core/src/config/ops/agent.rs @@ -85,11 +85,9 @@ pub async fn apply_autonomy_settings( root.path )); } - if let Some(enabled) = update.enabled { - config.autonomy.enabled = enabled; - } - if let Some(level) = update.level { - config.autonomy.level = match level.trim().to_ascii_lowercase().as_str() { + let level = match update.level.map(|level| level.trim().to_ascii_lowercase()) { + None => None, + Some(level) => Some(match level.as_str() { "readonly" | "read_only" | "read-only" => AutonomyLevel::ReadOnly, "supervised" => AutonomyLevel::Supervised, "full" => AutonomyLevel::Full, @@ -98,7 +96,16 @@ pub async fn apply_autonomy_settings( "invalid autonomy level '{other}' (expected readonly | supervised | full)" )); } - }; + }), + }; + if update.max_actions_per_hour == Some(0) { + return Err("max_actions_per_hour must be at least 1 (got 0)".to_string()); + } + if let Some(enabled) = update.enabled { + config.autonomy.enabled = enabled; + } + if let Some(level) = level { + config.autonomy.level = level; } if let Some(workspace_only) = update.workspace_only { config.autonomy.workspace_only = workspace_only; @@ -116,11 +123,6 @@ pub async fn apply_autonomy_settings( config.autonomy.allow_tool_install = allow_tool_install; } if let Some(max_actions_per_hour) = update.max_actions_per_hour { - if max_actions_per_hour == 0 { - return Err(format!( - "max_actions_per_hour must be at least 1 (got {max_actions_per_hour})" - )); - } config.autonomy.max_actions_per_hour = max_actions_per_hour; } if let Some(auto_approve) = update.auto_approve { @@ -129,10 +131,11 @@ pub async fn apply_autonomy_settings( if let Some(auto_approve_all) = update.auto_approve_all { config.autonomy.auto_approve_all = auto_approve_all; } - // TinySecurity refuses an enabled policy it cannot represent (relative - // forbidden paths, commands with arguments). Saved, such a policy would make - // every TinySecurity call fail until the file was edited by hand, so refuse - // it here and leave the settings as they were. + // The host's TinySecurity client refuses an enabled policy the module + // contract cannot represent (relative forbidden paths, commands with + // arguments): `validate` runs before every call. Saved, such a policy would + // make every TinySecurity check fail closed until the file was edited by + // hand, so refuse it here and leave the settings as they were. #[cfg(feature = "security-module")] if let Err(error) = crate::modules::security::validate_policy(config) { log::debug!("[config][autonomy] patch rejected: {error}"); From 54f6baf21066ba17a200ffcf97e1c23e476fce69 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 13:53:38 +0530 Subject: [PATCH 8/8] test(security): use a path that is absolute on every OS in the translation test --- crates/openhuman-core/src/modules/security/policy_tests.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/openhuman-core/src/modules/security/policy_tests.rs b/crates/openhuman-core/src/modules/security/policy_tests.rs index 9a87707890a..de32d186abc 100644 --- a/crates/openhuman-core/src/modules/security/policy_tests.rs +++ b/crates/openhuman-core/src/modules/security/policy_tests.rs @@ -81,10 +81,13 @@ fn enabled_policy_still_refuses_relative_forbidden_paths() { #[test] fn policy_translation_copies_effective_host_settings() { + // Absolute on every OS: a drive-less `/private` is left out on Windows. + let root = tempfile::tempdir().unwrap(); + let private = root.path().join("private").display().to_string(); let mut config = Config::default(); config.autonomy.enabled = true; config.autonomy.allowed_commands = vec!["pwd".into()]; - config.autonomy.forbidden_paths = vec!["/private".into()]; + config.autonomy.forbidden_paths = vec![private.clone()]; let translated = policy_config(&config); assert!(translated.enabled); @@ -97,7 +100,7 @@ fn policy_translation_copies_effective_host_settings() { config.workspace_dir.display().to_string() ); assert_eq!(translated.allowed_commands, ["pwd"]); - assert_eq!(translated.forbidden_paths, ["/private"]); + assert_eq!(translated.forbidden_paths, [private]); } #[test]