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¶
- 9
DESKTOP-1Keep Electron's secure renderer defaults: context isolation, the sandbox andwebSecurityon, and Node.js integration off. Callapp.enableSandbox()so that no window can turn the sandbox off. Keeping Node.js integration off helps stop an XSS in a renderer from escalating into code execution on the user's machine, and turning off context isolation also turns off the sandbox. Never load remote content in a renderer with Node.js integration. (Electron, Security: do not enable Node.js integration for remote content, Enable context isolation, Enable process sandboxing, Do not disable webSecurity, Enabling the sandbox globally) - 9
DESKTOP-2In Electron preload scripts, expose a narrow API withcontextBridge.exposeInMainWorld: one function per IPC message, usingipcRenderer.invokefor requests. Never exposeipcRendereror itssend,invokeoronmethods, and don't pass the IPC event object to callbacks in the page. Otherwise any script in the page can send arbitrary IPC messages, or reachipcRendererthroughevent.sender. (Electron, Security: do not expose Electron APIs to untrusted web content, Context Isolation: security considerations, IPC: renderer to main (two-way)) - 9
DESKTOP-3In Electron's main process, check the sender of every IPC message, for example the origin ofevent.senderFrame, and validate its arguments before acting on them. Any web frame can send IPC messages, including iframes and, in some cases, child windows. This appliesSEC-10. (Electron, Security: validate the sender of all IPC messages, Context Isolation: security considerations) - 8
DESKTOP-4Treat the arguments of every Tauri command as untrusted input: deserialize them into specific types, check their values in the command, and enforce your own scopes in the command itself. Keep secrets and as much business logic as you can in the Rust core. Capabilities decide which windows may call a command, but they don't protect against missing or incorrect checks in its implementation. This appliesSEC-10. (Tauri, Trust boundaries, Command scopes, Capabilities: security boundaries, Process model: the WebView process) - 7
DESKTOP-5Never block Electron's main process: use the asynchronous versions of Node.js APIs, avoidipcRenderer.sendSyncand@electron/remote, and move CPU-heavy, crash-prone or untrusted work to a worker thread or a utility process. A blocked main process freezes the whole app. (Electron, Performance: blocking the main process, Process Model: the utility process, IPC: using ipcRenderer.sendSync)
Permissions and web content¶
- 8
DESKTOP-8Scope 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-9Limit where Electron windows can go: block navigation in awill-navigatehandler unless a parsed URL matches the pages you expect, deny new windows insetWindowOpenHandlerby default, and pass only checked, allowlisted URLs toshell.openExternal. Navigation and new windows are common attack vectors, andopenExternalwith 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-6Give every window a Content Security Policy that allows only your own scripts, such asscript-src 'self': in Electron, send it as a header fromsession.webRequest.onHeadersReceived, or in a<meta>tag for pages that can't get headers; in Tauri, setapp.security.cspintauri.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 followWEB-10. (Electron, Security: define a Content Security Policy, Tauri, Content Security Policy, Tauri configuration: dangerousDisableAssetCspModification) - 7
DESKTOP-7Grant 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 withAppManifest::commandsinbuild.rsso 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-10Serve Electron's local pages from a custom protocol withprotocol.handleinstead offile://, and flip the fuses you don't need when packaging, before code signing: turn offRunAsNode,EnableNodeOptionsEnvironmentVariable,EnableNodeCliInspectArgumentsandGrantFileProtocolExtraPrivileges, and turn onEnableEmbeddedAsarIntegrityValidationandOnlyLoadAppFromAsar. An XSS in a page onfile://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-11Use 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-12Store users' credentials and tokens with Electron's asynchronoussafeStorageAPI, 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()returnsbasic_textwhen no secret store is available and data is encrypted with a hardcoded password. This appliesSEC-19andSEC-11. (Electron, ASAR Archives, safeStorage, Tauri, Process model: the WebView process, Stronghold)
Releases and updates¶
- 8
DESKTOP-13Sign every release in the release pipeline: sign macOS apps with a Developer ID Application certificate and notarize them, and sign Windows executables and installers with one consistent identity, asSTEAM-16describes. Windows and macOS warn about or block unsigned apps, and macOS features such asautoUpdater,safeStorageand the cookie encryption fuse only work reliably in a signed app. (Electron, Code Signing, macOS APIs that require code signing, Tauri, macOS code signing: notarization, Tauri, Windows code signing) - 8
DESKTOP-14Deliver updates only through a signed update mechanism over HTTPS: Electron'sautoUpdater, for example throughupdate-electron-app, in a signed app, or the Tauri updater with its signing key pair. Keep the update signing key in the CI secret store, and never set the Tauri updater'sdangerousInsecureTransportProtocol. Tauri verifies every update against the public key intauri.conf.json, and if you lose the private key you can't ship updates to existing installs. On macOS, Electron's updater requires a signed app. (Electron, Updating Applications, autoUpdater: macOS, Tauri, Updater: signing updates) - 8
DESKTOP-15Stay on an Electron major that the Electron team still supports, which is one of the latest three, on its latest minor release, and upgrade one major at a time. Update Tauri, the Rust compiler and Node.js just as promptly. Each Electron release ships its own Chromium and Node.js, and exploits for their older versions are more widely available. This appliesSEC-17. (Electron, Security: use a current version of Electron, Electron Releases: version support policy, Tauri, Keep your applications up to date)
Testing¶
- 6
DESKTOP-16Run end-to-end tests against the built app, for example with WebdriverIO's Electron or Tauri service, or with Playwright's experimental Electron support, and mock the IPC layer in front-end unit tests, for example with Tauri'smockIPC. Follow the end-to-end test rules in Web front end, such asWEB-15andWEB-17. (Electron, Automated Testing, WebdriverIO, Electron, Tauri, WebDriver, Tauri, Mock Tauri APIs)
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 overridessandbox: falsein any window. Partly checksDESKTOP-1. - 7 Tauri updater signature check: built into the updater, which verifies every update against the public key in
tauri.conf.jsonand can't be turned off, and enforces TLS for update endpoints in production. Partly checksDESKTOP-14. - 6 @electron/fuses: flips fuses from a build script, or through Electron Forge's Fuses plugin.
npx @electron/fuses read --appprints a packaged app's fuses for a check in CI, andstrictlyRequireAllFuses: truefails the build when the Electron binary has a fuse that your configuration doesn't set. Partly checksDESKTOP-10. - 6 SignTool
verifyandspctl --assess: in the release job,signtool verify /pachecks the signature of Windows files with the default authentication verification policy and returns 1 on failure, andspctl -vvv --assess --type execreports whether a macOS app will run under the system policies in effect. Partly checksDESKTOP-13. - 6 npm audit and cargo audit: report npm packages and Rust crates with known vulnerabilities;
npm auditexits with a non-zero code when it finds any, at or above--audit-level. Partly checksDESKTOP-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.