Skip to content

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

fix(sandbox): judge module grants as the OS resolves them

M3gA-Mindee8549975bb2
diff --git a/crates/openhuman-core/src/sandbox/local_grants.rs b/crates/openhuman-core/src/sandbox/local_grants.rs
index fbaf112c01..1f23229220 100644
--- a/crates/openhuman-core/src/sandbox/local_grants.rs
+++ b/crates/openhuman-core/src/sandbox/local_grants.rs
@@ -129,6 +129,8 @@ pub(crate) fn grant_request(
/// Second gate: drop every returned path the host floor forbids, and every
/// path that contains one of the operator's credential stores (a grant of
/// `$HOME` or `/` reaches `~/.ssh`, and Landlock cannot carve it back out).
+/// A path is judged as the OS resolves it: one with `.`/`..` segments or a
+/// rootless one is refused outright, and a symlink is checked at its target.
/// `/proc` is the one sanctioned exception to the floor, and only when
/// `allow_proc` is set.
#[cfg(feature = "modules")]
@@ -136,21 +138,56 @@ pub(crate) fn admit_module_grants(
reply: crate::modules::tinybox::contract::LocalGrants,
allow_proc: bool,
) -> JailGrants {
- let stores = grant_home(crate::core::runtime::is_saas(), dirs::home_dir)
- .as_deref()
- .map(crate::security::policy::home_credential_stores)
- .unwrap_or_default();
+ let home = grant_home(crate::core::runtime::is_saas(), dirs::home_dir);
+ admit_grants_under(reply, allow_proc, home.as_deref())
+}
+
+#[cfg(feature = "modules")]
+fn admit_grants_under(
+ reply: crate::modules::tinybox::contract::LocalGrants,
+ allow_proc: bool,
+ home: Option<&std::path::Path>,
+) -> JailGrants {
+ use std::path::Component;
+ let mut stores = Vec::new();
+ if let Some(home) = home {
+ stores.extend(crate::security::policy::home_credential_stores(home));
+ if let Ok(resolved) = home.canonicalize() {
+ stores.extend(crate::security::policy::home_credential_stores(&resolved));
+ }
+ }
let admit = |raw: String| -> Option<PathBuf> {
let path = PathBuf::from(raw);
+ let lexical = path.has_root()
+ && path.components().all(|c| {
+ matches!(
+ c,
+ Component::Prefix(_) | Component::RootDir | Component::Normal(_)
+ )
+ });
+ if !lexical {
+ tracing::warn!(
+ path = %path.display(),
+ "[sandbox:grants] refused module grant: not a plain absolute path"
+ );
+ return None;
+ }
+ let resolved = path.canonicalize().unwrap_or_else(|_| path.clone());
let sanctioned_proc = allow_proc && path == std::path::Path::new("/proc");
- if !sanctioned_proc && SecurityPolicy::is_always_forbidden(&path) {
+ if !sanctioned_proc
+ && (SecurityPolicy::is_always_forbidden(&path)
+ || SecurityPolicy::is_always_forbidden(&resolved))
+ {
tracing::warn!(
path = %path.display(),
"[sandbox:grants] refused module grant: host floor forbids it"
);
return None;
}
- if stores.iter().any(|store| store.starts_with(&path)) {
+ if stores
+ .iter()
+ .any(|store| store.starts_with(&path) || store.starts_with(&resolved))
+ {
tracing::warn!(
path = %path.display(),
"[sandbox:grants] refused module grant: it contains a credential store"
diff --git a/crates/openhuman-core/src/sandbox/local_grants_tests.rs b/crates/openhuman-core/src/sandbox/local_grants_tests.rs
index ca05598aae..b7def66c5d 100644
--- a/crates/openhuman-core/src/sandbox/local_grants_tests.rs
+++ b/crates/openhuman-core/src/sandbox/local_grants_tests.rs
@@ -43,17 +43,31 @@ mod with_module {
#[test]
fn a_grant_containing_a_credential_store_is_refused() {
- let home = dirs::home_dir().expect("a home directory");
+ // A synthetic home under a temp dir: the process home can sit under a
+ // floor-forbidden root (`/root`), which would refuse every grant.
+ let tmp = tempfile::tempdir().expect("tempdir");
+ let home = tmp.path().join("home");
let project = home.join("project");
+ std::fs::create_dir_all(&project).expect("project dir");
+ let mut read_only = vec![
+ home.display().to_string(),
+ "/".into(),
+ project.display().to_string(),
+ // Resolves to `home`; a lexical check alone would admit it.
+ format!("{}/..", project.display()),
+ "relative/project".into(),
+ ];
+ #[cfg(unix)]
+ {
+ let link = tmp.path().join("link-to-home");
+ std::os::unix::fs::symlink(&home, &link).expect("symlink");
+ read_only.push(link.display().to_string());
+ }
let reply = LocalGrants {
- read_only: vec![
- home.display().to_string(),
- "/".into(),
- project.display().to_string(),
- ],
+ read_only,
read_write: vec![home.display().to_string()],
};
- let grants = admit_module_grants(reply, false);
+ let grants = admit_grants_under(reply, false, Some(&home));
assert_eq!(grants.read_only, [project]);
assert!(grants.read_write.is_empty(), "{:?}", grants.read_write);
}