Skip to content

Native host: wasmtime producers behind a Tauri webview receiver - #16

Merged
lannbot merged 1 commit into
mainfrom
tauri-wasmtime-host
Sep 6, 2026
Merged

Native host: wasmtime producers behind a Tauri webview receiver#16
lannbot merged 1 commit into
mainfrom
tauri-wasmtime-host

Conversation

@lannbot

@lannbot lannbot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Summary

A fourth transport: producers run in wasmtime in a native process, the receiver runs in a Tauri webview, and the two meet over IPC. Semantically it is the worker tier (option C events only, no imperative preventDefault), plus what a wasm sandbox adds: per-producer memory and CPU limits and a host-chosen WASI capability surface. Producers are treated as untrusted; the webview is the privileged principal, so this PR also ships the receiver's first concrete policy.

  • host/stream-dom-host — wasmtime 47 host (component-model async, StoreLimits, epoch yielding, WASI with no preopens/sockets). One actor per producer owns the store; handle-event calls are serialized. The mutation stream is piped into an ack-gated StreamConsumer: each guest write completes only after HostBridge::apply resolves, so queries observe every committed batch holds structurally with no receiver-side buffering. Headless integration test drives the Dioxus TodoMVC component: wire shape, ack gating (mutation-tested), an event round trip, shutdown, and a too-small memory cap failing loudly.
  • host/desktop — Tauri 2 app. Pull with implicit ack: read_chunk returns raw bytes and the next read_chunk acks the previous one; events are one invoke with the payload as raw body; queries ride a Channel. Strict CSP, explicit command capabilities, on_navigation refuses everything off-origin. WebDriver smoke test (tauri-driver + WebKitWebDriver under Xvfb) mounts TodoMVC, adds and completes a todo, and reports IPC latency (~60–100 ms per read round trip vs single-digit ms DOM apply).
  • ReceiverdesktopPolicy(): allowlists (not denylists) for tags, attributes, properties, event names; URL-kind attributes take asset values only, with relativeHref/externalLinks opt-ins judged by URL parsing; maxNodes/maxListeners/maxStringBytes budgets; bindMarker denied. createDriver({ defaultPreventDefault }) installs root capture listeners cancelling unlistened submits and off-page link clicks (hash routes still work). In-page mount unchanged (just e2e green).
  • Design record — native-host transports column, "Trust inversion" and "What a policy cannot see" under Policy, native-host Spike paragraph, open questions 1 and 10 updated.

Independent review round on the policy applied (parser-based same-origin check, DOM-clobbering name, invoker/formtarget attributes, passive-listener and no-listener default-action gaps).

Gates

just check, just test (host: 5, receiver: 134), just e2e, just desktop-smoke — all green locally. CI gains the webkit2gtk dev libs, webkit2gtk-driver, Xvfb and tauri-driver (binstall) for the desktop crate and its smoke test.

Automerge is armed (merge commit).

host/stream-dom-host runs producers on wasmtime 47 with per-store memory
and epoch limits and an empty WASI context; each guest write is forwarded
to a HostBridge and completes only when the receiver acks it, so "queries
observe every committed batch" holds on this tier with no buffering.
host/desktop is a Tauri 2 app whose webview runs the existing receiver
driver over IPC (pull with implicit ack), under a strict CSP and a
navigation refusal; a WebDriver smoke test drives TodoMVC under Xvfb.

Receiver: desktopPolicy(), the first concrete embedder policy — allowlists
for tags, attributes, properties and event names, asset-only URL attributes
with parsed (not prefix-matched) relative/external href opt-ins, and node,
listener and string budgets. createDriver gains defaultPreventDefault,
which cancels unlistened submits and off-page link clicks at the mount
root. Design record: native-host transports column, trust inversion, what
a policy cannot see.
@lannbot
lannbot merged commit ebf45ab into main Sep 6, 2026
1 check failed
@lannbot
lannbot deleted the tauri-wasmtime-host branch September 6, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants