This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: tauri-v2-mobile-ipc-capability-sandboxing

Tauri 2.0 Mobile Capability-Based IPC Permission Sandboxing

Enforces strict principle-of-least-privilege IPC execution boundaries in Tauri 2.0 mobile runtimes (iOS/Android) via explicit capability manifests and scoped permission sets. Prevents embedded WebViews from invoking arbitrary host native APIs or escalating host OS privileges through wildcard IPC dispatchers and unvalidated custom command invocations.

Prohibited Anti-Pattern: Permissive Wildcard Core Permissions and Unscoped Custom Command Invocation on Mobile Runtimes

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Mobile Capability-Based IPC Permission Sandboxing - Enforces strict principle-of-least-privilege IPC execution boundaries in Tauri 2.0 mobile runtimes (iOS/Android) via explicit capability manifests and scoped permission sets. Prevents embedded WebViews from invoking arbitrary host native APIs or escalating host OS privileges through wildcard IPC dispatchers and unvalidated custom command invocations.
globs: src-tauri/capabilities/**/*.json, src-tauri/src/**/*.rs, src-tauri/tauri.conf.json, src/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/tauri-v2-mobile-ipc-capability-sandboxing"
---

# Tauri 2.0 Mobile Capability-Based IPC Permission Sandboxing

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Permissive Wildcard Core Permissions and Unscoped Custom Command Invocation on Mobile Runtimes

## System Constraints
You are a Principal Security Architect enforcing Tauri 2.0 Mobile Capability-Based IPC Permission Sandboxing. Mandate the isolation of native platform APIs on iOS and Android runtimes. Ensure that all IPC invocations from the frontend runtime conform strictly to scoped capability definitions defined in `src-tauri/capabilities/*.json`. Never permit wildcard permissions (`core:*`, `fs:*`, `shell:*`), enforce window/webview label matching, and validate that all native command handlers perform defensive argument validation against IPC boundary tampering.

## Strict Guidelines
- Engineers MUST ALWAYS isolate mobile capabilities into dedicated target-specific capability files (e.g., `src-tauri/capabilities/mobile.json`) using strict platform filters targeting `android` and `ios`.
- Engineers MUST NOT grant wildcard permissions (`core:*`, `default`, or unfiltered plugin roots like `fs:default`) in capability manifests exposed to mobile webview windows.
- Engineers MUST explicitly constrain filesystem, network, and biometric native commands to fine-grained scopes (e.g., `fs:allow-read-text-file` restricted to `$APPDATA/*` and `$RESOURCE/*`).
- Custom Rust `#[tauri::command]` handlers MUST validate all typed payloads at the Rust boundary and verify that the calling `tauri::ipc::Invoke` origin possesses an authorized Webview window label.
- Frontend IPC invokers MUST ONLY import strongly typed wrapper commands from a validated client SDK layer rather than invoking untyped `@tauri-apps/api/core::invoke` directly in UI components.

## Bad vs Good Implementations
### Tauri 2.0 Mobile Capability Manifest vs Permissive Default

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using wildcard windows ('*') and permissive bundles ('core:default', 'fs:default') allows any embedded webview or malicious script injection (via XSS) to access arbitrary native system resources, read the host mobile filesystem, and spawn external apps.
```json
{
  "$schema": "../gen/schemas/desktop-schema.json",
  "identifier": "mobile-capability",
  "description": "Insecure permissive capability allowing arbitrary commands",
  "windows": ["*"],
  "permissions": [
    "core:default",
    "fs:default",
    "shell:allow-open"
  ]
}
```

#### Production Standard (Correct)
> **Standard**: Limits exposure exclusively to the 'main' window on mobile platforms, rejects core wildcards, and enforces path-scoped filesystem read access restricted to the secure app-data subdirectory.
```json
{
  "$schema": "../gen/schemas/mobile-schema.json",
  "identifier": "mobile-capability",
  "description": "Hardened least-privilege capability for authenticated mobile webviews",
  "platforms": ["android", "ios"],
  "windows": ["main"],
  "permissions": [
    "core:path:allow-app-data-dir",
    {
      "identifier": "fs:allow-read-text-file",
      "allow": [{
        "path": "$APPDATA/user_cache/**"
      }]
    },
    "biometric:allow-authenticate"
  ]
}
```

