Skip to content
Tutorials Center
My learning

Topics

Lesson 26 of 39 ยท Security and Permissions

The Tauri Security Model

Understand how Tauri 2 protects users: the trust boundary between webview and Rust, what an attacker can reach, the layers of defense, and a runnable stand-in of a threat checklist.

An app that can read files, run programs and talk to the network is powerful, and powerful code is attractive to attackers. A website can do very little because the browser sandboxes it. A desktop app is different: it runs with the permissions of the user. If someone tricks your app into running their code, they get what the app has.

Tauri is designed around that fact. This lesson explains the picture: where the trust boundaries are, what the realistic attacks look like, and which defensive layers Tauri gives you. The following lessons then go deeper into Capabilities and Permissions, Scopes and Input Validation and CSP, Isolation and Hardening.

Real versus stand-in. The configuration shown is real Tauri 2 JSON and Rust. The runnable blocks are small JavaScript models of checks you would think about, not Tauri itself.

Two worlds with a bridge

A Tauri app has two parts that trust each other very differently.

flowchart LR
  subgraph Untrusted["Webview (less trusted)"]
    UI["HTML, CSS, JS<br/>your code, npm packages,<br/>content from the web"]
  end
  subgraph Bridge["IPC bridge"]
    Auth["Capabilities and scopes<br/>checked on every call"]
  end
  subgraph Trusted["Rust core (trusted)"]
    Core["Commands, plugins,<br/>OS access"]
  end
  UI -->|invoke| Auth --> Core
  Core -->|events, results| UI

Everything in the webview should be treated as something an attacker might control. Rust decides what actually happens.

The Rust side is compiled, small and written by you. The webview side holds a large amount of code you did not write: every npm package, every script, and any remote content you display. A single compromised dependency or one cross-site scripting (XSS) bug lets an attacker run JavaScript inside your window. The key question Tauri asks is: what can that JavaScript do?

In Tauri the answer is: only what you explicitly allowed for that window, and nothing more.

What attackers want

Threat Example Main defense
Injected script (XSS) A note contains <img onerror=...> and your UI renders it as HTML Escape output, CSP, restrict permissions
Malicious dependency A compromised npm package reads files Capabilities limit what the webview may call
Path traversal Frontend asks Rust to read ../../.ssh/id_rsa Scopes, canonicalizing paths in Rust
Command injection Your Rust command builds a shell string from user text Pass arguments as arrays, never through a shell
Remote content abuse Your window loads a website that calls your commands Capabilities with remote URLs only when needed
Tampered update An attacker serves a fake update Signed updates (see Updater and Releases)
Supply chain on the Rust side A vulnerable crate cargo audit, pinned versions

The defense layers Tauri gives you

  1. Small core and opt-in plugins. Features you do not install cannot be abused (plugin system).
  2. Capabilities and permissions. Each window (or webview) gets a list of allowed commands. Anything else is refused by the runtime.
  3. Scopes. Even an allowed command can be limited to certain paths, URLs or programs.
  4. Content Security Policy (CSP). The webview refuses to run scripts and load resources you did not list.
  5. Isolation pattern. Messages pass through a sandboxed iframe where a small script of yours can inspect and veto them.
  6. Rust's memory safety. A whole class of bugs (buffer overflows, use after free) does not exist in safe Rust.
  7. Signed updates and bundles. Users receive code that actually came from you.

You are expected to use several layers together. No single one is enough.

What Tauri does NOT do for you

  • It does not make your own Rust commands safe. A command that executes whatever string the frontend sends is dangerous, however many permissions surround it.
  • It does not sanitize HTML you render. Using innerHTML with untrusted text is still XSS.
  • It does not decide what is secret. If you store a token in a JSON file, anyone with the user's account can read it.
  • It does not remove the need to keep dependencies updated.

A habit: design from least privilege

Before adding a permission, ask three questions: Which window needs this? Which exact command? Which paths, URLs or programs? Start with nothing and add until the feature works, instead of starting with everything and trying to remove.

Compare two capability files for an app that only needs to show a note editor:

JSON
{
  "identifier": "too-much",
  "windows": ["*"],
  "permissions": ["core:default", "fs:default", "fs:allow-write-text-file", "shell:default", "http:default"]
}
JSON
{
  "identifier": "editor",
  "windows": ["main"],
  "permissions": [
    "core:default",
    "dialog:allow-open",
    "dialog:allow-save",
    {
      "identifier": "fs:allow-read-text-file",
      "allow": [{ "path": "$APPDATA/notes/**" }]
    },
    {
      "identifier": "fs:allow-write-text-file",
      "allow": [{ "path": "$APPDATA/notes/**" }]
    }
  ]
}

If an attacker runs script in the second app, they can touch notes in one folder and nothing more. In the first, they can write anywhere the plugin allows, launch shell commands and call the network.

A threat checklist you can run

The stand-in scores a configuration against simple rules. It is deliberately simplified, but doing a review like this on your own capabilities folder is a real, useful habit.

Node.js Stand-in: review a capability for risky grants

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Cross-site scripting stays your job

Frontend frameworks escape text by default. The danger starts when you bypass that, for example with innerHTML, v-html or dangerouslySetInnerHTML. The tiny escaper below shows what proper output encoding does to a hostile note.

Node.js Stand-in: escaping untrusted text

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which part of a Tauri app should be treated as potentially attacker-controlled?

    Any script running in the webview might be malicious (XSS or a bad package), so Tauri limits what it can call through capabilities.
  2. 2. What is least privilege in this context?

    Start with nothing and add only what a feature requires; a compromised window then has little to abuse.
  3. 3. Does a strict capability file make a command that runs arbitrary shell text safe?

    Permissions control who may call a command; they cannot fix a command that is dangerous by design.
  4. 4. Which is a defense against a fake update being installed?

    The updater verifies a signature against the public key embedded in your app, so unsigned or altered updates are rejected.

Summary

  • The webview is the less trusted side; the Rust core is the trusted side; the IPC bridge enforces capabilities.
  • Layers: opt-in plugins, capabilities, scopes, CSP, isolation, safe Rust and signed updates.
  • Tauri cannot rescue unsafe commands, unsafe HTML rendering or plain-text secrets.
  • Design with least privilege and review your capability files regularly.

Next: Capabilities and Permissions