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-scoping-standard

Tauri 2.0 Mobile IPC Capability Scoping and Payload Validation Standard

Enforces zero-trust isolation between mobile WebViews and native Rust runtimes under Tauri 2.0. Mandates granular capability scoping via capability files and strict bidirectional schema validation to prevent privilege escalation from compromised WebView contexts.

Prohibited Anti-Pattern: Wildcard Capability Grants and Untyped IPC Invocation with Unsanitized Structs

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Mobile IPC Capability Scoping and Payload Validation Standard - Enforces zero-trust isolation between mobile WebViews and native Rust runtimes under Tauri 2.0. Mandates granular capability scoping via capability files and strict bidirectional schema validation to prevent privilege escalation from compromised WebView contexts.
globs: src/**/*.{ts,tsx}, src-tauri/capabilities/**/*.json, src-tauri/src/**/*.rs
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/tauri-v2-mobile-ipc-capability-scoping-standard"
---

# Tauri 2.0 Mobile IPC Capability Scoping and Payload Validation Standard

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Wildcard Capability Grants and Untyped IPC Invocation with Unsanitized Structs

## System Constraints
You are a Principal Security Architect enforcing Tauri 2.0 Mobile IPC Security Invariants. Mobile WebView contexts are considered untrusted execution boundaries. You must enforce explicit capability definitions, disallow global wildcards, mandate strict schema-driven parameter validation on both TypeScript and Rust surfaces, and reject untyped serde deserialization.

## Strict Guidelines
- Engineers MUST ALWAYS define fine-grained capability sets in `src-tauri/capabilities/` scoped strictly to target mobile platforms (iOS/Android) and designated window labels.
- Engineers MUST NOT grant wildcard permissions (`*`) or unrestricted core plugin access (e.g., `fs:default`, `shell:default`) in mobile capabilities.
- Rust command handlers MUST deserialize incoming IPC arguments into concrete, strongly typed structs deriving `serde::Deserialize` and implementing boundary validation checks; untyped `serde_json::Value` arguments are strictly forbidden.
- Frontend IPC invocations via `@tauri-apps/api/core::invoke` MUST ALWAYS pass data validated against runtime schemas (e.g., Zod) with strict typing matching the Rust command contract.
- All file system paths or external resource identifiers supplied through IPC payloads MUST be canonicalized and checked against an allowlisted base directory scope inside the Rust host before native execution.

## Bad vs Good Implementations
### Tauri 2.0 IPC Contract Validation (TypeScript & Rust)

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The frontend invokes native IPC with unvalidated inputs, permitting path traversal (`../../sensitive_file`) and arbitrary JSON blobs. The Rust command accepts an arbitrary path without canonicalization or directory scoping, exposing the mobile sandbox to unauthorized file overwrites.
```typescript
// BAD: Blind IPC dispatch with untyped arguments and unconstrained Rust receiver
import { invoke } from '@tauri-apps/api/core';

export async function writeDocument(path: string, content: any): Promise<void> {
  // Anti-pattern: Untrusted path and unvalidated payload dispatched across boundary
  await invoke('save_user_document', { path, content });
}

/* In Rust (src-tauri/src/commands.rs):
#[tauri::command]
pub async fn save_user_document(path: String, content: serde_json::Value) -> Result<(), String> {
    // Anti-pattern: Raw string path execution and untyped JSON payload without validation
    std::fs::write(path, content.to_string()).map_err(|e| e.to_string())?;
    Ok(())
}
*/
```

