@@ -300,9 +300,15 @@ pub async fn upload_media(
300300
301301/// Read a picked path through the TOCTOU-safe pipeline (fd pin → sniff →
302302/// transcode-or-passthrough → MIME validation → upload).
303+ ///
304+ /// When `images_only` is set, the file is rejected **before upload** if it is
305+ /// not an image (videos and non-image files error out; HEIC/HEIF still
306+ /// transcode to JPEG, which is an image). This keeps discarded/non-image
307+ /// files from ever leaving the client on image-only surfaces.
303308async fn process_picked_path (
304309 path : std:: path:: PathBuf ,
305310 state : & State < ' _ , AppState > ,
311+ images_only : bool ,
306312) -> Result < BlobDescriptor , String > {
307313 // Pin the inode by opening the fd BEFORE spawn_blocking. This prevents a
308314 // local attacker from swapping the file between dialog return and read.
@@ -325,6 +331,9 @@ async fn process_picked_path(
325331 let n = file. read ( & mut header) . map_err ( |e| e. to_string ( ) ) ?;
326332
327333 if is_video_file ( & header[ ..n] ) {
334+ if images_only {
335+ return Err ( "Please choose an image file." . to_string ( ) ) ;
336+ }
328337 // ffmpeg needs a path, not an fd. Resolve the fd's real path
329338 // so we pass the actual inode's location, not the original
330339 // (potentially swapped) pathname. Same pattern as upload_media.
@@ -357,6 +366,12 @@ async fn process_picked_path(
357366
358367 let mime = detect_and_validate_mime ( & body) ?;
359368
369+ // Image-only surfaces (e.g. "Send feedback"): reject anything that didn't
370+ // sniff as an image, BEFORE the upload leaves the client.
371+ if images_only && !mime. starts_with ( "image/" ) {
372+ return Err ( "Please choose an image file." . to_string ( ) ) ;
373+ }
374+
360375 // Upload video first, then poster (best-effort). If poster upload fails,
361376 // the video descriptor is returned without an image field.
362377 let mut descriptor = do_upload ( body, & mime, state, None ) . await ?;
@@ -414,13 +429,51 @@ pub async fn pick_and_upload_media(
414429 let mut descriptors = Vec :: with_capacity ( file_paths. len ( ) ) ;
415430 for file_path in file_paths {
416431 let path = file_path. as_path ( ) . ok_or ( "invalid path" ) ?. to_path_buf ( ) ;
417- let descriptor = process_picked_path ( path, & state) . await ?;
432+ let descriptor = process_picked_path ( path, & state, false ) . await ?;
418433 descriptors. push ( descriptor) ;
419434 }
420435
421436 Ok ( descriptors)
422437}
423438
439+ /// Open a native single-file dialog constrained to images, read the picked
440+ /// file, and upload it — rejecting anything that doesn't sniff as an image
441+ /// **before** the bytes leave the client.
442+ ///
443+ /// This is the secure path for image-only surfaces (e.g. the "Send feedback"
444+ /// attachment). Unlike [`pick_and_upload_media`], the dialog is filtered to
445+ /// common image extensions and `process_picked_path` runs with
446+ /// `images_only = true`, so a user who bypasses the extension filter still
447+ /// can't upload a non-image (videos and other files error out during MIME
448+ /// validation, before `do_upload`). Returns `None` when the user cancels.
449+ #[ tauri:: command]
450+ pub async fn pick_and_upload_image (
451+ app : tauri:: AppHandle ,
452+ state : State < ' _ , AppState > ,
453+ ) -> Result < Option < BlobDescriptor > , String > {
454+ use tauri_plugin_dialog:: DialogExt ;
455+
456+ let ( tx, rx) = tokio:: sync:: oneshot:: channel ( ) ;
457+ app. dialog ( )
458+ . file ( )
459+ . add_filter (
460+ "Images" ,
461+ & [ "png" , "jpg" , "jpeg" , "gif" , "webp" , "heic" , "heif" , "bmp" ] ,
462+ )
463+ . pick_file ( move |path| {
464+ let _ = tx. send ( path) ;
465+ } ) ;
466+
467+ let file_path = match rx. await . map_err ( |_| "dialog cancelled" . to_string ( ) ) ? {
468+ Some ( path) => path,
469+ None => return Ok ( None ) ,
470+ } ;
471+
472+ let path = file_path. as_path ( ) . ok_or ( "invalid path" ) ?. to_path_buf ( ) ;
473+ let descriptor = process_picked_path ( path, & state, true ) . await ?;
474+ Ok ( Some ( descriptor) )
475+ }
476+
424477/// Upload raw bytes directly (for paste and drag-drop).
425478///
426479/// The renderer already has the bytes in memory from the clipboard/drag event.
0 commit comments