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

Tauri 2.0 IPC Zero-Copy Binary Buffer & Origin Capability Guardrail

Enforces strict origin-scoped capability boundaries and zero-copy binary IPC pipelines across the Rust-to-Webview bridge in Tauri 2.0 mobile architectures. Eliminates main-thread IPC serialization lockups by mandating raw byte streams over JSON-base64 representations and prevents privilege escalation by strictly binding IPC command execution to explicit window labels and vetted webview origins.

Prohibited Anti-Pattern: Base64 JSON Serialization of Binary Buffers Combined with Wildcard IPC Origin Capabilities

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 IPC Zero-Copy Binary Buffer & Origin Capability Guardrail - Enforces strict origin-scoped capability boundaries and zero-copy binary IPC pipelines across the Rust-to-Webview bridge in Tauri 2.0 mobile architectures. Eliminates main-thread IPC serialization lockups by mandating raw byte streams over JSON-base64 representations and prevents privilege escalation by strictly binding IPC command execution to explicit window labels and vetted webview origins.
globs: src/**/*.{ts,tsx}, src-tauri/src/**/*.rs, src-tauri/capabilities/**/*.json, src-tauri/tauri.conf.json
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/tauri-v2-ipc-binary-origin-guardrail"
---

# Tauri 2.0 IPC Zero-Copy Binary Buffer & Origin Capability Guardrail

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Base64 JSON Serialization of Binary Buffers Combined with Wildcard IPC Origin Capabilities

## System Constraints
You are a Principal Software Architect enforcing high-performance zero-copy binary data transfers and zero-trust capability scoping in Tauri 2.0 applications. You must mandate raw binary IPC responses (via `tauri::ipc::Response`) over JSON/Base64 payloads to eliminate mobile webview memory pressure, and enforce rigorous origin verification via Tauri 2.0 capability files to prevent unauthorized IPC bridge access.

## Strict Guidelines
- Engineers MUST ALWAYS use `tauri::ipc::Response::new(vec)` in Rust and typed `ArrayBuffer` / `Uint8Array` in TypeScript for any binary transfers exceeding 4KB, avoiding serde_json serialization.
- Engineers MUST NOT configure capability files with wildcard windows (`windows: ["*"]`) or unvalidated remote origins when exposing privileged IPC commands.
- Code SHOULD leverage Tauri 2.0 Channel APIs or direct `ipc::Response` binary streaming for continuous or large-scale data transfers instead of discrete JSON invoke calls.
- Services MUST validate the calling WebviewWindow origin and execution context before processing IPC commands that interact with native mobile hardware or local storage.
- Components NEVER accept raw base64-encoded strings across the IPC bridge for image, audio, or database byte buffers.

## Bad vs Good Implementations
### Rust IPC Command: Zero-Copy Binary Response vs Base64 JSON Payload

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Serializing raw binary buffers to Base64 within a JSON payload consumes significant mobile CPU, triggers intensive garbage collection in the Webview JS thread, and stalls the main UI thread during frame rendering.
```rust
use tauri::command;
use serde::Serialize;

#[derive(Serialize)]
pub struct FilePayload {
    pub data: String, // Bad: Base64 string causes 33% payload blowup and IPC freeze
}

#[command]
pub async fn read_sensor_frame() -> Result<FilePayload, String> {
    let raw_bytes: Vec<u8> = acquire_hardware_frame();
    Ok(FilePayload {
        data: base64::encode(raw_bytes),
    })
}
```

#### Production Standard (Correct)
> **Standard**: Using `tauri::ipc::Response::new(raw_bytes)` bypasses JSON serialization entirely, streaming raw bytes directly into a Webview `ArrayBuffer` without memory overhead or base64 decoding stalls.
```rust
use tauri::{command, ipc::Response};

#[command]
pub async fn read_sensor_frame() -> Result<Response, String> {
    let raw_bytes: Vec<u8> = acquire_hardware_frame();
    // Good: Returns direct zero-copy byte stream over Tauri 2.0 binary IPC channel
    Ok(Response::new(raw_bytes))
}
```

### TypeScript IPC Invocation: Raw ArrayBuffer vs Base64 Decoding

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Manual base64 decoding in the UI thread via `atob` blocks user gestures and produces temporary string objects that heavily strain mobile memory garbage collection.
```typescript
import { invoke } from '@tauri-apps/api/core';

interface FrameResponse {
  data: string;
}

export async function getCameraBuffer(): Promise<Uint8Array> {
  // Bad: Invoking command expecting JSON and manually decoding base64
  const response = await invoke<FrameResponse>('read_sensor_frame');
  const binaryString = atob(response.data);
  const bytes = new Uint8Array(binaryString.length);
  for (let i = 0; i < binaryString.length; i++) {
    bytes[i] = binaryString.charCodeAt(i);
  }
  return bytes;
}
```

