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>
This commit is contained in:
google-labs-jules[bot] 2026-07-08 12:11:12 +00:00
parent 21f7726316
commit db41305370

View file

@ -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<bool, String> {
async fn save_text_file_dialog(
app: tauri::AppHandle,
contents: String,
is_sum: bool,
) -> Result<bool, String> {
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<bool, String> {
use tauri_plugin_dialog::DialogExt;
async fn save_image_file_dialog(
app: tauri::AppHandle,
data_base64: String,
) -> Result<bool, String> {
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");