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

Tauri 2.0 Granular Capability Scoping & Zero-Copy IPC ArrayBuffer Protocol

Enforce principle-of-least-privilege capability manifests and zero-copy binary IPC transfer protocols for Tauri 2.0 mobile targets. Wildcard window permissions expose device native features (camera, biometric, filesystem) to cross-site script injection, while serialized JSON byte transport causes extreme memory duplication and thermal throttling on mobile ARM chipsets. Native commands must use scoped capability ACLs and return binary buffers directly wrapped in Tauri IPC Responses.

Prohibited Anti-Pattern: Exposing native OS host capabilities via wildcard permissions while transferring bulk binary data over JSON-serialized numeric arrays.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Granular Capability Scoping & Zero-Copy IPC ArrayBuffer Protocol - Enforce principle-of-least-privilege capability manifests and zero-copy binary IPC transfer protocols for Tauri 2.0 mobile targets. Wildcard window permissions expose device native features (camera, biometric, filesystem) to cross-site script injection, while serialized JSON byte transport causes extreme memory duplication and thermal throttling on mobile ARM chipsets. Native commands must use scoped capability ACLs and return binary buffers directly wrapped in Tauri IPC Responses.
globs: src-tauri/capabilities/**/*.json, src-tauri/src/**/*.rs, src/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/tauri-v2-granular-capability-scoping-zero-copy-ipc"
---

# Tauri 2.0 Granular Capability Scoping & Zero-Copy IPC ArrayBuffer Protocol

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Exposing native OS host capabilities via wildcard permissions while transferring bulk binary data over JSON-serialized numeric arrays.

## System Constraints
You are a Principal Mobile Architect specializing in Tauri 2.0 native security and high-performance cross-platform runtimes. Mandate strict capability ACL scoping in JSON manifests and zero-copy binary IPC protocols via tauri::ipc::Response. Reject any wildcard capability targets or JSON serialization of binary data across the webview-host boundary.

