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
chore: files changed crates/openhuman-core/src/inference/host_runtime/service/speech.rs,crates/openh
Steven Enamakel545b4109cd19
diff --git a/crates/openhuman-core/src/inference/host_runtime/service/speech.rs b/crates/openhuman-core/src/inference/host_runtime/service/speech.rsindex 5b03c34027..fbdf8117ac 100644--- a/crates/openhuman-core/src/inference/host_runtime/service/speech.rs+++ b/crates/openhuman-core/src/inference/host_runtime/service/speech.rs@@ -100,30 +100,29 @@ pub async fn tts(if !config.local_ai.runtime_enabled {return Err("local ai is disabled".to_string());}+ if text.trim().is_empty() {+ return Err("TTS text is required".to_string());+ }let runtime = crate::inference::local_runtime_config(config);+ let out_path = validated_tts_output_path(config, &runtime, output_path).await?;let piper_bin = tinyinference_local::service::paths::resolve_piper_binary_with_config(&runtime).ok_or_else(|| "piper binary not found. Set PIPER_BIN or install piper.".to_string())?;let model_path = tinyinference_local::service::paths::resolve_tts_voice_path(&runtime)?;- let out_path = output_path- .map(std::string::ToString::to_string)- .unwrap_or_else(|| {- tinyinference_local::service::paths::config_root_dir(&runtime)- .join("models")- .join("local-ai")- .join("tts-output.wav")- .display()- .to_string()- });- let parent = PathBuf::from(&out_path)+ let parent = out_path.parent()- .map(PathBuf::from)+ .map(std::path::Path::to_path_buf).ok_or_else(|| "invalid output_path".to_string())?;tokio::fs::create_dir_all(parent).await.map_err(|e| format!("failed to create TTS output directory: {e}"))?;let mut child = tokio::process::Command::new(piper_bin)- .args(["--model", &model_path, "--output_file", &out_path])+ .args([+ "--model",+ &model_path,+ "--output_file",+ &out_path.display().to_string(),+ ]).stdin(std::process::Stdio::piped()).stdout(std::process::Stdio::null()).stderr(std::process::Stdio::piped())@@ -149,11 +148,76 @@ pub async fn tts(}service.mark_tts_ready();Ok(LocalAiTtsResult {- output_path: out_path,+ output_path: out_path.display().to_string(),voice_id: model_ids::effective_tts_voice_id(config),})}+async fn validated_tts_output_path(+ config: &Config,+ runtime: &tinyinference_local::service::RuntimeConfig,+ requested_path: Option<&str>,+) -> Result<PathBuf, String> {+ let model_root = tinyinference_local::service::paths::config_root_dir(runtime)+ .join("models")+ .join("local-ai");+ if requested_path.is_some_and(|path| path.trim().is_empty()) {+ return Err("invalid output_path".to_string());+ }+ let requested = requested_path+ .map(PathBuf::from)+ .unwrap_or_else(|| model_root.join("tts-output.wav"));+ if requested.as_os_str().is_empty() {+ return Err("invalid output_path".to_string());+ }+ let candidate = if requested.is_absolute() {+ requested+ } else {+ config.workspace_dir.join(requested)+ };+ let candidate_string = candidate+ .to_str()+ .ok_or_else(|| "invalid output_path".to_string())?;+ let 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}"))?;++ for root in [&config.workspace_dir, &model_root] {+ let resolved_root = canonicalize_path_with_missing_suffix(root).await?;+ if resolved.starts_with(&resolved_root) {+ return Ok(resolved);+ }+ }+ Err("invalid output_path: path must be inside the workspace or local-ai models directory".into())+}++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 a3cfe86b75..1e5779535f 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@@ -39,3 +39,86 @@ async fn tts_rejects_output_outside_allowed_roots() {assert!(error.contains("output_path"), "unexpected error: {error}");assert!(!output.parent().unwrap().exists());}++#[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 runtime = crate::inference::local_runtime_config(&config);+ let model_root = tinyinference_local::service::paths::config_root_dir(&runtime)+ .join("models")+ .join("local-ai");++ for output in [+ config.workspace_dir.join("speech.wav"),+ model_root.join("speech.wav"),+ ] {+ let resolved = validated_tts_output_path(+ &config,+ &runtime,+ Some(output.to_str().unwrap()),+ )+ .await+ .unwrap();+ assert!(resolved.ends_with("speech.wav"));+ }+}++#[tokio::test]+async fn tts_output_path_rejects_traversal() {+ let tmp = tempfile::tempdir().unwrap();+ let config = enabled_config(&tmp);+ let runtime = crate::inference::local_runtime_config(&config);+ let traversal = config.workspace_dir.join("../outside/speech.wav");++ let error = validated_tts_output_path(+ &config,+ &runtime,+ Some(traversal.to_str().unwrap()),+ )+ .await+ .unwrap_err();++ assert!(error.contains("output_path"));+}++#[cfg(unix)]+#[tokio::test]+async fn tts_output_path_rejects_symlink_escape() {+ let tmp = tempfile::tempdir().unwrap();+ let config = enabled_config(&tmp);+ let runtime = crate::inference::local_runtime_config(&config);+ let outside = tmp.path().join("outside");+ std::fs::create_dir_all(&outside).unwrap();+ let link = config.workspace_dir.join("linked");+ std::os::unix::fs::symlink(&outside, &link).unwrap();+ let output = link.join("speech.wav");++ let error = validated_tts_output_path(+ &config,+ &runtime,+ Some(output.to_str().unwrap()),+ )+ .await+ .unwrap_err();++ assert!(error.contains("output_path"));+}++#[cfg(unix)]+#[tokio::test]+async fn tts_output_path_keeps_always_forbidden_paths_blocked() {+ let tmp = tempfile::tempdir().unwrap();+ let config = enabled_config(&tmp);+ let runtime = crate::inference::local_runtime_config(&config);++ let error = validated_tts_output_path(+ &config,+ &runtime,+ Some("/etc/openhuman-tts-test.wav"),+ )+ .await+ .unwrap_err();++ assert!(error.contains("output_path"));+}