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

Tauri 2.0 Mobile Capability-Based IPC Sandboxing Invariant

Enforces strict principle-of-least-privilege capability manifests between mobile WebView execution contexts and native Rust commands on iOS and Android. In Tauri 2.0, indiscriminate core permissions, default catch-all remote access, and unvalidated WebView origins allow untrusted or compromised UI scripts to execute privileged native device APIs. All commands and native plugins must be bounded by explicit target-scoped capability definitions and strict typed argument verification.

Prohibited Anti-Pattern: Over-Privileged Mobile Capability Grants and Global Allow-All IPC Bindings

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Mobile Capability-Based IPC Sandboxing Invariant - Enforces strict principle-of-least-privilege capability manifests between mobile WebView execution contexts and native Rust commands on iOS and Android. In Tauri 2.0, indiscriminate core permissions, default catch-all remote access, and unvalidated WebView origins allow untrusted or compromised UI scripts to execute privileged native device APIs. All commands and native plugins must be bounded by explicit target-scoped capability definitions and strict typed argument verification.
globs: src-tauri/capabilities/**/*.json, src-tauri/tauri.conf.json, src-tauri/src/**/*.rs, src/**/*.{ts,tsx,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/tauri-v2-mobile-capability-sandboxing"
---

# Tauri 2.0 Mobile Capability-Based IPC Sandboxing Invariant

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Over-Privileged Mobile Capability Grants and Global Allow-All IPC Bindings

## System Constraints
You are a Principal Security Architect enforcing Tauri 2.0 Mobile Capability-Based IPC Sandboxing. Mandate the strict separation of WebView contexts and native Rust system APIs. Never allow wildcard permissions ('core:default' with wildcard scopes or unrestricted plugin access) on mobile targets (iOS and Android). Enforce explicit capabilities declared inside `src-tauri/capabilities/*.json` with precise window and webview targeting, scoped filesystem boundaries, and rigorous parameter validation at the Rust IPC boundary.

## Strict Guidelines
- Engineers MUST ALWAYS isolate mobile capabilities into dedicated target files (e.g., `src-tauri/capabilities/mobile.json`) and bind them explicitly using `platforms: ["iOS", "android"]`.
- Engineers MUST NOT grant wildcard capabilities (`core:*`, `fs:*`, `shell:*`) or assign the catch-all `default.json` capability to untrusted remote URLs or broad mobile WebView contexts.
- Engineers MUST ALWAYS define fine-grained permission scopes for native plugins (e.g., restricting `fs:allow-read-file` to specific app-scoped mobile directory aliases like `$APPDATA` or `$RESOURCE`).
- Services MUST validate and sanitize all deserialized IPC arguments inside native Rust `#[tauri::command]` handlers, treating input from WebView contexts as untrusted tainted data regardless of frontend TypeScript typing.
- Components NEVER execute raw or unstructured shell/native invocations directly without a mediating Rust command that verifies origin state and session authorization.

## Bad vs Good Implementations
### Tauri 2.0 Mobile Capability Configuration

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Assigns wildcard window access ('*') and bundles broad 'default' permission presets (including arbitrary filesystem and network access) across all platforms without platform filtering or path-scoping constraints.
```json
{
  "$schema": "../gen/schemas/desktop-schema.json",
  "identifier": "mobile-capability",
  "description": "Anti-pattern: global unrestricted capabilities",
  "windows": ["*"],
  "permissions": [
    "core:default",
    "fs:default",
    "camera:default",
    "http:default"
  ]
}
```

#### Production Standard (Correct)
> **Standard**: Explicitly scopes capability targets to iOS and Android, binds only to the authenticated 'main' window/webview, rejects blanket permissions, and confines filesystem access strictly to the runtime-isolated '$APPCACHE' directory.
```json
{
  "$schema": "../gen/schemas/mobile-schema.json",
  "identifier": "mobile-capability",
  "description": "Least-privilege scoped permissions for mobile targets",
  "platforms": ["iOS", "android"],
  "windows": ["main"],
  "webviews": ["main"],
  "permissions": [
    "core:app:allow-version",
    "camera:allow-scan-qr",
    {
      "identifier": "fs:allow-read-file",
      "allow": [{
        "path": "$APPCACHE/*"
      }]
    }
  ]
}
```

### Tauri 2.0 Rust Native Command Guardrail

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Bypasses Tauri 2.0's capability-sandboxing model by writing directly to arbitrary paths provided by the frontend via standard Rust APIs, rendering mobile sandboxing null and void.
```rust
use tauri::command;

// Flawed: Direct un-sanitized filesystem write without scope or token validation
#[command]
pub async fn write_user_export(path: String, payload: String) -> Result<(), String> {
    std::fs::write(&path, payload).map_err(|e| e.to_string())?;
    Ok(())
}
```

#### Production Standard (Correct)
> **Standard**: Enforces strict path sanitation preventing directory traversal and resolves target file locations strictly through the managed Tauri `app.path()` API, ensuring operations stay within the sandboxed app-cache path.
```rust
use tauri::{command, AppHandle, Manager, Runtime};
use std::path::PathBuf;

#[command]
pub async fn write_user_export<R: Runtime>(
    app: AppHandle<R>,
    filename: String,
    payload: String,
) -> Result<(), String> {
    // Invariant: Enforce relative safe filename validation against traversal
    if filename.contains('/') || filename.contains('\\') || filename.contains("..") {
        return Err("Invalid filename: directory traversal detected".into());
    }

    let safe_dir = app.path().app_cache_dir().map_err(|e| e.to_string())?;
    let destination: PathBuf = safe_dir.join(filename);

    std::fs::write(&destination, payload.as_bytes()).map_err(|e| e.to_string())?;
    Ok(())
}
```

Recommended MCP Servers (mcp-serverlist.com)

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

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

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

Tauri 2.0 Mobile Capability-Based IPC Sandboxing Invariant defines an industrial-grade behavioral standard for mobile engineering. Enforces strict principle-of-least-privilege capability manifests between mobile WebView execution contexts and native Rust commands on iOS and Android. In Tauri 2.0, indiscriminate core permissions, default catch-all remote access, and unvalidated WebView origins allow untrusted or compromised UI scripts to execute privileged native device APIs. All commands and native plugins must be bounded by explicit target-scoped capability definitions and strict typed argument verification. 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: Over-Privileged Mobile Capability Grants and Global Allow-All IPC Bindings 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 DriftOver-Privileged Mobile Capability Grants and Global Allow-All IPC BindingsCritical
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 files (e.g., `src-tauri/capabilities/mobile.json`) and bind them explicitly using `platforms

Engineers MUST ALWAYS isolate mobile capabilities into dedicated target files (e.g., `src-tauri/capabilities/mobile.json`) and bind them explicitly using `platforms: ["iOS", "android"]`.

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 capabilities (`core

Engineers MUST NOT grant wildcard capabilities (`core:*`, `fs:*`, `shell:*`) or assign the catch-all `default.json` capability to untrusted remote URLs or broad mobile WebView contexts.

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 ALWAYS define fine-grained permission scopes for native plugins (e.g., restricting `fs

Engineers MUST ALWAYS define fine-grained permission scopes for native plugins (e.g., restricting `fs:allow-read-file` to specific app-scoped mobile directory aliases like `$APPDATA` or `$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

Services MUST validate and sanitize all deserialized IPC arguments inside native Rust `#[tauri

Services MUST validate and sanitize all deserialized IPC arguments inside native Rust `#[tauri::command]` handlers, treating input from WebView contexts as untrusted tainted data regardless of frontend TypeScript typing.

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

Components NEVER execute raw or unstructured shell/native invocations directly without a mediating Rust command that verifies origin state and session authorization.

Components NEVER execute raw or unstructured shell/native invocations directly without a mediating Rust command that verifies origin state and session authorization.

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 Sandboxing Invariant critical for AI coding assistants?

Enforces strict principle-of-least-privilege capability manifests between mobile WebView execution contexts and native Rust commands on iOS and Android. In Tauri 2.0, indiscriminate core permissions, default catch-all remote access, and unvalidated WebView origins allow untrusted or compromised UI scripts to execute privileged native device APIs. All commands and native plugins must be bounded by explicit target-scoped capability definitions and strict typed argument verification. 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 (Over-Privileged Mobile Capability Grants and Global Allow-All IPC Bindings) 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