Harden path sanitization in safe_name

Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
This commit is contained in:
google-labs-jules[bot] 2026-07-29 00:05:53 +00:00
parent f5b1fc038b
commit e183f58af1

View file

@ -35,7 +35,18 @@ fn docs_dir(app: &AppHandle, dir: &Option<String>) -> 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]