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(security): the core RPC token file is always owner-only and never a symlink
M3gA-Mindb551067bb2ee
diff --git a/crates/openhuman-core/src/security/pairing.rs b/crates/openhuman-core/src/security/pairing.rsindex cd2ffb43cb..12d450e4d3 100644--- a/crates/openhuman-core/src/security/pairing.rs+++ b/crates/openhuman-core/src/security/pairing.rs@@ -107,12 +107,17 @@ fn write_core_token_file(path: &Path, token: &str) -> std::io::Result<()> {#[cfg(unix)]{+ use std::os::unix::fs::PermissionsExt as _;+ // `mode` applies only when the file is created, so tighten an existing+ // file too; refuse to follow a symlink planted at the token path.let mut file = std::fs::OpenOptions::new().write(true).create(true).truncate(true).mode(0o600)+ .custom_flags(libc::O_NOFOLLOW).open(path)?;+ file.set_permissions(std::fs::Permissions::from_mode(0o600))?;file.write_all(token.as_bytes())?;}diff --git a/crates/openhuman-core/src/security/pairing_tests.rs b/crates/openhuman-core/src/security/pairing_tests.rsindex e544144c8b..b6ca13ad4e 100644--- a/crates/openhuman-core/src/security/pairing_tests.rs+++ b/crates/openhuman-core/src/security/pairing_tests.rs@@ -69,3 +69,35 @@ async fn public_bind_uses_nonempty_env_token_without_writing_file() {assert!(!tmp.join("core.token").exists());std::fs::remove_dir_all(&tmp).ok();}++/// `mode(0o600)` only applies on create: a token rewritten over an existing+/// world-readable file must still end up owner-only.+#[cfg(unix)]+#[test]+async fn rewriting_the_token_tightens_an_existing_file_to_owner_only() {+ use std::os::unix::fs::PermissionsExt as _;+ let tmp = tempfile::tempdir().unwrap();+ let path = tmp.path().join("core.token");+ std::fs::write(&path, "old").unwrap();+ std::fs::set_permissions(&path, std::fs::Permissions::from_mode(0o644)).unwrap();++ write_core_token_file(&path, "new-token").unwrap();++ let mode = std::fs::metadata(&path).unwrap().permissions().mode() & 0o777;+ assert_eq!(mode, 0o600, "token file left at {mode:o}");+ assert_eq!(std::fs::read_to_string(&path).unwrap(), "new-token");+}++/// A symlink planted at the token path must not redirect the bearer token.+#[cfg(unix)]+#[test]+async fn the_token_is_not_written_through_a_symlink() {+ let tmp = tempfile::tempdir().unwrap();+ let target = tmp.path().join("elsewhere");+ std::fs::write(&target, "untouched").unwrap();+ let path = tmp.path().join("core.token");+ std::os::unix::fs::symlink(&target, &path).unwrap();++ assert!(write_core_token_file(&path, "secret-token").is_err());+ assert_eq!(std::fs::read_to_string(&target).unwrap(), "untouched");+}