#### Production Standard (Correct)
> **Standard**: The payload is validated via Zod on the frontend and deserialized into rigid, strongly typed structs in Rust. Path traversal is mathematically eliminated by resolving strictly within `app_data_dir()` and verifying the prefix, honoring the Tauri 2.0 mobile zero-trust boundary.
```typescript
// GOOD: Runtime schema validation prior to invoke, paired with typed Rust contract
import { invoke } from '@tauri-apps/api/core';
import { z } from 'zod';

const DocumentPayloadSchema = z.object({
  fileName: z.string().regex(/^[a-zA-Z0-9_-]+\.json$/),
  content: z.object({
    version: z.number().int().positive(),
    data: z.record(z.string(), z.unknown())
  })
});

type DocumentPayload = z.infer<typeof DocumentPayloadSchema>;

export async function writeDocument(rawInput: unknown): Promise<void> {
  const payload = DocumentPayloadSchema.parse(rawInput);
  await invoke<void>('save_user_document', { payload });
}

/* In Rust (src-tauri/src/commands.rs):
use tauri::{AppHandle, Manager};
use serde::Deserialize;
use std::path::PathBuf;

#[derive(Deserialize)]
pub struct ValidatedDocument {
    #[serde(rename = "fileName")]
    file_name: String,
    content: DocumentContent,
}

#[derive(Deserialize)]
pub struct DocumentContent {
    version: u32,
    data: serde_json::Map<String, serde_json::Value>,
}

#[tauri::command]
pub async fn save_user_document(
    app: AppHandle,
    payload: ValidatedDocument,
) -> Result<(), String> {
    // Invariant: Enforce scope resolution via secure app data directory
    let app_dir = app.path().app_data_dir().map_err(|e| e.to_string())?;
    let secure_path: PathBuf = app_dir.join(&payload.file_name);
    
    if !secure_path.starts_with(&app_dir) {
        return Err("Path traversal detected".into());
    }
    
    let serialized = serde_json::to_string(&payload.content).map_err(|e| e.to_string())?;
    tokio::fs::write(secure_path, serialized).await.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 IPC Capability Scoping and Payload Validation Standard

Tauri 2.0 Mobile IPC Capability Scoping and Payload Validation Standard defines an industrial-grade behavioral standard for mobile engineering. Enforces zero-trust isolation between mobile WebViews and native Rust runtimes under Tauri 2.0. Mandates granular capability scoping via capability files and strict bidirectional schema validation to prevent privilege escalation from compromised WebView contexts. 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: Wildcard Capability Grants and Untyped IPC Invocation with Unsanitized Structs 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 DriftWildcard Capability Grants and Untyped IPC Invocation with Unsanitized StructsCritical
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 define fine-grained capability sets in `src-tauri/capabilities/` scoped strictly to target mobile platforms (iOS/Android) and designated window labels.

Engineers MUST ALWAYS define fine-grained capability sets in `src-tauri/capabilities/` scoped strictly to target mobile platforms (iOS/Android) and designated window labels.

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 (`*`) or unrestricted core plugin access (e.g., `fs

Engineers MUST NOT grant wildcard permissions (`*`) or unrestricted core plugin access (e.g., `fs:default`, `shell:default`) in mobile capabilities.

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

Rust command handlers MUST deserialize incoming IPC arguments into concrete, strongly typed structs deriving `serde

Rust command handlers MUST deserialize incoming IPC arguments into concrete, strongly typed structs deriving `serde::Deserialize` and implementing boundary validation checks; untyped `serde_json::Value` arguments are strictly forbidden.

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

Frontend IPC invocations via `@tauri-apps/api/core

Frontend IPC invocations via `@tauri-apps/api/core::invoke` MUST ALWAYS pass data validated against runtime schemas (e.g., Zod) with strict typing matching the Rust command contract.

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

All file system paths or external resource identifiers supplied through IPC payloads MUST be canonicalized and checked against an allowlisted base directory scope inside the Rust host before native execution.

All file system paths or external resource identifiers supplied through IPC payloads MUST be canonicalized and checked against an allowlisted base directory scope inside the Rust host before native execution.

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 IPC Capability Scoping and Payload Validation Standard critical for AI coding assistants?

Enforces zero-trust isolation between mobile WebViews and native Rust runtimes under Tauri 2.0. Mandates granular capability scoping via capability files and strict bidirectional schema validation to prevent privilege escalation from compromised WebView contexts. 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 (Wildcard Capability Grants and Untyped IPC Invocation with Unsanitized Structs) 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