@@ -19,6 +19,7 @@ use super::{CallbackFn, InvokeBody, InvokeResponse};
1919
2020const TAURI_CALLBACK_HEADER_NAME : & str = "Tauri-Callback" ;
2121const TAURI_ERROR_HEADER_NAME : & str = "Tauri-Error" ;
22+ const TAURI_INVOKE_KEY_HEADER_NAME : & str = "Tauri-Invoke-Key" ;
2223
2324pub fn message_handler < R : Runtime > (
2425 manager : Arc < AppManager < R > > ,
@@ -210,6 +211,8 @@ fn handle_ipc_message<R: Runtime>(request: Request<String>, manager: &AppManager
210211 error : CallbackFn ,
211212 payload : serde_json:: Value ,
212213 options : Option < RequestOptions > ,
214+ #[ serde( rename = "__TAURI_INVOKE_KEY__" ) ]
215+ invoke_key : String ,
213216 }
214217
215218 #[ allow( unused_mut) ]
@@ -224,6 +227,8 @@ fn handle_ipc_message<R: Runtime>(request: Request<String>, manager: &AppManager
224227 error : CallbackFn ,
225228 payload : crate :: utils:: pattern:: isolation:: RawIsolationPayload < ' a > ,
226229 options : Option < RequestOptions > ,
230+ #[ serde( rename = "__TAURI_INVOKE_KEY__" ) ]
231+ invoke_key : String ,
227232 }
228233
229234 if let crate :: Pattern :: Isolation { crypto_keys, .. } = & * manager. pattern {
@@ -240,6 +245,7 @@ fn handle_ipc_message<R: Runtime>(request: Request<String>, manager: &AppManager
240245 error : message. error ,
241246 payload : serde_json:: from_slice ( & crypto_keys. decrypt ( message. payload ) ?) ?,
242247 options : message. options ,
248+ invoke_key : message. invoke_key ,
243249 } )
244250 } ) ,
245251 ) ;
@@ -261,6 +267,7 @@ fn handle_ipc_message<R: Runtime>(request: Request<String>, manager: &AppManager
261267 url : Url :: parse ( & request. uri ( ) . to_string ( ) ) . expect ( "invalid IPC request URL" ) ,
262268 body : message. payload . into ( ) ,
263269 headers : message. options . map ( |o| o. headers . 0 ) . unwrap_or_default ( ) ,
270+ invoke_key : message. invoke_key ,
264271 } ;
265272
266273 #[ cfg( feature = "tracing" ) ]
@@ -394,6 +401,14 @@ fn parse_invoke_request<R: Runtime>(
394401 }
395402 }
396403
404+ let invoke_key = parts
405+ . headers
406+ . get ( TAURI_INVOKE_KEY_HEADER_NAME )
407+ . ok_or ( "missing Tauri-Invoke-Key header" ) ?
408+ . to_str ( )
409+ . map_err ( |_| "Tauri invoke key header value must be a string" ) ?
410+ . to_owned ( ) ;
411+
397412 let url = Url :: parse (
398413 parts
399414 . headers
@@ -461,6 +476,7 @@ fn parse_invoke_request<R: Runtime>(
461476 url,
462477 body,
463478 headers : parts. headers ,
479+ invoke_key,
464480 } ;
465481
466482 Ok ( payload)
0 commit comments