Tauri Permissions & Capabilities
Relevant source files
The following files were used as context for generating this wiki page:
Tauri's security model for the Serial Plugin relies on a granular Access Control List (ACL) system. This system gates access to underlying Rust commands, ensuring that frontend webviews can only interact with serial hardware through explicitly authorized interfaces. The permissions define which commands are allowed or denied, while capabilities group these permissions and apply them to specific application windows or remote domains.
The serial plugin implements a comprehensive set of permissions covering every aspect of serial communication, from port discovery and lifecycle management to low-level control signals and buffer clearing.
Permission Architecture
Permissions are defined in structured JSON or TOML files that follow a strict schema. A permission file can define default permissions, sets of permissions, or specific inlined permissions.
Permission Components
The architecture is divided into four main definitions:
- Default Permission: The baseline set of privileges granted to the plugin by default.
- Permission Set: A named group of individual permissions, allowing for easier assignment (e.g., a "read-only" set).
- Permission: Specific descriptions of privileges for individual commands, including optional scopes for fine-grained control.
- Commands: Explicit lists of "allow" and "deny" rules for Tauri commands.
The diagram above illustrates the hierarchy of components within a Tauri permission definition file as defined in the project schemas.
Sources: permissions/schemas/schema.json:10-120
Serial Plugin Permissions
The serial plugin defines a vast array of individual permission identifiers. Each identifier typically follows the pattern allow-[command-name] or deny-[command-name].
Permission Categories
Permissions are categorized based on the functional area of the serial API they control:
| Category | Key Identifiers | Description |
|---|---|---|
| Discovery | allow-available-ports, allow-managed-ports | Gates the ability to list system serial ports. |
| Lifecycle | allow-open, allow-close, allow-close-all | Controls the opening and termination of port connections. |
| I/O Operations | allow-read, allow-write, allow-write-binary | Gates data transmission and reception. |
| Configuration | allow-set-baud-rate, allow-set-parity | Controls the hardware parameters of the connection. |
| Control Signals | allow-read-cts, allow-write-dtr | Gates access to hardware flow control pins (CTS, DSR, DTR, etc). |
Sources: permissions/autogenerated/reference.md:65-350, permissions/schemas/schema.json:235-500
Default Permission Set
The serialplugin:default set is a pre-configured collection designed to enable standard serial communication while maintaining security boundaries. On Windows, it specifically denies access to webview data folders to protect application integrity.
Sources: permissions/autogenerated/reference.md:5-60, examples/serialport-test/src-tauri/gen/schemas/acl-manifests.json:1300-1310
Capability System
Capabilities act as the bridge between defined permissions and the frontend environment. They isolate access to the IPC (Inter-Process Communication) layer. If a webview or window is not associated with a capability, it has zero access to the serial plugin's commands.
Capability Structure
A capability includes:
- Windows/Webviews: Glob patterns (e.g.,
main,admin-*) defining which frontend instances receive the permissions. - Permissions: A list of permission identifiers, prefixed with the plugin name (e.g.,
serialplugin:allow-read). - Remote/Local: Configuration for whether the capability applies to local app content or specific remote URLs (using the URLPattern standard).
- Platforms: Restrictions to specific operating systems (macOS, Windows, Linux, Android, iOS).
Sources: examples/serialport-test/src-tauri/gen/schemas/macOS-schema.json:45-120
This diagram shows the validation flow when a frontend attempts to call a serial command.
Sources: examples/serialport-test/src-tauri/gen/schemas/macOS-schema.json:45-55, src/lib.rs:145-185
Command Mapping
The plugin maps permissions directly to Rust functions registered in the invoke_handler. This mapping is defined in the ACL manifests.
Registered Commands
The following core commands are protected by the ACL system:
- Discovery:
available_ports,available_ports_direct,managed_ports. - Lifecycle:
open,close,close_all,force_close. - Communication:
read,read_binary,write,write_binary,start_listening,stop_listening. - State:
bytes_to_read,bytes_to_write,clear_buffer,set_break,clear_break. - Signal Pins:
read_clear_to_send,read_data_set_ready,read_ring_indicator,read_carrier_detect,write_request_to_send,write_data_terminal_ready.
Sources: src/lib.rs:145-180, examples/serialport-test/src-tauri/gen/schemas/acl-manifests.json:1315-1500
Android Implementation
On Android, the plugin registration requires a specific identifier (app.tauri.serialplugin) and utilizes the register_android_plugin interface to bind the Rust commands to the Kotlin implementation.
Sources: src/lib.rs:12-15, src/lib.rs:185-190
Scopes and Fine-Grained Control
The schema allows for a scope property within permissions. Scopes provide an argument-level filter for commands. For example, a command implementation can check the configured scope to allow or prevent actions based on dynamic data, such as allowing access only to specific serial port paths.
Sources: permissions/schemas/schema.json:145-175
Scope Structure
| Field | Type | Description |
|---|---|---|
allow | Array of Values | Data definitions that are permitted by the scope. |
deny | Array of Values | Data definitions that are explicitly blocked (prioritized over allow). |
Sources: permissions/schemas/schema.json:175-200
Summary
The Tauri Permission and Capability system for the Serial Plugin ensures a secure-by-default posture. By requiring developers to explicitly define capabilities for their windows and map them to specific serial commands, the project prevents unauthorized hardware access. The system is cross-platform, supporting desktop and mobile (Android) through unified manifests and target-specific schemas.
Sources: src/lib.rs:145-200, permissions/autogenerated/reference.md:1-5