Skip to content

fix(desktop): the installed app applies its own style blocks and reaches its native side directly - #281

Merged
Aizen93 merged 1 commit into
developfrom
fix/desktop-policy-inline-styles-and-ipc
Nov 14, 2026
Merged

Aizen93 merged 1 commit into
developfrom
fix/desktop-policy-inline-styles-and-ipc

Conversation

@Aizen93

@Aizen93 Aizen93 commented Nov 14, 2026

Copy link
Copy Markdown
Owner

What was wrong

An installed desktop build ran under a stricter Content Security Policy than tauri.conf.json states, and the policy refused two things the app does itself. Both show in the official build as in a self-hosted one; a browser build and tauri dev are not affected (no policy applies to them).

  • Style blocks the app adds at run time were refused. At build time Tauri adds a nonce to the directives of the pages it serves, and a nonce makes the webview ignore 'unsafe-inline'. The app's own <style> blocks carry no nonce. Measured on the sign-in page: its four blocks (the background's animations, the wrong-password shake) were refused. The same rule covers every other block the app adds this way: the sign-up page, the live voice bars of the spaces strip, the supporter badges and a theme's pattern rules.
  • Tauri's own channel was refused. An installed app calls its Rust side with a request of its own (ipc: on macOS and Linux, http://ipc.localhost on Windows and Android). connect-src named neither, so the first call of every launch was refused and reported as a violation, and every later call went over the slower message channel Tauri falls back to.

What the code does now

  • tauri.conf.json: connect-src names ipc: and http://ipc.localhost, and dangerousDisableAssetCspModification: ["style-src"] tells Tauri to leave style-src as it is written ('self' 'unsafe-inline'). Only style-src: script-src keeps what Tauri adds to it.
  • pnpm tauri:build: the self-hosted overlay still drops every deployment host of the base policy and keeps the channel, which is no deployment's host (isDeploymentHost). The release overlay appends the storage origin as before. Neither overlay names the style-src setting, so the merge keeps it.
  • README: the self-hosted policy paragraph names the channel.

What changes for a user

In the installed app the sign-in page's background and its wrong-password shake animate (measured), and so do the other style blocks of the same kind: the live voice bars, the supporter badges, a theme's patterns. Nothing changes in the browser build.

The installed app now accepts inline style blocks, as the policy's text has always said. A style can load a url() only from the hosts img-src names; script-src is unchanged.

Follow-up

The stricter way is tracked in #279: no style block added at run time (the keyframes in the stylesheet, the theme's rules without an inline block), and then neither the setting nor 'unsafe-inline' in style-src.

Key files

  • apps/desktop/src-tauri/tauri.conf.json: the two settings.
  • apps/desktop/scripts/tauriCsp.mjs (TAURI_IPC_SOURCES), tauriSelfHosted.mjs (isDeploymentHost).
  • apps/desktop/src/__tests__/scripts/tauriCsp.test.ts, tauriSelfHosted.test.ts.

Migrations

None.

Tests

  • The two test files pin: the base policy byte for byte (2.1.1 without the dev sources, plus the channel), the channel in connect-src only and kept by both overlays, style-src as written and left alone by Tauri while no other directive is, and that the app still adds style blocks at run time (the reason for the setting).
  • Desktop suite: 3222 passed, 1 skipped. Typecheck and lint clean. Rust tests of the shell: 21 passed.
  • Measured on a build made with pnpm tauri:build for a local server with its own object store, installed on Windows and driven through its webview. Before: five violations on the way to the sign-in page (four style blocks, one call). After: none; the page's five style blocks applied; twelve calls answered on the channel; the app signs in, opens its socket, uploads an avatar and an attachment straight to the object store and shows both. A control image to an origin the policy does not name is still refused.

Issue: #57

…hes its native side directly

The Content Security Policy of an installed build refused two things the
app does itself, in the official build as in a self-hosted one:

- Style blocks added at run time: the animations of the sign-in and
  sign-up pages, the live voice bars of the spaces strip, the supporter
  badges, a theme's pattern rules. At build time Tauri adds a nonce to the
  directives of the pages it serves, and a nonce makes the webview ignore
  'unsafe-inline', so a block without the nonce was refused.
  `dangerousDisableAssetCspModification: ["style-src"]` leaves style-src as
  it is written ('self' 'unsafe-inline'); script-src keeps what Tauri adds
  to it.
- Tauri's own channel. An installed app calls its Rust side with a request
  of its own, `ipc:` on macOS and Linux and http://ipc.localhost on Windows
  and Android. connect-src named neither: the first call was refused and
  reported as a violation, and every later call went over the slower
  message channel Tauri falls back to. connect-src names both now.

A self-hosted build keeps the channel: its overlay still drops every
deployment host of the base policy (isDeploymentHost), and the channel is
no deployment's host. The release overlay appends the storage origin as
before, and neither overlay names the style-src setting, so the merge keeps
it.

Measured on a build made with `pnpm tauri:build` for a local server and
installed on Windows. Before: five violations on the way to the sign-in
page (four style blocks, one call). After: none, the page's five style
blocks applied, twelve calls answered on the channel; the app signs in,
opens its socket, uploads and shows an avatar and an attachment.

This leaves the installed app accepting inline style blocks, as the policy
is written. The stricter way, with no style block added at run time and no
'unsafe-inline', is tracked in #279.

Issue: #57
@Aizen93
Aizen93 merged commit 136c468 into develop Nov 14, 2026
7 checks passed
@Aizen93
Aizen93 deleted the fix/desktop-policy-inline-styles-and-ipc branch November 14, 2026 18:02
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.

1 participant