From 79de4332b6fe01e848c286cedf9ceea773cf6190 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Mon, 2 Sep 2024 13:12:59 -0300 Subject: [PATCH] fix(core): isolation pattern breaks raw postMessage payload (#10841) --- .changes/fix-isolation-parse-raw-body.md | 5 +++++ crates/tauri/src/ipc/protocol.rs | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 .changes/fix-isolation-parse-raw-body.md diff --git a/.changes/fix-isolation-parse-raw-body.md b/.changes/fix-isolation-parse-raw-body.md new file mode 100644 index 000000000..3dfece32d --- /dev/null +++ b/.changes/fix-isolation-parse-raw-body.md @@ -0,0 +1,5 @@ +--- +"tauri": patch:bug +--- + +Fixes IPC postMessage raw body processing when using the isolation pattern. diff --git a/crates/tauri/src/ipc/protocol.rs b/crates/tauri/src/ipc/protocol.rs index 40b2d0fa4..0348d5015 100644 --- a/crates/tauri/src/ipc/protocol.rs +++ b/crates/tauri/src/ipc/protocol.rs @@ -17,6 +17,7 @@ use http::{ }, HeaderValue, Method, Request, StatusCode, }; +use mime::APPLICATION_OCTET_STREAM; use url::Url; use super::{CallbackFn, InvokeResponse}; @@ -278,11 +279,17 @@ fn handle_ipc_message(request: Request, manager: &AppManager serde_json::from_str::>(request.body()) .map_err(Into::into) .and_then(|message| { + let is_raw = message.payload.content_type() == &APPLICATION_OCTET_STREAM.to_string(); + let payload = crypto_keys.decrypt(message.payload)?; Ok(Message { cmd: message.cmd, callback: message.callback, error: message.error, - payload: serde_json::from_slice(&crypto_keys.decrypt(message.payload)?)?, + payload: if is_raw { + payload.into() + } else { + serde_json::from_slice(&payload)? + }, options: message.options, invoke_key: message.invoke_key, })