From e601efb8516cecfe07c78065a1be7b6c257cb9bc Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Thu, 5 Nov 2026 21:25:41 +0530 Subject: [PATCH 1/7] test(config): agent folders refuse credential stores, symlinks to them and the data folder Red on main: a files_dir that is a symlink into ~/.ssh is accepted (TS-E2E-016), and action_dir accepts ~/.ssh, /etc, a symlink into ~/.ssh and a folder inside the workspace (TS-E2E-021). --- .../src/config/ops_agent_paths_tests.rs | 58 +++++++++++++++++++ .../src/config/ops_files_dir_tests.rs | 16 +++++ 2 files changed, 74 insertions(+) diff --git a/crates/openhuman-core/src/config/ops_agent_paths_tests.rs b/crates/openhuman-core/src/config/ops_agent_paths_tests.rs index 76c7a488a55..cd95dec6209 100644 --- a/crates/openhuman-core/src/config/ops_agent_paths_tests.rs +++ b/crates/openhuman-core/src/config/ops_agent_paths_tests.rs @@ -325,6 +325,64 @@ async fn apply_agent_paths_env_set_reports_source_env() { } } +/// The action_dir edit, expected to be refused without storing an override. +async fn action_dir_rejected(cfg: &mut Config, value: &std::path::Path) -> String { + let err = apply_agent_paths_settings( + cfg, + AgentPathsPatch { + action_dir: Some(value.to_string_lossy().to_string()), + files_dir: None, + }, + ) + .await + .expect_err("action_dir must be rejected"); + assert!(cfg.action_dir_override.is_none(), "a rejected value is not stored"); + err +} + +/// TS-E2E-021: the agent's working folder becomes its read-write root, so a +/// credential store, an OS directory or a symlink to one must be refused. +#[tokio::test] +async fn apply_agent_paths_rejects_a_protected_action_dir() { + let _g = ENV_LOCK.lock().await; + unsafe { + std::env::remove_var("OPENHUMAN_ACTION_DIR"); + } + let tmp = tempdir().unwrap(); + let mut cfg = tmp_config(&tmp); + let ssh = tmp.path().join(".ssh"); + std::fs::create_dir_all(&ssh).unwrap(); + + let err = action_dir_rejected(&mut cfg, &ssh).await; + assert!(err.contains("protected"), "{err}"); + #[cfg(unix)] + { + let err = action_dir_rejected(&mut cfg, std::path::Path::new("/etc")).await; + assert!(err.contains("protected"), "{err}"); + let link = tmp.path().join("projects-link"); + std::os::unix::fs::symlink(&ssh, &link).unwrap(); + let err = action_dir_rejected(&mut cfg, &link).await; + assert!(err.contains("protected"), "{err}"); + } +} + +/// TS-E2E-021: a folder inside the OpenHuman data folder holds internal state +/// and must not become the agent's working folder. +#[tokio::test] +async fn apply_agent_paths_rejects_an_action_dir_inside_the_data_folder() { + let _g = ENV_LOCK.lock().await; + unsafe { + std::env::remove_var("OPENHUMAN_ACTION_DIR"); + } + let tmp = tempdir().unwrap(); + let mut cfg = tmp_config(&tmp); + let inside = cfg.workspace_dir.join("vault"); + + let err = action_dir_rejected(&mut cfg, &inside).await; + assert!(err.contains("OpenHuman data folder"), "{err}"); + assert!(!inside.exists(), "nothing is created for a rejected value"); +} + // --- #3353 regression tests ------------------------------------------------- #[test] diff --git a/crates/openhuman-core/src/config/ops_files_dir_tests.rs b/crates/openhuman-core/src/config/ops_files_dir_tests.rs index f41414ec551..b761ddc534f 100644 --- a/crates/openhuman-core/src/config/ops_files_dir_tests.rs +++ b/crates/openhuman-core/src/config/ops_files_dir_tests.rs @@ -181,6 +181,22 @@ async fn a_symlinked_route_into_the_data_folder_is_rejected() { assert!(err.contains("OpenHuman data folder"), "{err}"); } +/// TS-E2E-016: a symlink into a credential store is the credential store; the +/// floor is asked about the resolved path, not only the spelling. +#[cfg(unix)] +#[tokio::test] +async fn a_symlink_into_a_credential_folder_is_rejected() { + let tmp = tempdir().unwrap(); + let mut cfg = tmp_config(&tmp); + let ssh = tmp.path().join(".ssh"); + std::fs::create_dir_all(&ssh).unwrap(); + let link = tmp.path().join("Documents-link"); + std::os::unix::fs::symlink(&ssh, &link).unwrap(); + + let err = rejected(&mut cfg, &link.to_string_lossy()).await; + assert!(err.contains("protected"), "{err}"); +} + /// Changing the folder affects new files only: a file made in the previous /// folder keeps resolving, because that folder is recorded as trusted. #[tokio::test] From 08d404fa4fdbf4ee4c4deadb6cb765daea818e9d Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Thu, 5 Nov 2026 21:25:41 +0530 Subject: [PATCH 2/7] fix(config): check agent folders against the floor by their resolved path files_dir asked TinySecurity's lexical floor about the path as typed, so a symlink into ~/.ssh passed, and action_dir, which becomes the agent's read-write root, had no floor or data-folder check at all. Both now go through refuse_protected_folder, which asks the floor about the given and the resolved path and refuses anything inside the workspace or the OpenHuman data folder. action_dir keeps its equal-to-workspace message. Fixes TS-E2E-016 and TS-E2E-021. --- .../src/config/ops/agent_paths.rs | 51 ++++++++++++++----- 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/crates/openhuman-core/src/config/ops/agent_paths.rs b/crates/openhuman-core/src/config/ops/agent_paths.rs index 82acbac871c..8bb5f1ccb2f 100644 --- a/crates/openhuman-core/src/config/ops/agent_paths.rs +++ b/crates/openhuman-core/src/config/ops/agent_paths.rs @@ -200,10 +200,9 @@ fn agent_paths_payload(config: &Config) -> serde_json::Value { } /// Validate a user-chosen files folder (#5505) and create it. Fail-closed: -/// the path must be absolute, not an existing file, not a protected location -/// (credential stores, OS directories), and not inside the OpenHuman data -/// directory — the point of the folder is that the user can see it, and the -/// data dir holds internal state. +/// the path must be absolute, not an existing file, and pass +/// [`refuse_protected_folder`] — the point of the folder is that the user can +/// see it, and the data dir holds internal state. async fn validate_files_dir(raw: &str, config: &Config) -> Result { let expanded = expand_tilde(raw); let candidate = PathBuf::from(&expanded); @@ -217,24 +216,44 @@ async fn validate_files_dir(raw: &str, config: &Config) -> Result Result<(), String> { + let resolved = canonical_prefix(candidate); + if crate::security::SecurityPolicy::is_always_forbidden_async(candidate).await + || crate::security::SecurityPolicy::is_always_forbidden_async(&resolved).await + { + log::debug!("[config][agent_paths] {kind} refused: protected location"); return Err(format!( - "files_dir cannot be a protected system or credential folder: {expanded}" + "{kind} cannot be a protected system or credential folder: {expanded}" )); } let mut internal = vec![config.workspace_dir.clone()]; if let Ok(root) = crate::config::default_root_openhuman_dir() { internal.push(root); } - if internal.iter().any(|dir| path_within(&candidate, dir)) { + if internal.iter().any(|dir| path_within(candidate, dir)) { + log::debug!("[config][agent_paths] {kind} refused: inside the data folder"); return Err(format!( - "files_dir must not be inside the OpenHuman data folder: {expanded}" + "{kind} must not be inside the OpenHuman data folder: {expanded}" )); } - tokio::fs::create_dir_all(&candidate) - .await - .map_err(|e| format!("failed to create files_dir {expanded}: {e}"))?; - Ok(candidate) + Ok(()) } /// `path` equals or sits under `dir`, comparing canonical forms so a @@ -265,9 +284,11 @@ pub(crate) fn canonical_prefix(path: &Path) -> PathBuf { /// Applies an edit to the agent's `action_dir` sandbox root. /// /// Validation (fail-closed): the path is trimmed and `~`-expanded; it must be -/// **absolute**; it must not be an existing *file*; and it must not equal +/// **absolute**; it must not be an existing *file*; it must not equal /// `workspace_dir` (which holds memory DBs / tokens and must never become the -/// agent-writable root). A missing directory is auto-created (mirroring the +/// agent-writable root); and it must pass [`refuse_protected_folder`] (no +/// credential store or OS directory, even through a symlink, and nothing inside +/// the OpenHuman data folder). A missing directory is auto-created (mirroring the /// startup auto-create in `channels/runtime/startup.rs`). An empty input clears /// the override and reverts `action_dir` to the default. /// @@ -317,6 +338,8 @@ pub async fn apply_agent_paths_settings( ); } + refuse_protected_folder("action_dir", &candidate, &expanded, config).await?; + if !candidate.exists() { tokio::fs::create_dir_all(&candidate) .await From 43fb043368f96c2d561b2d3924414252f614cb15 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 09:15:15 +0530 Subject: [PATCH 3/7] style: rustfmt the agent paths tests --- crates/openhuman-core/src/config/ops_agent_paths_tests.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/openhuman-core/src/config/ops_agent_paths_tests.rs b/crates/openhuman-core/src/config/ops_agent_paths_tests.rs index cd95dec6209..4ae5968f91d 100644 --- a/crates/openhuman-core/src/config/ops_agent_paths_tests.rs +++ b/crates/openhuman-core/src/config/ops_agent_paths_tests.rs @@ -336,7 +336,10 @@ async fn action_dir_rejected(cfg: &mut Config, value: &std::path::Path) -> Strin ) .await .expect_err("action_dir must be rejected"); - assert!(cfg.action_dir_override.is_none(), "a rejected value is not stored"); + assert!( + cfg.action_dir_override.is_none(), + "a rejected value is not stored" + ); err } From eea1f9f0979dcb3d719532b40ef72ed82badbf4e Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 19:09:52 +0530 Subject: [PATCH 4/7] fix(config): refuse agent folders that contain OpenHuman's state An action_dir or files_dir that contains the workspace, the data root or the folder holding config.toml makes that state part of the agent's root. Refuse it as well as a folder inside the workspace or data root, and fail closed when the data root can't be resolved. --- .../src/config/ops/agent_paths.rs | 43 +++++++++++++++---- .../src/config/ops_agent_paths_tests.rs | 34 +++++++++++++++ 2 files changed, 68 insertions(+), 9 deletions(-) diff --git a/crates/openhuman-core/src/config/ops/agent_paths.rs b/crates/openhuman-core/src/config/ops/agent_paths.rs index 8bb5f1ccb2f..14bad61fb19 100644 --- a/crates/openhuman-core/src/config/ops/agent_paths.rs +++ b/crates/openhuman-core/src/config/ops/agent_paths.rs @@ -224,8 +224,8 @@ async fn validate_files_dir(raw: &str, config: &Config) -> Result Result<(), String> { + let root = crate::config::default_root_openhuman_dir().map_err(|e| { + format!("{kind} can't be checked: the OpenHuman data folder is unknown: {e}") + })?; + let state = [config.workspace_dir.clone(), root]; + let config_dir = config + .config_path + .parent() + .filter(|dir| !dir.as_os_str().is_empty()); + let inside = state.iter().any(|dir| path_within(candidate, dir)); + let contains = state + .iter() + .map(PathBuf::as_path) + .chain(config_dir) + .any(|dir| path_within(dir, candidate)); + if inside || contains { + log::debug!( + "[config][agent_paths] {kind} refused: inside={inside} contains={contains} the data folder" + ); return Err(format!( - "{kind} must not be inside the OpenHuman data folder: {expanded}" + "{kind} must not be inside or contain the OpenHuman data folder: {expanded}" )); } Ok(()) diff --git a/crates/openhuman-core/src/config/ops_agent_paths_tests.rs b/crates/openhuman-core/src/config/ops_agent_paths_tests.rs index 4ae5968f91d..8e19f4643cf 100644 --- a/crates/openhuman-core/src/config/ops_agent_paths_tests.rs +++ b/crates/openhuman-core/src/config/ops_agent_paths_tests.rs @@ -386,6 +386,40 @@ async fn apply_agent_paths_rejects_an_action_dir_inside_the_data_folder() { assert!(!inside.exists(), "nothing is created for a rejected value"); } +/// An `OPENHUMAN_WORKSPACE` profile keeps `config.toml` and its credential +/// files beside the workspace, so the profile folder itself (or any folder +/// above it) must not become the agent's working folder. A sibling folder in +/// the profile reaches none of that state and stays allowed. +#[tokio::test] +async fn apply_agent_paths_rejects_an_action_dir_that_contains_the_profile() { + let _g = ENV_LOCK.lock().await; + unsafe { + std::env::remove_var("OPENHUMAN_ACTION_DIR"); + } + let tmp = tempdir().unwrap(); + let profile = tmp.path().join("profile"); + let mut cfg = Config::default(); + cfg.workspace_dir = profile.join("workspace"); + cfg.config_path = profile.join("config.toml"); + std::fs::create_dir_all(&cfg.workspace_dir).unwrap(); + + for root in [profile.as_path(), tmp.path()] { + let err = action_dir_rejected(&mut cfg, root).await; + assert!(err.contains("OpenHuman data folder"), "{err}"); + } + let beside = profile.join("projects"); + apply_agent_paths_settings( + &mut cfg, + AgentPathsPatch { + action_dir: Some(beside.to_string_lossy().to_string()), + files_dir: None, + }, + ) + .await + .expect("a folder beside the profile's state is allowed"); + assert_eq!(cfg.action_dir_override.as_deref(), Some(beside.as_path())); +} + // --- #3353 regression tests ------------------------------------------------- #[test] From 1bfd12cfe942b0ab15fe216848c3668f49e3a785 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 19:09:52 +0530 Subject: [PATCH 5/7] fix(threads): check thread working folders against OpenHuman's state A thread's working folder replaces action_dir for its turns, but only the protected-path floor checked it. Create, update and resume now apply the same data-folder check as the action_dir setting. --- crates/openhuman-core/src/attachments/mod.rs | 2 +- crates/openhuman-core/src/config/ops/mod.rs | 1 + crates/openhuman-core/src/threads/ops/crud.rs | 6 +- .../src/threads/ops/working_dir.rs | 19 ++- .../src/threads/ops/working_dir_tests.rs | 116 ++++++++++++++++-- .../openhuman-core/src/web_chat/run_task.rs | 2 +- .../openhuman-core/src/web_chat/turn_host.rs | 1 + 7 files changed, 128 insertions(+), 19 deletions(-) diff --git a/crates/openhuman-core/src/attachments/mod.rs b/crates/openhuman-core/src/attachments/mod.rs index 5d2b31d5659..58f03cf49c4 100644 --- a/crates/openhuman-core/src/attachments/mod.rs +++ b/crates/openhuman-core/src/attachments/mod.rs @@ -202,7 +202,7 @@ pub(crate) async fn thread_action_dir( let Some(thread_id) = thread_id.filter(|id| !id.is_empty()) else { return Ok(config.action_dir.clone()); }; - let bound = crate::threads::ops::thread_working_dir(ctx, threads_dir.to_path_buf(), thread_id) + let bound = crate::threads::ops::thread_working_dir(ctx, config, threads_dir.to_path_buf(), thread_id) .await .map_err(anyhow::Error::msg)?; Ok(bound.unwrap_or_else(|| config.action_dir.clone())) diff --git a/crates/openhuman-core/src/config/ops/mod.rs b/crates/openhuman-core/src/config/ops/mod.rs index fdd244f2b03..b45da1b3cd2 100644 --- a/crates/openhuman-core/src/config/ops/mod.rs +++ b/crates/openhuman-core/src/config/ops/mod.rs @@ -81,6 +81,7 @@ pub use agent_paths::{ apply_agent_paths_settings, ensure_agent_dirs, ensure_usable_cwd, expand_tilde, get_agent_paths, load_and_apply_agent_paths_settings, redact_home, AgentPathsPatch, }; +pub(crate) use agent_paths::refuse_data_folder; pub use loader::{ agent_server_status, client_config_json, core_rpc_url_from_env, get_config_snapshot, diff --git a/crates/openhuman-core/src/threads/ops/crud.rs b/crates/openhuman-core/src/threads/ops/crud.rs index 9f0eda08a55..ce4250aeb06 100644 --- a/crates/openhuman-core/src/threads/ops/crud.rs +++ b/crates/openhuman-core/src/threads/ops/crud.rs @@ -71,8 +71,12 @@ pub async fn thread_create_new( request: CreateConversationThreadRequest, ) -> Result>, String> { let dir = workspace_dir().await?; + let config = ctx + .load_config() + .await + .map_err(|e| format!("load config: {e}"))?; let working_dir = - super::working_dir::validate_working_dir(request.action_dir.as_deref()).await?; + super::working_dir::validate_working_dir(request.action_dir.as_deref(), &config).await?; let id = format!("thread-{}", uuid::Uuid::new_v4()); let now = chrono::Local::now(); let title = format!("Chat {} {}", now.format("%b %-d"), now.format("%-I:%M %p")); diff --git a/crates/openhuman-core/src/threads/ops/working_dir.rs b/crates/openhuman-core/src/threads/ops/working_dir.rs index f9acc3e53ea..68631c617fc 100644 --- a/crates/openhuman-core/src/threads/ops/working_dir.rs +++ b/crates/openhuman-core/src/threads/ops/working_dir.rs @@ -8,6 +8,7 @@ //! in another. use super::support::{counts, envelope, thread_to_summary, workspace_dir}; +use crate::config::Config; use crate::core::runtime::DispatchCtx; use crate::core::Outcome; use crate::security::SecurityPolicy; @@ -23,8 +24,12 @@ use std::path::{Path, PathBuf}; /// /// The folder must be an existing absolute directory outside the paths the /// security policy never opens (credential stores, system roots), the same -/// floor that holds with the autonomy policy disabled. -pub(crate) async fn validate_working_dir(raw: Option<&str>) -> Result, String> { +/// floor that holds with the autonomy policy disabled. Like the global +/// `action_dir`, it must neither sit inside nor contain OpenHuman's own state. +pub(crate) async fn validate_working_dir( + raw: Option<&str>, + config: &Config, +) -> Result, String> { let Some(raw) = raw.map(str::trim).filter(|raw| !raw.is_empty()) else { return Ok(None); }; @@ -44,6 +49,7 @@ pub(crate) async fn validate_working_dir(raw: Option<&str>) -> Result) -> Result Result, String> { @@ -66,7 +73,7 @@ pub(crate) async fn thread_working_dir( let Some(bound) = bound else { return Ok(None); }; - match validate_working_dir(Some(&bound)).await { + match validate_working_dir(Some(&bound), config).await { Ok(Some(dir)) => Ok(Some(PathBuf::from(dir))), Ok(None) => Ok(None), Err(err) => Err(format!("thread working folder is unusable: {err}")), @@ -79,7 +86,11 @@ pub async fn thread_update_working_dir( request: UpdateConversationThreadWorkingDirRequest, ) -> Result>, ThreadsError> { let dir = workspace_dir().await?; - let working_dir = validate_working_dir(Some(&request.action_dir)).await?; + let config = ctx + .load_config() + .await + .map_err(|e| format!("load config: {e}"))?; + let working_dir = validate_working_dir(Some(&request.action_dir), &config).await?; let Some(thread) = conversations::blocking::list_threads(ctx.clone(), dir.clone()) .await? .into_iter() diff --git a/crates/openhuman-core/src/threads/ops/working_dir_tests.rs b/crates/openhuman-core/src/threads/ops/working_dir_tests.rs index 69abee807fe..ef88c6f5656 100644 --- a/crates/openhuman-core/src/threads/ops/working_dir_tests.rs +++ b/crates/openhuman-core/src/threads/ops/working_dir_tests.rs @@ -1,9 +1,23 @@ use super::*; +/// A config whose state lives in `/profile` (workspace and config.toml). +fn profile_config(root: &Path) -> Config { + let mut config = Config::default(); + config.workspace_dir = root.join("profile").join("workspace"); + config.config_path = root.join("profile").join("config.toml"); + std::fs::create_dir_all(&config.workspace_dir).unwrap(); + config +} + #[tokio::test] async fn empty_request_uses_the_global_folder() { - assert_eq!(validate_working_dir(None).await.unwrap(), None); - assert_eq!(validate_working_dir(Some(" ")).await.unwrap(), None); + let temp = tempfile::tempdir().unwrap(); + let config = profile_config(temp.path()); + assert_eq!(validate_working_dir(None, &config).await.unwrap(), None); + assert_eq!( + validate_working_dir(Some(" "), &config).await.unwrap(), + None + ); } #[tokio::test] @@ -12,34 +26,73 @@ async fn existing_absolute_directory_is_canonicalized() { let nested = temp.path().join("project"); std::fs::create_dir(&nested).unwrap(); let raw = format!("{}/./", nested.display()); - let validated = validate_working_dir(Some(&raw)).await.unwrap().unwrap(); + let validated = validate_working_dir(Some(&raw), &profile_config(temp.path())) + .await + .unwrap() + .unwrap(); assert_eq!(PathBuf::from(validated), nested.canonicalize().unwrap()); } #[tokio::test] async fn relative_missing_file_and_forbidden_paths_are_rejected() { - assert!(validate_working_dir(Some("relative/dir")).await.is_err()); - let temp = tempfile::tempdir().unwrap(); + let config = profile_config(temp.path()); + assert!(validate_working_dir(Some("relative/dir"), &config) + .await + .is_err()); + assert!( - validate_working_dir(Some(&temp.path().join("missing").display().to_string())) - .await + validate_working_dir( + Some(&temp.path().join("missing").display().to_string()), + &config + ) + .await .is_err() ); let file = temp.path().join("file.txt"); std::fs::write(&file, "x").unwrap(); - assert!(validate_working_dir(Some(&file.display().to_string())) + assert!(validate_working_dir(Some(&file.display().to_string()), &config) .await .is_err()); let ssh = temp.path().join(".ssh"); std::fs::create_dir(&ssh).unwrap(); - assert!(validate_working_dir(Some(&ssh.display().to_string())) + assert!(validate_working_dir(Some(&ssh.display().to_string()), &config) .await .is_err()); } +/// TS-E2E-021 on the thread path: a thread's working folder becomes the +/// agent's `action_dir`, so it must not sit inside or contain OpenHuman's +/// state. A folder beside that state stays allowed. +#[tokio::test] +async fn a_working_folder_inside_or_around_the_data_folder_is_rejected() { + let temp = tempfile::tempdir().unwrap(); + let config = profile_config(temp.path()); + let vault = config.workspace_dir.join("vault"); + std::fs::create_dir(&vault).unwrap(); + for dir in [ + config.workspace_dir.as_path(), + vault.as_path(), + temp.path().join("profile").as_path(), + temp.path(), + ] { + let error = validate_working_dir(Some(&dir.display().to_string()), &config) + .await + .expect_err("a folder inside or around the data folder"); + assert!(error.contains("OpenHuman data folder"), "{dir:?}: {error}"); + } + let beside = temp.path().join("profile").join("projects"); + std::fs::create_dir(&beside).unwrap(); + assert!( + validate_working_dir(Some(&beside.display().to_string()), &config) + .await + .unwrap() + .is_some() + ); +} + fn thread(id: &str, working_dir: Option) -> conversations::CreateConversationThread { conversations::CreateConversationThread { id: id.into(), @@ -56,6 +109,7 @@ fn thread(id: &str, working_dir: Option) -> conversations::CreateConvers async fn a_bound_folder_that_disappears_fails_closed() { // The thread must not silently fall back to the global folder. let temp = tempfile::tempdir().unwrap(); + let config = profile_config(temp.path()); let workspace = temp.path().join("internal"); let folder = temp.path().join("project"); std::fs::create_dir(&folder).unwrap(); @@ -69,14 +123,14 @@ async fn a_bound_folder_that_disappears_fails_closed() { .await .unwrap(); assert_eq!( - thread_working_dir(&ctx, workspace.clone(), "bound") + thread_working_dir(&ctx, &config, workspace.clone(), "bound") .await .unwrap(), Some(folder.clone()) ); std::fs::remove_dir(&folder).unwrap(); - let error = thread_working_dir(&ctx, workspace, "bound") + let error = thread_working_dir(&ctx, &config, workspace, "bound") .await .expect_err("a vanished bound folder"); assert!(error.contains("unusable"), "{error}"); @@ -119,7 +173,9 @@ async fn the_working_folder_is_fixed_after_the_first_message() { ) .await .unwrap(); - let error = thread_update_working_dir(&ctx, request(home.path())) + let other = home.path().join("other"); + std::fs::create_dir(&other).unwrap(); + let error = thread_update_working_dir(&ctx, request(&other)) .await .map(|_| ()) .expect_err("rebinding after the first message"); @@ -130,3 +186,39 @@ async fn the_working_folder_is_fixed_after_the_first_message() { "{error}" ); } + +/// The update RPC checks the folder against the loaded profile: with +/// `OPENHUMAN_WORKSPACE` set, the profile root holds config.toml and the +/// workspace, so binding it is refused and nothing is stored. +#[tokio::test] +async fn binding_the_profile_root_as_a_working_folder_is_refused() { + let _lock = crate::config::TEST_ENV_LOCK.lock().await; + let home = tempfile::tempdir().unwrap(); + let _workspace = crate::config::test_env::EnvVarGuard::workspace_unlocked(home.path()); + let ctx = DispatchCtx::ambient(); + let workspace = workspace_dir().await.unwrap(); + conversations::blocking::ensure_thread(ctx.clone(), workspace.clone(), thread("t", None)) + .await + .unwrap(); + let error = thread_update_working_dir( + &ctx, + UpdateConversationThreadWorkingDirRequest { + thread_id: "t".into(), + action_dir: home.path().display().to_string(), + }, + ) + .await + .map(|_| ()) + .expect_err("the profile root holds OpenHuman's state"); + assert!( + error.to_string().contains("OpenHuman data folder"), + "{error}" + ); + let stored = conversations::blocking::list_threads(ctx, workspace) + .await + .unwrap() + .into_iter() + .find(|thread| thread.id == "t") + .unwrap(); + assert_eq!(stored.working_dir, None, "a refused folder is not stored"); +} diff --git a/crates/openhuman-core/src/web_chat/run_task.rs b/crates/openhuman-core/src/web_chat/run_task.rs index 4e7d1128e7b..b8ddbe7f98e 100644 --- a/crates/openhuman-core/src/web_chat/run_task.rs +++ b/crates/openhuman-core/src/web_chat/run_task.rs @@ -122,7 +122,7 @@ pub(crate) async fn run_chat_task( // policy (which grants `action_dir` as a trusted root) and its tools are // all built on the thread's folder. let thread_dir = - crate::threads::ops::thread_working_dir(ctx, config.workspace_dir.clone(), thread_id) + crate::threads::ops::thread_working_dir(ctx, &config, config.workspace_dir.clone(), thread_id) .await?; if let Some(dir) = &thread_dir { log::debug!("[web-channel] thread working folder applied thread_id={thread_id}"); diff --git a/crates/openhuman-core/src/web_chat/turn_host.rs b/crates/openhuman-core/src/web_chat/turn_host.rs index 029968359a2..8337872c17d 100644 --- a/crates/openhuman-core/src/web_chat/turn_host.rs +++ b/crates/openhuman-core/src/web_chat/turn_host.rs @@ -156,6 +156,7 @@ impl WebHost { // tools are all built on the thread's folder. let thread_dir = crate::threads::ops::thread_working_dir( &ctx, + &config, config.workspace_dir.clone(), &request.thread_id, ) From 24acae93c0e33e87f9e56aa68c3131f37567c047 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 19:35:15 +0530 Subject: [PATCH 6/7] style: rustfmt the thread working folder check --- crates/openhuman-core/src/attachments/mod.rs | 7 +++-- crates/openhuman-core/src/config/ops/mod.rs | 2 +- .../src/threads/ops/working_dir_tests.rs | 30 ++++++++++--------- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/crates/openhuman-core/src/attachments/mod.rs b/crates/openhuman-core/src/attachments/mod.rs index 58f03cf49c4..e10113692be 100644 --- a/crates/openhuman-core/src/attachments/mod.rs +++ b/crates/openhuman-core/src/attachments/mod.rs @@ -202,9 +202,10 @@ pub(crate) async fn thread_action_dir( let Some(thread_id) = thread_id.filter(|id| !id.is_empty()) else { return Ok(config.action_dir.clone()); }; - let bound = crate::threads::ops::thread_working_dir(ctx, config, threads_dir.to_path_buf(), thread_id) - .await - .map_err(anyhow::Error::msg)?; + let bound = + crate::threads::ops::thread_working_dir(ctx, config, threads_dir.to_path_buf(), thread_id) + .await + .map_err(anyhow::Error::msg)?; Ok(bound.unwrap_or_else(|| config.action_dir.clone())) } diff --git a/crates/openhuman-core/src/config/ops/mod.rs b/crates/openhuman-core/src/config/ops/mod.rs index b45da1b3cd2..fad736fdeb5 100644 --- a/crates/openhuman-core/src/config/ops/mod.rs +++ b/crates/openhuman-core/src/config/ops/mod.rs @@ -77,11 +77,11 @@ pub use agent::{ get_autonomy_settings, load_and_apply_agent_settings, load_and_apply_autonomy_settings, AgentSettingsPatch, AutonomySettingsPatch, }; +pub(crate) use agent_paths::refuse_data_folder; pub use agent_paths::{ apply_agent_paths_settings, ensure_agent_dirs, ensure_usable_cwd, expand_tilde, get_agent_paths, load_and_apply_agent_paths_settings, redact_home, AgentPathsPatch, }; -pub(crate) use agent_paths::refuse_data_folder; pub use loader::{ agent_server_status, client_config_json, core_rpc_url_from_env, get_config_snapshot, diff --git a/crates/openhuman-core/src/threads/ops/working_dir_tests.rs b/crates/openhuman-core/src/threads/ops/working_dir_tests.rs index ef88c6f5656..dd85ff01408 100644 --- a/crates/openhuman-core/src/threads/ops/working_dir_tests.rs +++ b/crates/openhuman-core/src/threads/ops/working_dir_tests.rs @@ -41,26 +41,28 @@ async fn relative_missing_file_and_forbidden_paths_are_rejected() { .await .is_err()); - assert!( - validate_working_dir( - Some(&temp.path().join("missing").display().to_string()), - &config - ) - .await - .is_err() - ); + assert!(validate_working_dir( + Some(&temp.path().join("missing").display().to_string()), + &config + ) + .await + .is_err()); let file = temp.path().join("file.txt"); std::fs::write(&file, "x").unwrap(); - assert!(validate_working_dir(Some(&file.display().to_string()), &config) - .await - .is_err()); + assert!( + validate_working_dir(Some(&file.display().to_string()), &config) + .await + .is_err() + ); let ssh = temp.path().join(".ssh"); std::fs::create_dir(&ssh).unwrap(); - assert!(validate_working_dir(Some(&ssh.display().to_string()), &config) - .await - .is_err()); + assert!( + validate_working_dir(Some(&ssh.display().to_string()), &config) + .await + .is_err() + ); } /// TS-E2E-021 on the thread path: a thread's working folder becomes the From 5d746c01db0221eafb548c7b35245186b652c890 Mon Sep 17 00:00:00 2001 From: M3gA-Mind Date: Fri, 6 Nov 2026 20:14:10 +0530 Subject: [PATCH 7/7] fix(threads): also refuse the thread store's workspace as a working folder In single-user mode the store's workspace_dir() comes from the disk config and can differ from the dispatch context's config, so check both. --- crates/openhuman-core/src/threads/ops/crud.rs | 8 +++-- .../src/threads/ops/working_dir.rs | 31 +++++++++++++++++-- .../src/threads/ops/working_dir_tests.rs | 27 ++++++++++++++++ 3 files changed, 61 insertions(+), 5 deletions(-) diff --git a/crates/openhuman-core/src/threads/ops/crud.rs b/crates/openhuman-core/src/threads/ops/crud.rs index ce4250aeb06..a5cd9242d5d 100644 --- a/crates/openhuman-core/src/threads/ops/crud.rs +++ b/crates/openhuman-core/src/threads/ops/crud.rs @@ -75,8 +75,12 @@ pub async fn thread_create_new( .load_config() .await .map_err(|e| format!("load config: {e}"))?; - let working_dir = - super::working_dir::validate_working_dir(request.action_dir.as_deref(), &config).await?; + let working_dir = super::working_dir::validate_working_dir_for_store( + request.action_dir.as_deref(), + &config, + &dir, + ) + .await?; let id = format!("thread-{}", uuid::Uuid::new_v4()); let now = chrono::Local::now(); let title = format!("Chat {} {}", now.format("%b %-d"), now.format("%-I:%M %p")); diff --git a/crates/openhuman-core/src/threads/ops/working_dir.rs b/crates/openhuman-core/src/threads/ops/working_dir.rs index 68631c617fc..7d0df26cf4b 100644 --- a/crates/openhuman-core/src/threads/ops/working_dir.rs +++ b/crates/openhuman-core/src/threads/ops/working_dir.rs @@ -53,6 +53,30 @@ pub(crate) async fn validate_working_dir( Ok(Some(canonical.to_string_lossy().into_owned())) } +/// [`validate_working_dir`], also refusing the workspace the thread store +/// uses. In single-user mode the store's `workspace_dir()` (the disk config) +/// can differ from the dispatch context's config. +pub(crate) async fn validate_working_dir_for_store( + raw: Option<&str>, + config: &Config, + store: &Path, +) -> Result, String> { + let validated = validate_working_dir(raw, config).await?; + if let Some(dir) = &validated { + if store != config.workspace_dir { + let mut store_config = config.clone(); + store_config.workspace_dir = store.to_path_buf(); + crate::config::ops::refuse_data_folder( + "working folder", + Path::new(dir), + dir, + &store_config, + )?; + } + } + Ok(validated) +} + /// The working folder bound to `thread_id`, if the thread exists and has one. /// /// An unusable bound folder is an error, rather than a reason to run in the @@ -63,7 +87,7 @@ pub(crate) async fn thread_working_dir( workspace_dir: PathBuf, thread_id: &str, ) -> Result, String> { - let threads = conversations::blocking::list_threads(ctx.clone(), workspace_dir) + let threads = conversations::blocking::list_threads(ctx.clone(), workspace_dir.clone()) .await .map_err(|err| format!("failed to load thread working folder: {err}"))?; let bound = threads @@ -73,7 +97,7 @@ pub(crate) async fn thread_working_dir( let Some(bound) = bound else { return Ok(None); }; - match validate_working_dir(Some(&bound), config).await { + match validate_working_dir_for_store(Some(&bound), config, &workspace_dir).await { Ok(Some(dir)) => Ok(Some(PathBuf::from(dir))), Ok(None) => Ok(None), Err(err) => Err(format!("thread working folder is unusable: {err}")), @@ -90,7 +114,8 @@ pub async fn thread_update_working_dir( .load_config() .await .map_err(|e| format!("load config: {e}"))?; - let working_dir = validate_working_dir(Some(&request.action_dir), &config).await?; + let working_dir = + validate_working_dir_for_store(Some(&request.action_dir), &config, &dir).await?; let Some(thread) = conversations::blocking::list_threads(ctx.clone(), dir.clone()) .await? .into_iter() diff --git a/crates/openhuman-core/src/threads/ops/working_dir_tests.rs b/crates/openhuman-core/src/threads/ops/working_dir_tests.rs index dd85ff01408..50fad7a27ad 100644 --- a/crates/openhuman-core/src/threads/ops/working_dir_tests.rs +++ b/crates/openhuman-core/src/threads/ops/working_dir_tests.rs @@ -95,6 +95,33 @@ async fn a_working_folder_inside_or_around_the_data_folder_is_rejected() { ); } +/// The thread store's workspace can differ from the context config's (single +/// user: the disk config vs the embedder config). A folder inside the store's +/// workspace is refused even when the context config doesn't name it. +#[tokio::test] +async fn a_working_folder_inside_the_thread_stores_workspace_is_rejected() { + let temp = tempfile::tempdir().unwrap(); + let config = profile_config(temp.path()); + let store = temp.path().join("store").join("workspace"); + let inside = store.join("threads"); + std::fs::create_dir_all(&inside).unwrap(); + let raw = inside.display().to_string(); + + assert!( + validate_working_dir(Some(&raw), &config).await.is_ok(), + "the context config alone doesn't cover the store's workspace" + ); + let error = validate_working_dir_for_store(Some(&raw), &config, &store) + .await + .expect_err("a folder inside the thread store's workspace"); + assert!(error.contains("OpenHuman data folder"), "{error}"); + assert!( + validate_working_dir_for_store(Some(&raw), &config, &config.workspace_dir) + .await + .is_ok() + ); +} + fn thread(id: &str, working_dir: Option) -> conversations::CreateConversationThread { conversations::CreateConversationThread { id: id.into(),