#### Production Standard (Correct)
> **Standard**: Invoking the command with an `ArrayBuffer` return type natively captures the raw binary bytes dispatched via Tauri 2.0's custom IPC protocol with zero UI thread overhead.
```typescript
import { invoke } from '@tauri-apps/api/core';

export async function getCameraBuffer(): Promise<Uint8Array> {
  // Good: Native zero-copy binary transfer directly resolves to ArrayBuffer
  const rawBuffer = await invoke<ArrayBuffer>('read_sensor_frame');
  return new Uint8Array(rawBuffer);
}
```

### Tauri 2.0 Capability Configuration: Origin Scoping vs Global Exposure

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using wildcard window declarations (`"*"`) allows any current or future window—including unvetted webviews or iframe contexts—to invoke sensitive native commands.
```json
{
  "$schema": "../gen/schemas/desktop-schema.json",
  "identifier": "sensor-capability",
  "description": "Insecure global capability",
  "windows": ["*"],
  "permissions": [
    "core:default",
    "allow-read-sensor-frame"
  ]
}
```

#### Production Standard (Correct)
> **Standard**: Scoping capabilities strictly to designated window identifiers (`"main"`) and specific mobile platforms ensures the principle of least privilege is preserved across the IPC bridge.
```json
{
  "$schema": "../gen/schemas/desktop-schema.json",
  "identifier": "sensor-capability",
  "description": "Strict origin-scoped capability",
  "windows": ["main"],
  "permissions": [
    "core:default",
    "allow-read-sensor-frame"
  ],
  "platforms": ["android", "iOS"]
}
```

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 IPC Zero-Copy Binary Buffer & Origin Capability Guardrail

Tauri 2.0 IPC Zero-Copy Binary Buffer & Origin Capability Guardrail defines an industrial-grade behavioral standard for mobile engineering. Enforces strict origin-scoped capability boundaries and zero-copy binary IPC pipelines across the Rust-to-Webview bridge in Tauri 2.0 mobile architectures. Eliminates main-thread IPC serialization lockups by mandating raw byte streams over JSON-base64 representations and prevents privilege escalation by strictly binding IPC command execution to explicit window labels and vetted webview origins. 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: Base64 JSON Serialization of Binary Buffers Combined with Wildcard IPC Origin Capabilities 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 DriftBase64 JSON Serialization of Binary Buffers Combined with Wildcard IPC Origin CapabilitiesCritical
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 use `tauri

Engineers MUST ALWAYS use `tauri::ipc::Response::new(vec)` in Rust and typed `ArrayBuffer` / `Uint8Array` in TypeScript for any binary transfers exceeding 4KB, avoiding serde_json serialization.

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 configure capability files with wildcard windows (`windows

Engineers MUST NOT configure capability files with wildcard windows (`windows: ["*"]`) or unvalidated remote origins when exposing privileged IPC commands.

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 leverage Tauri 2.0 Channel APIs or direct `ipc

Code SHOULD leverage Tauri 2.0 Channel APIs or direct `ipc::Response` binary streaming for continuous or large-scale data transfers instead of discrete JSON invoke calls.

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 the calling WebviewWindow origin and execution context before processing IPC commands that interact with native mobile hardware or local storage.

Services MUST validate the calling WebviewWindow origin and execution context before processing IPC commands that interact with native mobile hardware or local storage.

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 accept raw base64-encoded strings across the IPC bridge for image, audio, or database byte buffers.

Components NEVER accept raw base64-encoded strings across the IPC bridge for image, audio, or database byte buffers.

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 IPC Zero-Copy Binary Buffer & Origin Capability Guardrail critical for AI coding assistants?

Enforces strict origin-scoped capability boundaries and zero-copy binary IPC pipelines across the Rust-to-Webview bridge in Tauri 2.0 mobile architectures. Eliminates main-thread IPC serialization lockups by mandating raw byte streams over JSON-base64 representations and prevents privilege escalation by strictly binding IPC command execution to explicit window labels and vetted webview origins. 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 (Base64 JSON Serialization of Binary Buffers Combined with Wildcard IPC Origin Capabilities) 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