Skip to content

Commit 426d14b

Browse files
authored
check the main frame's origin in isolation.js (#10423)
* check the main frame's origin in isolation.js * add changefile * correct changefile tag * use strict origin checking
1 parent 8702931 commit 426d14b

5 files changed

Lines changed: 20 additions & 4 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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

‎core/tauri-utils/src/pattern/isolation.js‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
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
*/
@@ -42,14 +47,14 @@
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)
@@ -101,7 +106,7 @@
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

‎core/tauri-utils/src/pattern/isolation.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ pub struct IsolationJavascriptCodegen {
156156
pub 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,

‎core/tauri/src/manager/webview.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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))

‎core/tauri/src/protocol/isolation.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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()) {

0 commit comments

Comments
 (0)