From db4130537005542ca004110ca428598b3d757b5d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 8 Jul 2026 12:11:12 +0000 Subject: [PATCH] fix: replace write_text_file with backend dialog Replaces `write_text_file` and `write_image_file` with backend commands `save_text_file_dialog` and `save_image_file_dialog`. Instead of allowing the frontend to pass an arbitrary absolute path, the Tauri backend now invokes the OS save dialog directly, eliminating the risk of arbitrary file write if the frontend is compromised. Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com> --- src-tauri/src/main.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index d57ce83..a5cb21c 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -38,7 +38,11 @@ fn safe_name(name: &str) -> bool { } #[tauri::command] -async fn save_text_file_dialog(app: tauri::AppHandle, contents: String, is_sum: bool) -> Result { +async fn save_text_file_dialog( + app: tauri::AppHandle, + contents: String, + is_sum: bool, +) -> Result { use tauri_plugin_dialog::DialogExt; let dialog = app.dialog().file(); let dialog = if is_sum { @@ -57,11 +61,19 @@ async fn save_text_file_dialog(app: tauri::AppHandle, contents: String, is_sum: } #[tauri::command] -async fn save_image_file_dialog(app: tauri::AppHandle, data_base64: String) -> Result { - use tauri_plugin_dialog::DialogExt; +async fn save_image_file_dialog( + app: tauri::AppHandle, + data_base64: String, +) -> Result { use std::io::Write; + use tauri_plugin_dialog::DialogExt; - if let Some(path) = app.dialog().file().add_filter("PNG Image", &["png"]).blocking_save_file() { + if let Some(path) = app + .dialog() + .file() + .add_filter("PNG Image", &["png"]) + .blocking_save_file() + { let path = path.into_path().map_err(|_| "invalid path".to_string())?; let bytes = base64_decode(&data_base64)?; let tmp = path.with_extension("tmp");