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(inference): reject symlinked TTS output paths
Steven Enamakela376130961f4
diff --git a/crates/openhuman-core/src/inference/host_runtime/service/speech.rs b/crates/openhuman-core/src/inference/host_runtime/service/speech.rsindex 22f738b844..a8b5a25554 100644--- a/crates/openhuman-core/src/inference/host_runtime/service/speech.rs+++ b/crates/openhuman-core/src/inference/host_runtime/service/speech.rs@@ -178,18 +178,42 @@ async fn validated_tts_output_path(let candidate_string = candidate.to_str().ok_or_else(|| "invalid output_path".to_string())?;- let policy = crate::security::SecurityPolicy::from_config(+ let mut policy = crate::security::SecurityPolicy::from_config(&config.autonomy,&config.workspace_dir,&config.action_dir,);- let resolved = policy- .validate_parent_path(candidate_string)- .await- .map_err(|error| format!("invalid output_path: {error}"))?;+ policy.trusted_roots.push(crate::security::TrustedRoot {+ path: model_root.display().to_string(),+ access: crate::security::TrustedAccess::ReadWrite,+ });+ let resolved = match tokio::fs::symlink_metadata(&candidate).await {+ Ok(metadata) if metadata.file_type().is_symlink() => {+ return Err("invalid output_path: symbolic links are not allowed".into());+ }+ Ok(_) => policy.validate_path(candidate_string).await,+ Err(error) if error.kind() == std::io::ErrorKind::NotFound => {+ policy.validate_parent_path(candidate_string).await+ }+ Err(error) => Err(format!("could not inspect output_path: {error}")),+ }+ .map_err(|error| format!("invalid output_path: {error}"))?;for root in [&config.workspace_dir, &model_root] {- let resolved_root = canonicalize_path_with_missing_suffix(root).await?;+ let root_probe = root.join(".openhuman-tts-root-check");+ let root_probe_string = root_probe+ .to_str()+ .ok_or_else(|| "could not resolve allowed TTS path root".to_string())?;+ let resolved_probe = policy+ .validate_parent_path(root_probe_string)+ .await+ .map_err(|error| format!("could not resolve allowed TTS path root: {error}"))?;+ let resolved_root = resolved_probe.parent().ok_or_else(|| {+ format!(+ "could not resolve allowed TTS path root: {}",+ root.display()+ )+ })?;if resolved.starts_with(&resolved_root) {return Ok(resolved);}@@ -200,33 +224,6 @@ async fn validated_tts_output_path()}-async fn canonicalize_path_with_missing_suffix(path: &std::path::Path) -> Result<PathBuf, String> {- let mut ancestor = path;- let mut missing = Vec::new();- while tokio::fs::metadata(ancestor).await.is_err() {- let name = ancestor.file_name().ok_or_else(|| {- format!(- "could not resolve allowed TTS path root: {}",- path.display()- )- })?;- missing.push(name.to_os_string());- ancestor = ancestor.parent().ok_or_else(|| {- format!(- "could not resolve allowed TTS path root: {}",- path.display()- )- })?;- }- let mut resolved = tokio::fs::canonicalize(ancestor)- .await- .map_err(|error| format!("could not resolve allowed TTS path root: {error}"))?;- for component in missing.iter().rev() {- resolved.push(component);- }- Ok(resolved)-}-#[cfg(test)]#[path = "speech_tests.rs"]mod tests;diff --git a/crates/openhuman-core/src/inference/host_runtime/service/speech_tests.rs b/crates/openhuman-core/src/inference/host_runtime/service/speech_tests.rsindex 63c72ae017..587a36620f 100644--- a/crates/openhuman-core/src/inference/host_runtime/service/speech_tests.rs+++ b/crates/openhuman-core/src/inference/host_runtime/service/speech_tests.rs@@ -41,7 +41,9 @@ async fn tts_rejects_output_outside_allowed_roots() {#[tokio::test]async fn tts_output_path_allows_workspace_and_local_ai_models_roots() {let tmp = tempfile::tempdir().unwrap();- let config = enabled_config(&tmp);+ let mut config = enabled_config(&tmp);+ config.autonomy.enabled = true;+ config.autonomy.workspace_only = true;let runtime = crate::inference::local_runtime_config(&config);let model_root = tinyinference_local::service::paths::config_root_dir(&runtime).join("models")@@ -91,6 +93,28 @@ async fn tts_output_path_rejects_symlink_escape() {assert!(error.contains("output_path"));}+#[cfg(unix)]+#[tokio::test]+async fn tts_output_path_rejects_final_component_symlink() {+ let tmp = tempfile::tempdir().unwrap();+ let config = enabled_config(&tmp);+ let runtime = crate::inference::local_runtime_config(&config);+ let outside_file = tmp.path().join("outside.wav");+ std::fs::write(&outside_file, b"outside target").unwrap();+ let output = config.workspace_dir.join("speech.wav");+ std::os::unix::fs::symlink(&outside_file, &output).unwrap();++ let error = validated_tts_output_path(&config, &runtime, Some(output.to_str().unwrap()))+ .await+ .unwrap_err();++ assert!(+ error.contains("symbolic links"),+ "unexpected error: {error}"+ );+ assert_eq!(std::fs::read(outside_file).unwrap(), b"outside target");+}+#[cfg(unix)]#[tokio::test]async fn tts_output_path_keeps_always_forbidden_paths_blocked() {