[bug] Isolation pattern: the isolation iframe gets an opaque origin, so crypto.subtle is undefined and ALL IPC silently hangs (Windows/WebView2)
Describe the bug
With app.security.pattern.use = "isolation", every invoke() hangs forever on Windows. No
error is thrown, no promise rejects, and nothing is logged on either the JS or the Rust side.
The cause is in crates/tauri/scripts/isolation.js. The isolation iframe is created with
allow-scripts and nothing else:
let iframe = document.createElement('iframe')
iframe.id = '__tauri_isolation__'
iframe.sandbox.add('allow-scripts') // <- no allow-same-origin
iframe.src = __TEMPLATE_isolation_src__
A sandboxed iframe without allow-same-origin is assigned an opaque origin. On Windows (and
Android) the isolation frame is navigated to http://<schema>.localhost
(crates/tauri/src/pattern.rs, format_real_schema), and the resulting frame is not a secure
context, so window.crypto.subtle is undefined.
That breaks the isolation payload script, which needs SubtleCrypto to import the AES-GCM key:
// crates/tauri-utils/src/pattern/isolation.js
const aesGcmKey = await window.crypto.subtle.importKey(
'raw', aesGcmKeyRaw, 'AES-GCM', false, ['encrypt']
)
Why it fails silently — this is the part that makes it expensive to debug
Three things compound:
crates/tauri-utils/src/pattern/isolation.jsis an async IIFE with notry/catch. TheimportKeyabove rejects, the IIFE's promise rejects as an unhandled rejection inside a sandboxed iframe, and thesetTimeout(waitUntilReady, readyIntervalMs)at the bottom of the file is never reached — so__TAURI_ISOLATION_READY__is never posted to the parent.- In
crates/tauri/scripts/ipc.js, thecase 'isolation'branch doesif (isolation.ready) sendIsolationMessage(message) else isolation.queue.push(message), andisolation.readyis only ever set by the__TAURI_ISOLATION_READY__listener. Soisolation.queuegrows without bound and is never flushed. - Therefore every
invoke()promise is pending forever. There is nothing tocatch, no Rust log line (nothing reaches Rust), and no error boundary fires. Only a timeout can observe it.
Downstream this presents as unrelated-looking failures: OAuth never starts (shell:open is IPC),
the SQL plugin never creates its database, keychain commands never return — all one root cause.
Reproduction
Minimal, no Tauri required
This isolates the web-platform mechanism. Serve two files over plain http and open parent.html:
<!-- parent.html -->
<script>
const i = document.createElement('iframe')
i.sandbox.add('allow-scripts') // flip: also add 'allow-same-origin'
i.src = 'http://localhost:8791/child.html'
document.body.appendChild(i)
</script>
<!-- child.html -->
<script>
parent.postMessage({
origin: location.origin, // "null" == opaque
isSecureContext: window.isSecureContext,
subtle: typeof (window.crypto && window.crypto.subtle)
}, '*')
</script>
With allow-scripts only the child reports an opaque origin; adding allow-same-origin gives it
its real origin, isSecureContext: true and a working crypto.subtle.
In Tauri
tauri.conf.json→"app": { "security": { "pattern": { "use": "isolation" } } }.- Build and run a release build on Windows.
- Launch with
WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--remote-debugging-port=9222, attach over CDP, and readisSecureContext+typeof crypto.subtleper frame. - Call any
invoke()from the frontend — the promise never settles.
Measured
| Frame | Origin | isSecureContext |
crypto.subtle |
|---|---|---|---|
| main | http://tauri.localhost |
true |
object |
| isolation | http://isolation-<uuid>.localhost |
false |
undefined |
…with a live pageerror from the isolation frame:
TypeError: Cannot read properties of undefined (reading 'importKey').
Expected behavior
The isolation frame should be a secure context so its AES-GCM key bootstrap succeeds and IPC works;
failing that, the key bootstrap should fail loudly rather than leaving every invoke() pending.
Platform
- OS: Windows 10 Pro 19045, WebView2
tauri: 2.11.6 (line is identical in 2.11.5 and unchanged ondev)- Pattern:
isolation - macOS/Linux are not affected:
format_real_schemagives those platforms a Tauri-registered custom scheme (<schema>://localhost) rather thanhttp://<schema>.localhost.
Related
- #10956 — "Refused to execute inline script in isolation mode", Windows/WebView2, open since
2024-09-11,
status: needs triage. A second Windows-specific isolation defect. tauri-apps/wry#1710 / #1709 — the same bug class already accepted for Android: Android WebView excludeshttp://tauri.localhostfrom secure contexts, blocking secure-context APIs.
Suggested fix
Add allow-same-origin to the isolation iframe's sandbox (PR below). The frame keeps a different
origin from the main frame (<schema>.localhost vs tauri.localhost), so the two remain
cross-origin and postMessage stays the only channel.
Two secondary issues worth fixing alongside
- The payload script has no error handling. Wrapping the IIFE in
try/catchand posting a failure message to the parent would have turned this from a silent hang into a one-line diagnosis. Worth doing independently of the sandbox fix. frame-srcis never widened for the isolation origin. For the main document,crates/tauri/src/manager/mod.rspushes the isolation origin intodefault-srconly. An app whose configured CSP sets an explicitframe-src(e.g.frame-src 'none', which is otherwise good hygiene) will have the isolation iframe blocked outright, because an explicitframe-srcsuppresses thedefault-srcfallback. Either inject intoframe-srcas well, or document thatframe-srcmust not be set when using the isolation pattern.
I tried this on Windows 11 and couldn't reproduce the hang.
Setup: Windows 11 build 26300, WebView2 157.0.4341.46, tauri dev at c42354b (the core crates are identical to the 2.12.6 release), examples/isolation built with cargo build --example isolation --features isolation, both debug and --release. I attached over CDP (WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--remote-debugging-port=...) and read the values in each frame:
| frame | self.origin |
isSecureContext |
typeof crypto.subtle |
|---|---|---|---|
main (http://tauri.localhost) |
http://tauri.localhost |
true |
object |
isolation iframe (sandbox="allow-scripts") |
null |
true |
object |
So the iframe does get an opaque origin, but here it is still a secure context, __TAURI_ISOLATION_READY__ arrives, and invoke("ping") resolves.
When I force crypto.subtle to be undefined inside the isolation iframe (injected over CDP before the document runs), I get the failure mode described above: the iframe throws, the ready message never arrives, and invoke stays pending with nothing on the Rust side.
Output with crypto.subtle forced to undefined
Injected into the isolation iframe:
Object.defineProperty(Crypto.prototype, 'subtle', { get() { return undefined } })
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'importKey')
at http://isolation-b4a40420-d40f-4a09-b4f8-b158a088e9af.localhost/:33:48
at http://isolation-b4a40420-d40f-4a09-b4f8-b158a088e9af.localhost/:198:3
...
invoke("ping"): still pending after 5000 ms
So the part that differs is whether the opaque-origin iframe counts as a secure context in your environment. @asmarmomand could you post the full tauri info output (mainly the WebView2 version), and check whether examples/isolation from this repo hangs for you as well?