Skip to content

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

fix(artifacts): refuse protected paths under their macOS canonical name

Sanil87bae2c65c9b
diff --git a/crates/openhuman-core/src/agent/artifacts/tiny_store.rs b/crates/openhuman-core/src/agent/artifacts/tiny_store.rs
index 30af11ac2f..d8c11aa13c 100644
--- a/crates/openhuman-core/src/agent/artifacts/tiny_store.rs
+++ b/crates/openhuman-core/src/agent/artifacts/tiny_store.rs
@@ -272,8 +272,17 @@ fn contains(folder: &Path, inside: &Path) -> bool {
/// Why a resolved path may not be an artifact's file, if it may not: it is in
/// a location OpenHuman never lets the agent reach (credential stores, system
/// roots), however broad the folders around it.
+///
+/// The guard sees canonical paths, and on macOS `/etc` canonicalizes to
+/// `/private/etc`: a `/private/...` path is also checked without that prefix,
+/// as the protected prefixes name the familiar form.
pub fn refused_path(path: &Path) -> Option<String> {
- crate::security::SecurityPolicy::is_always_forbidden(path)
+ let forbidden = |p: &Path| crate::security::SecurityPolicy::is_always_forbidden(p);
+ let aliased = path
+ .strip_prefix("/private")
+ .ok()
+ .map(|rest| Path::new("/").join(rest));
+ (forbidden(path) || aliased.as_deref().is_some_and(forbidden))
.then(|| "the file is in a protected location".to_string())
}
diff --git a/crates/openhuman-core/src/agent/artifacts/tiny_store_tests.rs b/crates/openhuman-core/src/agent/artifacts/tiny_store_tests.rs
index 9330148af0..db59821088 100644
--- a/crates/openhuman-core/src/agent/artifacts/tiny_store_tests.rs
+++ b/crates/openhuman-core/src/agent/artifacts/tiny_store_tests.rs
@@ -273,3 +273,14 @@ fn a_working_folder_that_contains_the_workspace_is_not_trusted() {
let roots = file_roots(&workspace, &FileRoots::new(&files), Some(&beside));
assert_eq!(roots.first(), Some(&beside));
}
+
+#[test]
+fn a_protected_location_is_refused_under_its_macos_canonical_name() {
+ // `/etc` canonicalizes to `/private/etc` on macOS.
+ assert!(refused_path(Path::new("/private/etc/hosts")).is_some());
+ assert!(refused_path(Path::new("/etc/hosts")).is_some());
+ // `/private/var` and `/private/tmp` (temp folders) are not protected.
+ assert!(refused_path(Path::new("/private/var/folders/x/notes.md")).is_none());
+ assert!(refused_path(Path::new("/private/tmp/notes.md")).is_none());
+ assert!(refused_path(Path::new("/Users/me/OpenHuman/notes.md")).is_none());
+}