File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " tauri " : " patch:sec"
3+ " tauri-utils " : " patch:sec"
4+ ---
5+
6+ Explicitly check that the main frame's origin is the sender of Isolation Payloads
Original file line number Diff line number Diff line change 1717 window . parent . postMessage ( message , '*' )
1818 }
1919
20+ /**
21+ * @type {string } - The main frame origin.
22+ */
23+ const origin = __TEMPLATE_origin__
24+
2025 /**
2126 * @type {Uint8Array } - Injected by Tauri during runtime
2227 */
4247 algorithm . name = 'AES-GCM'
4348 algorithm . iv = window . crypto . getRandomValues ( new Uint8Array ( 12 ) )
4449
45- const { contentType, data } = __RAW_process_ipc_message_fn__ ( payload )
50+ const { contentType, data} = __RAW_process_ipc_message_fn__ ( payload )
4651
4752 const message =
4853 typeof data === 'string'
4954 ? new TextEncoder ( ) . encode ( data )
5055 : ArrayBuffer . isView ( data ) || data instanceof ArrayBuffer
51- ? data
52- : new Uint8Array ( data )
56+ ? data
57+ : new Uint8Array ( data )
5358
5459 return window . crypto . subtle
5560 . encrypt ( algorithm , aesGcmKey , message )
101106 * @param {MessageEvent<any> } event
102107 */
103108 async function payloadHandler ( event ) {
104- if ( ! isIsolationPayload ( event . data ) ) {
109+ if ( event . origin !== origin || ! isIsolationPayload ( event . data ) ) {
105110 return
106111 }
107112
Original file line number Diff line number Diff line change @@ -156,6 +156,8 @@ pub struct IsolationJavascriptCodegen {
156156pub struct IsolationJavascriptRuntime < ' a > {
157157 /// The key used on the Rust backend and the Isolation Javascript
158158 pub runtime_aes_gcm_key : & ' a [ u8 ; 32 ] ,
159+ /// The origin the isolation application is expecting messages from.
160+ pub origin : String ,
159161 /// The function that processes the IPC message.
160162 #[ raw]
161163 pub process_ipc_message_fn : & ' a str ,
Original file line number Diff line number Diff line change @@ -336,6 +336,7 @@ impl<R: Runtime> WebviewManager<R> {
336336 schema,
337337 assets. clone ( ) ,
338338 * crypto_keys. aes_gcm ( ) . raw ( ) ,
339+ window_origin,
339340 ) ;
340341 pending. register_uri_scheme_protocol ( schema, move |request, responder| {
341342 protocol ( request, UriSchemeResponder ( responder) )
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ pub fn get<R: Runtime>(
2020 schema : & str ,
2121 assets : Arc < EmbeddedAssets > ,
2222 aes_gcm_key : [ u8 ; 32 ] ,
23+ window_origin : String ,
2324) -> UriSchemeProtocolHandler {
2425 let frame_src = if cfg ! ( any( windows, target_os = "android" ) ) {
2526 format ! ( "http://{schema}.localhost" )
@@ -45,6 +46,7 @@ pub fn get<R: Runtime>(
4546
4647 let template = tauri_utils:: pattern:: isolation:: IsolationJavascriptRuntime {
4748 runtime_aes_gcm_key : & aes_gcm_key,
49+ origin : window_origin. clone ( ) ,
4850 process_ipc_message_fn : PROCESS_IPC_MESSAGE_FN ,
4951 } ;
5052 match template. render ( asset. as_ref ( ) , & Default :: default ( ) ) {
You can’t perform that action at this time.
0 commit comments