Skip to content

Desktop apps (Electron and Tauri)

Scope: desktop apps for Windows, macOS and Linux whose user interface is a web front end, built with Electron (current major: Electron 45; the Electron team supports the latest three majors) or Tauri 2 (current release: 2.13). Tauri 2 also builds mobile apps, which these guidelines don't cover. The web content in a window follows Web front end and the guidelines of its framework, such as React, Vue or Svelte. Electron's main process runs on Node.js, so the Node.js guidelines apply to it. Keeping secrets out of what you ship (SEC-11), validating input at trust boundaries (SEC-10) and staying on supported releases (SEC-17) are in Security, and versioning and release builds are in Releases. Games sold on Steam also follow Steam and PC games.

Entries are sorted by score from 1 to 10 (criteria): 9โ€“10 start here or strongly recommended, 6โ€“8 recommended, 1โ€“5 further reading or conditional.

Adopted references

  • 9 Security (Electron): the baseline for Electron apps. The official checklist of 20 security recommendations, from context isolation, the sandbox and a Content Security Policy to navigation limits, IPC sender validation, custom protocols and fuses.
  • 8 Security (Tauri): the baseline for Tauri apps. Trust boundaries between the Rust core and the WebView, permissions, command scopes, capabilities, runtime authority, the CSP, the isolation pattern, and threats across the application lifecycle.
  • 8 Process Model (Electron): the main process, renderer processes, preload scripts and utility processes, and what each one may do.
  • 8 Inter-Process Communication (Electron): the IPC patterns between renderer and main process, exposed through a preload script and contextBridge.
  • 7 Capabilities (Tauri): granting and denying permissions to windows and webviews, per platform, and what capabilities do and don't protect against.
  • 7 Electron Forge: the Electron project's all-in-one tool for packaging, code signing, creating installers and publishing apps, which combines Electron's first-party tools into one build pipeline.
  • 7 Distribute (Tauri): building, bundling, versioning, signing and distributing Tauri apps for each platform and store.
  • 7 Performance (Electron): a checklist for fast Electron apps, from choosing modules and loading code late to not blocking the main process and bundling code.
  • 7 Code Signing (Electron): signing and notarizing macOS builds and signing Windows builds with Electron Forge and other tools.
  • 6 App Size (Tauri): a Cargo release profile for small binaries, and removing commands that no capability allows.

Key rules

Processes and IPC

Permissions and web content

  • 8 DESKTOP-8 Scope every Tauri plugin permission that reaches the system: allow file system access only to the base directories the app needs, such as $APPDATA, with deny scopes for sensitive paths, allow the shell plugin to run only named programs with argument validators, and allow the opener plugin only the URLs and paths it needs. Deny scopes take precedence over allow scopes. (Tauri, File System: scopes, Command scopes, Shell: permissions, Opener: permissions)
  • 8 DESKTOP-9 Limit where Electron windows can go: block navigation in a will-navigate handler unless a parsed URL matches the pages you expect, deny new windows in setWindowOpenHandler by default, and pass only checked, allowlisted URLs to shell.openExternal. Navigation and new windows are common attack vectors, and openExternal with untrusted input can run arbitrary commands. Compare parsed origins, not string prefixes. (Electron, Security: disable or limit navigation, Disable or limit creation of new windows, Do not use shell.openExternal with untrusted content)
  • 7 DESKTOP-6 Give every window a Content Security Policy that allows only your own scripts, such as script-src 'self': in Electron, send it as a header from session.webRequest.onHeadersReceived, or in a <meta> tag for pages that can't get headers; in Tauri, set app.security.csp in tauri.conf.json, because Tauri's CSP protection is off until you set it. Don't load scripts from remote servers or CDNs, and don't turn off Tauri's injection of hashes and nonces. This is how desktop apps follow WEB-10. (Electron, Security: define a Content Security Policy, Tauri, Content Security Policy, Tauri configuration: dangerousDisableAssetCspModification)
  • 7 DESKTOP-7 Grant each Tauri window only the permissions it needs: give windows with different privileges separate capabilities, add a window to several capabilities only if it needs all their permissions, declare your own commands with AppManifest::commands in build.rs so that a window can call them only when a capability allows it, and let only higher-privileged windows create windows. A window in several capabilities gets the permissions of all of them, by default every command the app registers is allowed for every window, and capabilities match windows by label, not by title. (Tauri, Capabilities, Capabilities: security boundaries, Capabilities for different windows and platforms)
  • 7 DESKTOP-10 Serve Electron's local pages from a custom protocol with protocol.handle instead of file://, and flip the fuses you don't need when packaging, before code signing: turn off RunAsNode, EnableNodeOptionsEnvironmentVariable, EnableNodeCliInspectArguments and GrantFileProtocolExtraPrivileges, and turn on EnableEmbeddedAsarIntegrityValidation and OnlyLoadAppFromAsar. An XSS in a page on file:// can read any file on the machine, and with the default fuses the app's binary can be started as plain Node.js or with a debugger, which can be used to run commands through your app. (Electron, Security: avoid the file:// protocol, Check which fuses you can change, Electron Fuses)
  • 6 DESKTOP-11 Use Tauri's isolation pattern when the front end has many dependencies or loads third-party content, and keep the isolation application small, with few dependencies and build steps. It routes every IPC message through a sandboxed iframe that can validate or reject it before it reaches the Rust core. (Tauri, Isolation pattern: when, Recommendations, Tauri configuration: pattern)

Secrets and local data

  • 9 DESKTOP-12 Store users' credentials and tokens with Electron's asynchronous safeStorage API, which uses the operating system's cryptography, or in Tauri, for example, with the Stronghold plugin, and never build API keys or other secrets into the app. Stronghold encrypts its vault with a key derived from a password, so ask the user for that password instead of building it into the app. An ASAR archive only conceals code from cursory inspection, and the front end of a Tauri app must never handle secrets. On Linux, safeStorage.getSelectedStorageBackend() returns basic_text when no secret store is available and data is encrypted with a hardcoded password. This applies SEC-19 and SEC-11. (Electron, ASAR Archives, safeStorage, Tauri, Process model: the WebView process, Stronghold)

Releases and updates

Testing

How to enforce

Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.

  • 7 app.enableSandbox(): built into Electron; called before the app is ready, it forces the sandbox in every renderer and overrides sandbox: false in any window. Partly checks DESKTOP-1.
  • 7 Tauri updater signature check: built into the updater, which verifies every update against the public key in tauri.conf.json and can't be turned off, and enforces TLS for update endpoints in production. Partly checks DESKTOP-14.
  • 6 @electron/fuses: flips fuses from a build script, or through Electron Forge's Fuses plugin. npx @electron/fuses read --app prints a packaged app's fuses for a check in CI, and strictlyRequireAllFuses: true fails the build when the Electron binary has a fuse that your configuration doesn't set. Partly checks DESKTOP-10.
  • 6 SignTool verify and spctl --assess: in the release job, signtool verify /pa checks the signature of Windows files with the default authentication verification policy and returns 1 on failure, and spctl -vvv --assess --type exec reports whether a macOS app will run under the system policies in effect. Partly checks DESKTOP-13.
  • 6 npm audit and cargo audit: report npm packages and Rust crates with known vulnerabilities; npm audit exits with a non-zero code when it finds any, at or above --audit-level. Partly checks DESKTOP-15.

Tutorials and further reading

  • 7 Electron tutorial (Electron): the official tutorial in six parts, from a first app and preload scripts to packaging with Electron Forge, publishing and updating.
  • 6 Using plugin permissions (Tauri): a step-by-step exercise in granting a plugin's permissions to a window and narrowing them with scopes.