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(artifacts): guard a symlinked artifact dir and keep relative workspaces
M3gA-Mindf4bf591be425
diff --git a/crates/openhuman-core/src/artifacts/files_tests.rs b/crates/openhuman-core/src/artifacts/files_tests.rsindex b2dfc224e0..e807caf95e 100644--- a/crates/openhuman-core/src/artifacts/files_tests.rs+++ b/crates/openhuman-core/src/artifacts/files_tests.rs@@ -453,3 +453,21 @@ async fn a_legacy_record_symlinked_out_of_the_artifacts_root_is_refused() {read.map(|bytes| String::from_utf8_lossy(&bytes).into_owned()));}++/// An embedder may pass a relative workspace; a legacy record must still+/// resolve through the escape guard, which only accepts absolute paths.+#[tokio::test]+async fn a_legacy_record_in_a_relative_workspace_still_resolves() {+ let tmp = tempfile::Builder::new()+ .prefix("artifacts-relative-ws-")+ .tempdir_in(".")+ .unwrap();+ let ws = Path::new(tmp.path().file_name().unwrap());+ let meta = legacy_meta("legacy-4", "legacy-4/x.txt");+ save_artifact_meta(ws, &meta).await.unwrap();+ std::fs::create_dir_all(ws.join("artifacts/legacy-4")).unwrap();+ std::fs::write(ws.join("artifacts/legacy-4/x.txt"), b"abc").unwrap();++ let bytes = read_artifact_bytes(ws, ws, "legacy-4").await.unwrap();+ assert_eq!(bytes, b"abc");+}diff --git a/crates/openhuman-core/src/artifacts/migrate.rs b/crates/openhuman-core/src/artifacts/migrate.rsindex a6401ce542..1c11fa636a 100644--- a/crates/openhuman-core/src/artifacts/migrate.rs+++ b/crates/openhuman-core/src/artifacts/migrate.rs@@ -133,8 +133,12 @@ pub(crate) async fn migrate_with(fn legacy_bytes(root: &Path, artifact_dir: &Path, meta: &ArtifactMeta) -> Option<PathBuf> {let candidate = root.join(&meta.path);// The escape guard also refuses a symlink that leads out of the directory.- (super::files::check_within(artifact_dir, &candidate).is_ok() && candidate.is_file())- .then_some(candidate)+ // Check against `root` too: when `artifact_dir` is itself a symlink, both+ // sides of the inner check resolve through it.+ (super::files::check_within(root, &candidate).is_ok()+ && super::files::check_within(artifact_dir, &candidate).is_ok()+ && candidate.is_file())+ .then_some(candidate)}/// For a migrated record, every regular file in its artifact directory otherdiff --git a/crates/openhuman-core/src/artifacts/migrate_tests.rs b/crates/openhuman-core/src/artifacts/migrate_tests.rsindex 4f2080688f..6a887e9a2e 100644--- a/crates/openhuman-core/src/artifacts/migrate_tests.rs+++ b/crates/openhuman-core/src/artifacts/migrate_tests.rs@@ -346,3 +346,26 @@ async fn a_legacy_file_symlinked_out_of_its_directory_is_not_migrated() {assert_eq!(report.moved, 0);assert!(visible(&files_dir).is_empty(), "{:?}", visible(&files_dir));}++/// A symlinked artifact directory must not make its external files migratable:+/// the inner guard alone resolves both sides through the same link.+#[cfg(unix)]+#[tokio::test]+async fn a_legacy_artifact_directory_symlinked_outside_is_not_migrated() {+ let tmp = TempDir::new().unwrap();+ let ws = tmp.path().join("ws");+ let files_dir = tmp.path().join("Files");+ let outside = tmp.path().join("outside");+ std::fs::create_dir_all(&outside).unwrap();+ legacy(&ws, "s2", "x.txt", b"placeholder", ArtifactStatus::Ready).await;+ let dir = ws.join("artifacts").join("s2");+ std::fs::remove_dir_all(&dir).unwrap();+ std::fs::write(outside.join("x.txt"), b"private").unwrap();+ std::os::unix::fs::symlink(&outside, &dir).unwrap();++ let report = migrate_legacy_artifacts(&ws, &files_dir).await;++ assert_eq!(report.moved, 0);+ assert!(visible(&files_dir).is_empty(), "{:?}", visible(&files_dir));+ assert!(outside.join("x.txt").exists(), "external file was removed");+}diff --git a/crates/openhuman-core/src/artifacts/store.rs b/crates/openhuman-core/src/artifacts/store.rsindex 451f4a296a..3574ec9866 100644--- a/crates/openhuman-core/src/artifacts/store.rs+++ b/crates/openhuman-core/src/artifacts/store.rs@@ -19,7 +19,11 @@ const ARGS_FILENAME: &str = "args.json";////// The root lives at `<workspace_dir>/artifacts/`.pub(crate) async fn artifacts_root(workspace_dir: &Path) -> Result<PathBuf, String> {- let root = workspace_dir.join(ARTIFACTS_SUBDIR);+ // Absolute, so the escape guard (which refuses relative paths) also works+ // for an embedder's relative workspace.+ let root = std::path::absolute(workspace_dir)+ .map_err(|e| format!("[artifacts] failed to resolve workspace {workspace_dir:?}: {e}"))?+ .join(ARTIFACTS_SUBDIR);log::debug!("[artifacts] artifacts_root: {:?}", root);tokio::fs::create_dir_all(&root).await.map_err(|e| {format!(