The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix: revalidate media artifact reads and attachments
Steven Enamakelb4913be5b4e0
diff --git a/crates/openhuman-core/src/agent/attachments/mod.rs b/crates/openhuman-core/src/agent/attachments/mod.rsindex 0124414adb..26b6ab6d3c 100644--- a/crates/openhuman-core/src/agent/attachments/mod.rs+++ b/crates/openhuman-core/src/agent/attachments/mod.rs@@ -179,7 +179,13 @@ pub(crate) async fn thread_action_dir(}fn policy(config: &Config, root: &Path) -> SecurityPolicy {- SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, root)+ let policy = SecurityPolicy::from_config(&config.autonomy, &config.workspace_dir, root);+ *policy+ .media_files_roots+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner) =+ Some(crate::agent::artifacts::FileRoots::from_config(config));+ policy}/// Resolve a local attachment under the same filesystem policy as actingdiff --git a/crates/openhuman-core/src/agent/attachments/mod_tests.rs b/crates/openhuman-core/src/agent/attachments/mod_tests.rsindex 37c9279807..4d4cfa8967 100644--- a/crates/openhuman-core/src/agent/attachments/mod_tests.rs+++ b/crates/openhuman-core/src/agent/attachments/mod_tests.rs@@ -189,6 +189,52 @@ fn config(root: &Path) -> Config {}}+#[tokio::test]+async fn ready_media_artifact_in_files_folder_can_be_attached() {+ let temp = tempfile::tempdir().unwrap();+ let mut config = config(temp.path());+ let files = temp.path().join("Files");+ tokio::fs::create_dir_all(&files).await.unwrap();+ config.files_dir_override = Some(files.clone());+ config.autonomy.enabled = true;++ let (artifact, path) = crate::agent::artifacts::create_artifact(+ &config.workspace_dir,+ &files,+ crate::agent::artifacts::ArtifactKind::Image,+ "Generated image",+ "png",+ None,+ )+ .await+ .unwrap();+ tokio::fs::write(&path, b"image bytes").await.unwrap();+ crate::agent::artifacts::finalize_artifact(&config.workspace_dir, &artifact.id, 11, None)+ .await+ .unwrap();++ let resolved = resolve_path(+ &config,+ &path.to_string_lossy(),+ &AttachmentAccessScope::default(),+ )+ .await+ .unwrap();+ assert_eq!(resolved, path.canonicalize().unwrap());++ let unrelated = files.join("unrelated.png");+ tokio::fs::write(&unrelated, b"not a filed media artifact")+ .await+ .unwrap();+ assert!(resolve_path(+ &config,+ &unrelated.to_string_lossy(),+ &AttachmentAccessScope::default(),+ )+ .await+ .is_err());+}+#[tokio::test]async fn arbitrary_original_is_durable_and_reference_contains_no_payload() {let temp = tempfile::tempdir().unwrap();diff --git a/crates/openhuman-core/src/security/policy/path_checks.rs b/crates/openhuman-core/src/security/policy/path_checks.rsindex aae84e7110..2bb5c2fa84 100644--- a/crates/openhuman-core/src/security/policy/path_checks.rs+++ b/crates/openhuman-core/src/security/policy/path_checks.rs@@ -342,16 +342,17 @@ impl SecurityPolicy {let resolved = tokio::fs::canonicalize(&full_path).await.map_err(|e| format!("Failed to resolve path '{path}': {e}"))?;- if !self.is_resolved_path_allowed_for(&resolved, false)- && !self.authorize_ready_media_artifact_path(&resolved).await- {+ let is_allowed_root = self.is_resolved_path_allowed_for(&resolved, false);+ let is_ready_media_artifact =+ !is_allowed_root && self.authorize_ready_media_artifact_path(&resolved).await;+ if !is_allowed_root && !is_ready_media_artifact {return Err(format!("{POLICY_BLOCKED_MARKER} Resolved path escapes workspace: {}",resolved.display()));}let workspace_root = self.workspace_root().await;- self.check_resolved_against_forbidden(&resolved, &workspace_root)?;+ self.check_resolved_against_forbidden(&resolved, &workspace_root, is_ready_media_artifact)?;log::debug!("[security] validate_path: '{}' resolved to '{}'",path,@@ -418,8 +419,8 @@ impl SecurityPolicy {let result = resolved_parent.join(file_name);let workspace_root = self.workspace_root().await;- self.check_resolved_against_forbidden(&canonical_ancestor, &workspace_root)?;- self.check_resolved_against_forbidden(&result, &workspace_root)?;+ self.check_resolved_against_forbidden(&canonical_ancestor, &workspace_root, false)?;+ self.check_resolved_against_forbidden(&result, &workspace_root, false)?;log::debug!("[security] validate_parent_path: '{}' resolved parent to '{}'",@@ -573,9 +574,6 @@ impl SecurityPolicy {if !self.enabled {return true;}- if !require_write && self.is_media_artifact_path_cached(resolved) {- return true;- }let workspace_root = self.workspace_root_sync();resolved.starts_with(&workspace_root)|| self.is_within_trusted_root(resolved, require_write)@@ -588,6 +586,7 @@ impl SecurityPolicy {&self,resolved: &Path,workspace_root: &Path,+ ready_media_artifact: bool,) -> Result<(), String> {// Credential stores are never reachable, even via a trusted-root grant.if Self::is_always_forbidden(resolved) {@@ -607,7 +606,7 @@ impl SecurityPolicy {resolved.display()));}- if self.is_media_artifact_path_cached(resolved) {+ if ready_media_artifact {return Ok(());}// A trusted-root grant takes precedence over forbidden_paths for its subtree.@@ -654,9 +653,11 @@ impl SecurityPolicy {.unwrap_or_else(std::sync::PoisonError::into_inner).clone()else {+ self.forget_media_artifact_path(path);return false;};if !roots.contains_path(path) {+ self.forget_media_artifact_path(path);return false;}@@ -703,6 +704,14 @@ impl SecurityPolicy {return true;}}+ self.forget_media_artifact_path(path);false}++ fn forget_media_artifact_path(&self, path: &Path) {+ self.media_artifact_paths+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner)+ .remove(path);+ }}diff --git a/crates/openhuman-core/src/security/policy/policy_media_artifact_tests.rs b/crates/openhuman-core/src/security/policy/policy_media_artifact_tests.rsindex 60541eb982..854296beef 100644--- a/crates/openhuman-core/src/security/policy/policy_media_artifact_tests.rs+++ b/crates/openhuman-core/src/security/policy/policy_media_artifact_tests.rs@@ -58,9 +58,9 @@ async fn ready_media_artifacts_are_readable_but_other_files_are_not() {.unwrap();let policy = SecurityPolicy {- workspace_dir: workspace,+ workspace_dir: workspace.clone(),action_dir: tmp.path().join("action"),- media_files_roots: Arc::new(std::sync::Mutex::new(Some(FileRoots::new(files)))),+ media_files_roots: Arc::new(std::sync::Mutex::new(Some(FileRoots::new(files.clone())))),..SecurityPolicy::default()};@@ -76,4 +76,18 @@ async fn ready_media_artifacts_are_readable_but_other_files_are_not() {.validate_path(&pending_path.to_string_lossy()).await.is_err());++ crate::agent::artifacts::store::delete_artifact(&workspace, FileRoots::new(files), &image.id)+ .await+ .unwrap();+ tokio::fs::write(&image_path, b"unrelated replacement")+ .await+ .unwrap();+ assert!(+ policy+ .validate_path(&image_path.to_string_lossy())+ .await+ .is_err(),+ "a cached path must not authorize a replacement file"+ );}