Skip to content

build(desktop): set a Content Security Policy - #25

Merged
arifintahu merged 1 commit into
mainfrom
fix/set-csp
Oct 28, 2026
Merged

arifintahu merged 1 commit into
mainfrom
fix/set-csp

Conversation

@arifintahu

Copy link
Copy Markdown
Member

What and why

app.security.csp was null. The webview can call session_write, so any future script injection would be code execution. The app loads nothing from the network, so a strict policy fits:

default-src 'self'; script-src 'self'; connect-src ipc: http://ipc.localhost; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; object-src 'none'; base-uri 'none'; frame-src 'none'

devCsp adds the Vite dev server and its HMR websocket. dangerousDisableAssetCspModification: ["style-src"] stops Tauri adding a style nonce: xterm.js creates <style> elements at runtime without a nonce, and a nonce would make 'unsafe-inline' ineffective. Styles cannot run script, so scripts stay locked to 'self'.

Fixes #20

How you checked it

  • Grepped the frontend for network use, workers, eval, blob: and external fonts: none.
  • Served the built frontend with this exact header: no CSP violations on load; inline scripts are blocked; runtime <style> elements and style attributes still apply.
  • Built the release exe with the config (cargo build --release --features tauri/custom-protocol).
  • Not tested: the full app running under the policy (my own EmberTerm was open, so I did not start a second instance). Please smoke-test a built app before merging: open tabs, split, paste, change theme, Check for updates.

@arifintahu arifintahu self-assigned this Oct 28, 2026
@arifintahu
arifintahu merged commit 78cf671 into main Oct 28, 2026
@arifintahu
arifintahu deleted the fix/set-csp branch October 28, 2026 12:54
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.

build(desktop): set a Content Security Policy

1 participant