## Strict Guidelines
- Engineers MUST ALWAYS isolate native mobile commands into capability files under `src-tauri/capabilities/` explicitly specifying exact window identifiers and permission strings without wildcards (`*`).
- Engineers MUST NOT serialize binary datasets (images, audio, blobs, tensors) into JSON Base64 strings or `Vec<u8>` numeric arrays (`[0, 1, ...]` across the IPC bridge.
- Code SHOULD utilize `tauri::ipc::Response::new(Vec<u8>)` in Rust commands to stream binary data directly to the webview as raw `ArrayBuffer` payloads.
- Services MUST scope remote and local origin access in capability declarations to verified mobile app origins (`mobile:main`, explicit custom schemes).
- Components NEVER execute raw native shell, un-sandboxed filesystem, or device OS commands without validating caller contexts against mobile runtime capability boundaries.

## Bad vs Good Implementations
### Binary IPC Transfer: JSON Serialized Byte Array vs. Zero-Copy IPC Response

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Returning a raw Vec<u8> through standard Tauri command serialization converts each byte into an individual JSON numeric token. For a 4MB frame, this produces a ~16MB JSON text payload, triggering severe GC pressure and thermal throttling on iOS/Android runtimes.
```typescript
// Rust Command: Serializing Vec<u8> via default serde JSON serialization
// #[tauri::command]
// pub fn get_capture_frame() -> Vec<u8> { vec![0u8; 1024 * 1024 * 4] }

import { invoke } from '@tauri-apps/api/core';

// Webview: Deserializes 4MB buffer as an array of 4,194,304 JSON numbers
export async function captureFrame(): Promise<Uint8Array> {
  const jsonArray = await invoke<number[]>('get_capture_frame');
  // Massive CPU spike, 3x memory footprint allocation on mobile
  return new Uint8Array(jsonArray);
}
```

#### Production Standard (Correct)
> **Standard**: Using `tauri::ipc::Response::new(raw_buffer)` bypasses serde_json entirely, streaming raw bytes directly to the webview as an `ArrayBuffer`. This provides deterministic O(1) allocation overhead and sub-millisecond transfer speeds on mobile ARM devices.
```typescript
// Rust Command: Returning zero-copy raw binary IPC response
// use tauri::ipc::Response;
// #[tauri::command]
// pub fn get_capture_frame() -> Result<Response, String> {
//     let raw_buffer: Vec<u8> = capture_sensor_data().map_err(|e| e.to_string())?;
//     Ok(Response::new(raw_buffer))
// }

import { invoke } from '@tauri-apps/api/core';

// Webview: Consumes raw ArrayBuffer transferred directly across native bridge
export async function captureFrame(): Promise<Uint8Array> {
  const buffer = await invoke<ArrayBuffer>('get_capture_frame');
  return new Uint8Array(buffer);
}
```

### Capability Manifest: Wildcard Exposure vs. Scoped Mobile ACL

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using wildcard windows (`*`) and unrestricted permissions (`allow-all`) grants arbitrary dynamically injected webview contexts full access to sensitive mobile hardware APIs and the host device filesystem.
```json
{
  "$schema": "../gen/schemas/desktop-schema.json",
  "identifier": "default-capability",
  "description": "Insecure permissive capability manifest",
  "windows": ["*"],
  "permissions": [
    "core:default",
    "fs:allow-all",
    "camera:allow-all"
  ]
}
```

#### Production Standard (Correct)
> **Standard**: Defines granular capability scoping: targets only the authenticated `main` window on mobile platforms, restricts camera usage to explicit operations, and constrains filesystem access to an application-scoped sandboxed directory.
```json
{
  "$schema": "../gen/schemas/desktop-schema.json",
  "identifier": "mobile-camera-stream",
  "description": "Restricted ACL for camera hardware streaming on mobile",
  "windows": ["main"],
  "platforms": ["iOS", "android"],
  "permissions": [
    "core:default",
    "camera:allow-capture-frame",
    {
      "identifier": "fs:allow-read-file",
      "allow": [{
        "path": "$APP_DATA/captures/*"
      }]
    }
  ]
}
```

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 Granular Capability Scoping & Zero-Copy IPC ArrayBuffer Protocol

Tauri 2.0 Granular Capability Scoping & Zero-Copy IPC ArrayBuffer Protocol defines an industrial-grade behavioral standard for mobile engineering. Enforce principle-of-least-privilege capability manifests and zero-copy binary IPC transfer protocols for Tauri 2.0 mobile targets. Wildcard window permissions expose device native features (camera, biometric, filesystem) to cross-site script injection, while serialized JSON byte transport causes extreme memory duplication and thermal throttling on mobile ARM chipsets. Native commands must use scoped capability ACLs and return binary buffers directly wrapped in Tauri IPC Responses. 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: Exposing native OS host capabilities via wildcard permissions while transferring bulk binary data over JSON-serialized numeric arrays. 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 DriftExposing native OS host capabilities via wildcard permissions while transferring bulk binary data over JSON-serialized numeric arrays.Critical
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 native mobile commands into capability files under `src-tauri/capabilities/` explicitly specifying exact window identifiers and permission strings without wildcards (`*`).

Engineers MUST ALWAYS isolate native mobile commands into capability files under `src-tauri/capabilities/` explicitly specifying exact window identifiers and permission strings without wildcards (`*`).

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 serialize binary datasets (images, audio, blobs, tensors) into JSON Base64 strings or `Vec<u8>` numeric arrays (`[0, 1, ...]` across the IPC bridge.

Engineers MUST NOT serialize binary datasets (images, audio, blobs, tensors) into JSON Base64 strings or `Vec<u8>` numeric arrays (`[0, 1, ...]` across the IPC bridge.

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

Code SHOULD utilize `tauri

Code SHOULD utilize `tauri::ipc::Response::new(Vec<u8>)` in Rust commands to stream binary data directly to the webview as raw `ArrayBuffer` payloads.

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 scope remote and local origin access in capability declarations to verified mobile app origins (`mobile

Services MUST scope remote and local origin access in capability declarations to verified mobile app origins (`mobile:main`, explicit custom schemes).

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 native shell, un-sandboxed filesystem, or device OS commands without validating caller contexts against mobile runtime capability boundaries.

Components NEVER execute raw native shell, un-sandboxed filesystem, or device OS commands without validating caller contexts against mobile runtime capability boundaries.

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 Granular Capability Scoping & Zero-Copy IPC ArrayBuffer Protocol critical for AI coding assistants?

Enforce principle-of-least-privilege capability manifests and zero-copy binary IPC transfer protocols for Tauri 2.0 mobile targets. Wildcard window permissions expose device native features (camera, biometric, filesystem) to cross-site script injection, while serialized JSON byte transport causes extreme memory duplication and thermal throttling on mobile ARM chipsets. Native commands must use scoped capability ACLs and return binary buffers directly wrapped in Tauri IPC Responses. 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 (Exposing native OS host capabilities via wildcard permissions while transferring bulk binary data over JSON-serialized numeric arrays.) 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