### Rust IPC Boundary Validation with Window Context

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Accepts an unvalidated target path from the IPC caller without checking caller provenance, window identity, or sandbox containment, permitting path-traversal attacks across the native mobile storage boundary.
```rust
use tauri::command;

#[command]
pub fn write_mobile_log(content: String, target_path: String) -> Result<(), String> {
    // Anti-pattern: Untrusted path from IPC directly executed without origin validation
    std::fs::write(&target_path, content).map_err(|e| e.to_string())
}
```

#### Production Standard (Correct)
> **Standard**: Validates the calling WebviewWindow label, prevents path-traversal sequences, resolves paths strictly through AppHandle's secured app_data_dir sandbox, and enforces asynchronous I/O.
```rust
use tauri::{command, ipc::Invoke, AppHandle, Manager, WebviewWindow};
use std::path::PathBuf;

#[command]
pub async fn write_mobile_log(
    app: AppHandle,
    window: WebviewWindow,
    file_name: String,
    content: String,
) -> Result<(), String> {
    if window.label() != "main" {
        return Err("Unauthorized caller origin".into());
    }
    
    // Reject path traversal attempts strictly
    if file_name.contains('/') || file_name.contains('\\') || file_name.starts_with('.') {
        return Err("Invalid file identifier name".into());
    }
    
    let app_dir = app.path().app_data_dir().map_err(|e| e.to_string())?;
    let secure_path: PathBuf = app_dir.join("user_cache").join(file_name);
    
    tokio::fs::create_dir_all(app_dir.join("user_cache"))
        .await
        .map_err(|e| e.to_string())?;
    tokio::fs::write(&secure_path, content.as_bytes())
        .await
        .map_err(|e| e.to_string())
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Tauri 2.0 Mobile Capability-Based IPC Permission Sandboxing

Tauri 2.0 Mobile Capability-Based IPC Permission Sandboxing defines an industrial-grade behavioral standard for mobile engineering. Enforces strict principle-of-least-privilege IPC execution boundaries in Tauri 2.0 mobile runtimes (iOS/Android) via explicit capability manifests and scoped permission sets. Prevents embedded WebViews from invoking arbitrary host native APIs or escalating host OS privileges through wildcard IPC dispatchers and unvalidated custom command invocations. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Permissive Wildcard Core Permissions and Unscoped Custom Command Invocation on Mobile Runtimes Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftPermissive Wildcard Core Permissions and Unscoped Custom Command Invocation on Mobile RuntimesCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS isolate mobile capabilities into dedicated target-specific capability files (e.g., `src-tauri/capabilities/mobile.json`) using strict platform filters targeting `android` and `ios`.

Engineers MUST ALWAYS isolate mobile capabilities into dedicated target-specific capability files (e.g., `src-tauri/capabilities/mobile.json`) using strict platform filters targeting `android` and `ios`.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT grant wildcard permissions (`core

Engineers MUST NOT grant wildcard permissions (`core:*`, `default`, or unfiltered plugin roots like `fs:default`) in capability manifests exposed to mobile webview windows.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Engineers MUST explicitly constrain filesystem, network, and biometric native commands to fine-grained scopes (e.g., `fs

Engineers MUST explicitly constrain filesystem, network, and biometric native commands to fine-grained scopes (e.g., `fs:allow-read-text-file` restricted to `$APPDATA/*` and `$RESOURCE/*`).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Custom Rust `#[tauri

Custom Rust `#[tauri::command]` handlers MUST validate all typed payloads at the Rust boundary and verify that the calling `tauri::ipc::Invoke` origin possesses an authorized Webview window label.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Frontend IPC invokers MUST ONLY import strongly typed wrapper commands from a validated client SDK layer rather than invoking untyped `@tauri-apps/api/core

Frontend IPC invokers MUST ONLY import strongly typed wrapper commands from a validated client SDK layer rather than invoking untyped `@tauri-apps/api/core::invoke` directly in UI components.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Tauri 2.0 Mobile Capability-Based IPC Permission Sandboxing critical for AI coding assistants?

Enforces strict principle-of-least-privilege IPC execution boundaries in Tauri 2.0 mobile runtimes (iOS/Android) via explicit capability manifests and scoped permission sets. Prevents embedded WebViews from invoking arbitrary host native APIs or escalating host OS privileges through wildcard IPC dispatchers and unvalidated custom command invocations. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Permissive Wildcard Core Permissions and Unscoped Custom Command Invocation on Mobile Runtimes) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

Related MOBILE Rules

View all rules →
1 Rule in Stack

Tauri