From e183f58af1b661087f2b37748a4fb351a4c3e39b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 29 Jul 2026 00:05:53 +0000 Subject: [PATCH] Harden path sanitization in safe_name Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- src-tauri/src/main.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 6c3968f..00d88da 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -35,7 +35,18 @@ fn docs_dir(app: &AppHandle, dir: &Option) -> PathBuf { } fn safe_name(name: &str) -> bool { - !name.is_empty() && !name.contains(['/', '\\', ':']) && !name.contains("..") + let path = Path::new(name); + let mut components = path.components(); + match components.next() { + Some(std::path::Component::Normal(_)) => { + if components.next().is_none() { + !name.contains(['/', '\\', ':']) + } else { + false + } + } + _ => false, + } } #[tauri::command]