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

Tauri 2.0 Context-Isolated Multi-WebView IPC Contract

Enforces strict origin-based ACL boundary separation and zero-trust event sanitization across Tauri 2.0 multi-webview mobile runtimes. Prevents untrusted secondary or remote webviews from accessing privileged native IPC channels and host bindings.

Prohibited Anti-Pattern: Exposing Raw Native IPC Bridges to Untrusted Secondary WebViews Without Origin Checks and Strict Schema Validation

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Context-Isolated Multi-WebView IPC Contract - Enforces strict origin-based ACL boundary separation and zero-trust event sanitization across Tauri 2.0 multi-webview mobile runtimes. Prevents untrusted secondary or remote webviews from accessing privileged native IPC channels and host bindings.
globs: src-tauri/capabilities/**/*.json, src-tauri/tauri.conf.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-multi-webview-ipc-isolation"
---

# Tauri 2.0 Context-Isolated Multi-WebView IPC Contract

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Exposing Raw Native IPC Bridges to Untrusted Secondary WebViews Without Origin Checks and Strict Schema Validation

## System Constraints
You are a Principal Software Architect enforcing Tauri 2.0 Multi-WebView Context-Isolated IPC Contracts. Mandate zero-trust communication across all webview instances. Ensure that remote or secondary mobile webviews are physically segregated from native Tauri host capabilities, enforcing origin verification and cryptographic message validation at every boundary.

## Strict Guidelines
- Engineers MUST ALWAYS isolate untrusted or remote webviews by assigning explicit, minimal capability profiles in 'src-tauri/capabilities/' that deny default core IPC access.
- Engineers MUST NOT expose '@tauri-apps/api' or '__TAURI_INTERNALS__' to external web domains or unauthenticated secondary webview contexts.
- Code SHOULD validate origin headers and enforce strict schema parsing (e.g., Zod, ArkType) on all bridge messages before invoking native commands.
- Services MUST verify the calling WebviewWindow label inside native Rust command handlers via 'tauri::ipc::Request' or 'tauri::WebviewWindow' parameters.
- Components NEVER blindly forward 'window.addEventListener("message", ...)' payloads directly into Tauri's 'invoke()' or 'emit()' pipelines.

## Bad vs Good Implementations
### Untrusted Multi-WebView IPC Bridge Message Relaying

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Listens indiscriminately to global window messages without checking event.origin or validating message structure with a runtime schema, allowing untrusted third-party frames or secondary remote webviews to invoke arbitrary host capabilities.
```typescript
import { invoke } from '@tauri-apps/api/core';

// CRITICAL FLAW: Blindly accepting messages from any frame/origin and executing native invoke
window.addEventListener('message', async (event) => {
  const { command, payload } = event.data;
  // Any untrusted remote webview can trigger privileged host operations
  const result = await invoke(command, payload);
  if (event.source && 'postMessage' in event.source) {
    (event.source as Window).postMessage({ result }, '*');
  }
});
```

#### Production Standard (Correct)
> **Standard**: Enforces strict origin checking against the authorized origin, sanitizes all incoming payloads using Zod before invoking native commands, namespaces native actions to isolated operations, and uses explicit targetOrigin on responses.
```typescript
import { invoke } from '@tauri-apps/api/core';
import { z } from 'zod';

const TRUSTED_ORIGIN = 'tauri://localhost';

const BridgePayloadSchema = z.object({
  nonce: z.string().uuid(),
  action: z.enum(['read_cached_session', 'request_view_dismiss']),
  data: z.record(z.unknown())
});

type BridgePayload = z.infer<typeof BridgePayloadSchema>;

window.addEventListener('message', async (event: MessageEvent) => {
  // Invariant 1: Hardware/Origin Isolation Boundary Check
  if (event.origin !== TRUSTED_ORIGIN) {
    console.error(`Rejected unauthorized IPC relay attempt from origin: ${event.origin}`);
    return;
  }

  // Invariant 2: Zero-Trust Runtime Schema Validation
  const parseResult = BridgePayloadSchema.safeParse(event.data);
  if (!parseResult.success) {
    console.error('Invalid IPC message structure', parseResult.error.format());
    return;
  }

  const { action, data, nonce } = parseResult.data;

  try {
    // Invariant 3: Strictly Scoped Native Command Dispatch
    const result = await invoke(`isolated_${action}`, { payload: data, nonce });
    
    if (event.source && 'postMessage' in event.source) {
      (event.source as Window).postMessage(
        { nonce, ok: true, result },
        { targetOrigin: TRUSTED_ORIGIN }
      );
    }
  } catch (error) {
    if (event.source && 'postMessage' in event.source) {
      (event.source as Window).postMessage(
        { nonce, ok: false, error: (error as Error).message },
        { targetOrigin: TRUSTED_ORIGIN }
      );
    }
  }
});
```

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 Context-Isolated Multi-WebView IPC Contract

Tauri 2.0 Context-Isolated Multi-WebView IPC Contract defines an industrial-grade behavioral standard for mobile engineering. Enforces strict origin-based ACL boundary separation and zero-trust event sanitization across Tauri 2.0 multi-webview mobile runtimes. Prevents untrusted secondary or remote webviews from accessing privileged native IPC channels and host bindings. 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 Raw Native IPC Bridges to Untrusted Secondary WebViews Without Origin Checks and Strict Schema Validation 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 Raw Native IPC Bridges to Untrusted Secondary WebViews Without Origin Checks and Strict Schema ValidationCritical
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 untrusted or remote webviews by assigning explicit, minimal capability profiles in 'src-tauri/capabilities/' that deny default core IPC access.

Engineers MUST ALWAYS isolate untrusted or remote webviews by assigning explicit, minimal capability profiles in 'src-tauri/capabilities/' that deny default core IPC access.

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 expose '@tauri-apps/api' or '__TAURI_INTERNALS__' to external web domains or unauthenticated secondary webview contexts.

Engineers MUST NOT expose '@tauri-apps/api' or '__TAURI_INTERNALS__' to external web domains or unauthenticated secondary 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

Code SHOULD validate origin headers and enforce strict schema parsing (e.g., Zod, ArkType) on all bridge messages before invoking native commands.

Code SHOULD validate origin headers and enforce strict schema parsing (e.g., Zod, ArkType) on all bridge messages before invoking native 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.
4

Services MUST verify the calling WebviewWindow label inside native Rust command handlers via 'tauri

Services MUST verify the calling WebviewWindow label inside native Rust command handlers via 'tauri::ipc::Request' or 'tauri::WebviewWindow' parameters.

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 blindly forward 'window.addEventListener("message", ...)' payloads directly into Tauri's 'invoke()' or 'emit()' pipelines.

Components NEVER blindly forward 'window.addEventListener("message", ...)' payloads directly into Tauri's 'invoke()' or 'emit()' pipelines.

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 Context-Isolated Multi-WebView IPC Contract critical for AI coding assistants?

Enforces strict origin-based ACL boundary separation and zero-trust event sanitization across Tauri 2.0 multi-webview mobile runtimes. Prevents untrusted secondary or remote webviews from accessing privileged native IPC channels and host bindings. 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 Raw Native IPC Bridges to Untrusted Secondary WebViews Without Origin Checks and Strict Schema Validation) 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