Tauri plugin

Security

Reserved ids, read-only clients, the URL allow-list, refused headers and webview isolation.

Reserve Rust's ids

Rust usually registers its clients after an await (the connect). Until then any page script with allow-connect could connect under the same id, and Rust's insert would fail with AlreadyExists while get(id) returned the page's client. Call reserve(id) in setup, synchronously:

.setup(|app| {
    app.socketio().reserve("core");
    Ok(())
})

Read-only clients

Register clients the webview must not drive with Access::ReadOnly: emit, emitWithAck, ack and disconnect are refused from every webview with AccessDenied, whatever the capabilities allow. See Rust API.

URL allow-list

The sockets run in Rust, so the webview's CSP (connect-src) does not limit them: with allow-connect a page can reach any host with any headers. Restrict it:

.plugin(
    tauri_plugin_socketio::Builder::new()
        .allow_url_prefix("https://api.example.com")       // scheme + host + port
        .allow_url_prefix("wss://rt.example.com/v1/")      // ... and a path prefix
        .build(),
)

What is enforced: the scheme, the host, the port, and the engine.io path (the path option, default /socket.io/) under the prefix's path on a / boundary. The URL's own path is the namespace and is not part of the check, nor is the namespace option. Query and headers changed later (setQuery, setHeaders) and reconnect cannot move the target. A refused URL rejects with UrlNotAllowed.

Without allow_url_prefix every URL is allowed (init()). Rust's connect / insert are never restricted.

Headers

Headers from the webview are limited: Host, Connection, Upgrade, Content-Length, Transfer-Encoding, Cookie (cookies come from the jar), Sec-WebSocket-* and Proxy-* are refused with InvalidOptions naming the header, in the connect options and in setHeaders. Rust's clients are not limited.

TLS

The ca option adds trusted certificates for a private CA; there is no option to turn certificate checks off.

Webview isolation

unsubscribe and ack act only on the calling webview's subscriptions and on acks offered to it (UnknownAck otherwise). A webview has at most MAX_SUBSCRIPTIONS_PER_WEBVIEW (64) subscriptions (TooManySubscriptions) and, per client, at most MAX_PENDING_ACKS_PER_WEBVIEW (256) unanswered server acks; past that its own oldest ack is forgotten, never another webview's.

Least privilege

Grant socketio:allow-read instead of socketio:default to windows that only observe.