Repository navigation
fix(desktop): the installed app applies its own style blocks and reaches its native side directly - #281
Merged
Conversation
…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
4 tasks
Open
5 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
An installed desktop build ran under a stricter Content Security Policy than
tauri.conf.jsonstates, 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 andtauri devare not affected (no policy applies to them).'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.ipc:on macOS and Linux,http://ipc.localhoston Windows and Android).connect-srcnamed 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-srcnamesipc:andhttp://ipc.localhost, anddangerousDisableAssetCspModification: ["style-src"]tells Tauri to leavestyle-srcas it is written ('self' 'unsafe-inline'). Onlystyle-src:script-srckeeps 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 thestyle-srcsetting, so the merge keeps it.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 hostsimg-srcnames;script-srcis 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'instyle-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
connect-srconly and kept by both overlays,style-srcas 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).pnpm tauri:buildfor 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