Skip to content

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

fix(sandbox): a not-yet-created workspace inside a credential store is refused

M3gA-Mindd597204600cc
diff --git a/crates/openhuman-core/src/config/ops/agent_paths.rs b/crates/openhuman-core/src/config/ops/agent_paths.rs
index 8fe894f438..e47ed59797 100644
--- a/crates/openhuman-core/src/config/ops/agent_paths.rs
+++ b/crates/openhuman-core/src/config/ops/agent_paths.rs
@@ -233,7 +233,7 @@ fn path_within(path: &Path, dir: &Path) -> bool {
canonical_prefix(path).starts_with(canonical_prefix(dir))
}
-fn canonical_prefix(path: &Path) -> PathBuf {
+pub(crate) fn canonical_prefix(path: &Path) -> PathBuf {
let mut rest = Vec::new();
let mut cursor = path;
loop {
diff --git a/crates/openhuman-core/src/config/ops/mod.rs b/crates/openhuman-core/src/config/ops/mod.rs
index b871707d06..a5bfbb6148 100644
--- a/crates/openhuman-core/src/config/ops/mod.rs
+++ b/crates/openhuman-core/src/config/ops/mod.rs
@@ -2,6 +2,7 @@
mod agent;
mod agent_paths;
+pub(crate) use agent_paths::canonical_prefix;
mod cloud_providers;
mod loader;
mod model;
diff --git a/crates/openhuman-core/src/sandbox/native_jail.rs b/crates/openhuman-core/src/sandbox/native_jail.rs
index ba13f013d5..e402038f66 100644
--- a/crates/openhuman-core/src/sandbox/native_jail.rs
+++ b/crates/openhuman-core/src/sandbox/native_jail.rs
@@ -277,7 +277,9 @@ fn credential_denials(
) -> anyhow::Result<Vec<String>> {
let granted: Vec<std::path::PathBuf> = std::iter::once(root)
.chain(read_write.iter().map(std::path::PathBuf::as_path))
- .filter_map(|path| path.canonicalize().ok())
+ // A root or grant that doesn't exist yet still sits where its nearest
+ // existing ancestor resolves; dropping it skipped the check for it.
+ .map(crate::config::ops::canonical_prefix)
.collect();
let mut denied = Vec::new();
for store in stores {
diff --git a/crates/openhuman-core/src/sandbox/native_jail_tests.rs b/crates/openhuman-core/src/sandbox/native_jail_tests.rs
index 43ba95590d..937b620b26 100644
--- a/crates/openhuman-core/src/sandbox/native_jail_tests.rs
+++ b/crates/openhuman-core/src/sandbox/native_jail_tests.rs
@@ -194,6 +194,22 @@ fn a_workspace_inside_a_credential_store_is_refused() {
assert!(!err.contains(home.path().to_str().unwrap()), "{err}");
}
+#[test]
+fn a_workspace_not_yet_created_inside_a_credential_store_is_refused() {
+ let home = home_with(&[".aws/"]);
+
+ // The workspace folder doesn't exist yet; it still lands inside `~/.aws`.
+ let err = credential_denials(
+ crate::security::policy::home_credential_stores(home.path()),
+ &home.path().join(".aws/new-project"),
+ &[],
+ )
+ .unwrap_err()
+ .to_string();
+
+ assert!(err.contains("`.aws`"), "{err}");
+}
+
#[test]
fn a_writable_grant_inside_a_credential_store_is_refused() {
let home = home_with(&[".kube/"]);