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

Tauri 2.0 Multi-WebView IPC Isolation & Dynamic Context Inheritance Guardrail

Enforces strict process sandboxing, capability scoping, and deterministic origin-scoped message port validation when spawning decoupled native child windows and embedded webviews in Tauri 2.0. Prevents untrusted frame elevation, privilege leaks across secondary webview contexts, and arbitrary IPC execution on mobile viewports. Guarantees that dynamically initialized contexts inherit exclusively minimized, cryptographically verifiable access boundaries.

Prohibited Anti-Pattern: Spawning Decoupled Secondary WebViews with Implicit Root IPC Capability Inheritance and Unfiltered PostMessage Handshakes

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Multi-WebView IPC Isolation & Dynamic Context Inheritance Guardrail - Enforces strict process sandboxing, capability scoping, and deterministic origin-scoped message port validation when spawning decoupled native child windows and embedded webviews in Tauri 2.0. Prevents untrusted frame elevation, privilege leaks across secondary webview contexts, and arbitrary IPC execution on mobile viewports. Guarantees that dynamically initialized contexts inherit exclusively minimized, cryptographically verifiable access boundaries.
globs: src-tauri/src/**/*.rs, src-tauri/capabilities/**/*.json, src/**/*.{ts,tsx,js,jsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/tauri-2-multi-webview-ipc-isolation-guardrail"
---

# Tauri 2.0 Multi-WebView IPC Isolation & Dynamic Context Inheritance Guardrail

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Spawning Decoupled Secondary WebViews with Implicit Root IPC Capability Inheritance and Unfiltered PostMessage Handshakes

## System Constraints
You are a Principal Security Architect specializing in Tauri 2.0 mobile security, native process isolation, and sandboxed embedded runtime environments. Your task is to enforce airtight IPC boundaries, explicit capability segregation, and deterministic origin validation across all multi-webview lifecycle operations. Reject any implementation where secondary webviews inherit full root application capabilities or lack deterministic origin isolation.

## Strict Guidelines
- Engineers MUST ALWAYS declare explicit Tauri 2.0 capability identifiers in separate JSON configuration files for each spawned window or embedded webview label.
- Engineers MUST NOT allow child webviews or external/dynamic URLs to inherit root window IPC endpoints, global event listeners, or wildcard '*' capabilities.
- Code SHOULD enforce deterministic origin-matching logic (`origin === window.location.origin`) and transfer MessagePorts with cryptographically signed session tokens before processing IPC payloads.
- Services MUST configure the `WebviewBuilder` in Rust or the Webview API in TypeScript with `with_ipc(false)` or explicit initialization scripts when loading untrusted, external, or third-party web contexts.
- Components NEVER execute raw `invoke()` calls within a shared child webview context without checking the runtime origin context and assigned capability permissions.

## Bad vs Good Implementations
### Decoupled Webview Spawn with Scoped Capabilities & Origin Validation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The child window is spawned without isolating capabilities, allowing malicious or compromised webview content to access native Tauri APIs. The postMessage handler lacks origin verification, creating a severe remote code execution / native invoke vulnerability for untrusted contexts.
```typescript
import { WebviewWindow } from '@tauri-apps/api/webviewWindow';
import { listen } from '@tauri-apps/api/event';

// ANTI-PATTERN: Spawns secondary webview with full ambient IPC access,
// wildcard origin messaging, and unverified postMessage bridge inheritance.
export async function openChildView(url: string, label: string) {
  const child = new WebviewWindow(label, {
    url: url,
    // Missing explicit capability decoupling; child inherits root privileges
  });

  // Insecure wildcard postMessage listener allowing cross-frame injection
  window.addEventListener('message', async (event) => {
    if (event.data?.action === 'execute-native-command') {
      // Exposing native invoke blindly to external child window
      const { invoke } = await import('@tauri-apps/api/core');
      await invoke(event.data.command, event.data.payload);
    }
  });

  return child;
}
```

#### Production Standard (Correct)
> **Standard**: Validates the target path strictly against expected origin boundaries, enables incognito isolation to prevent storage cross-contamination on mobile platforms, and implements an origin-checked handshake with a cryptographic nonce before binding inter-frame communications.
```typescript
import { WebviewWindow } from '@tauri-apps/api/webviewWindow';

interface SecureHandshakePayload {
  nonce: string;
  action: 'sync-ready';
}

// PRODUCTION INVARIANT: Explicit origin boundary, transient token handshake,
// and strict capability-scoped isolation for decoupled child webviews.
export async function openChildViewSecurely(
  targetPath: string,
  label: string,
  expectedOrigin: string,
  sessionNonce: string
): Promise<WebviewWindow> {
  if (!targetPath.startsWith('/') && !targetPath.startsWith(expectedOrigin)) {
    throw new Error(`Security Violation: Target path does not conform to expected origin ${expectedOrigin}`);
  }

  const child = new WebviewWindow(label, {
    url: targetPath,
    incognito: true,
    // Ensures mobile viewports stay sandboxed from parent storage & state
  });

  const messageHandler = (event: MessageEvent<SecureHandshakePayload>): void => {
    // Deterministic origin validation
    if (event.origin !== expectedOrigin) {
      return;
    }
    // Cryptographic single-use nonce validation before establishing bridge
    if (event.data?.nonce !== sessionNonce || event.data?.action !== 'sync-ready') {
      return;
    }

    // Clean up transient handshake listener immediately
    window.removeEventListener('message', messageHandler);
  };

  window.addEventListener('message', messageHandler);
  return child;
}
```

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 Multi-WebView IPC Isolation & Dynamic Context Inheritance Guardrail

Tauri 2.0 Multi-WebView IPC Isolation & Dynamic Context Inheritance Guardrail defines an industrial-grade behavioral standard for mobile engineering. Enforces strict process sandboxing, capability scoping, and deterministic origin-scoped message port validation when spawning decoupled native child windows and embedded webviews in Tauri 2.0. Prevents untrusted frame elevation, privilege leaks across secondary webview contexts, and arbitrary IPC execution on mobile viewports. Guarantees that dynamically initialized contexts inherit exclusively minimized, cryptographically verifiable access boundaries. 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: Spawning Decoupled Secondary WebViews with Implicit Root IPC Capability Inheritance and Unfiltered PostMessage Handshakes 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 DriftSpawning Decoupled Secondary WebViews with Implicit Root IPC Capability Inheritance and Unfiltered PostMessage HandshakesCritical
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 declare explicit Tauri 2.0 capability identifiers in separate JSON configuration files for each spawned window or embedded webview label.

Engineers MUST ALWAYS declare explicit Tauri 2.0 capability identifiers in separate JSON configuration files for each spawned window or embedded webview label.

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 allow child webviews or external/dynamic URLs to inherit root window IPC endpoints, global event listeners, or wildcard '*' capabilities.

Engineers MUST NOT allow child webviews or external/dynamic URLs to inherit root window IPC endpoints, global event listeners, or wildcard '*' 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

Code SHOULD enforce deterministic origin-matching logic (`origin === window.location.origin`) and transfer MessagePorts with cryptographically signed session tokens before processing IPC payloads.

Code SHOULD enforce deterministic origin-matching logic (`origin === window.location.origin`) and transfer MessagePorts with cryptographically signed session tokens before processing IPC 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 configure the `WebviewBuilder` in Rust or the Webview API in TypeScript with `with_ipc(false)` or explicit initialization scripts when loading untrusted, external, or third-party web contexts.

Services MUST configure the `WebviewBuilder` in Rust or the Webview API in TypeScript with `with_ipc(false)` or explicit initialization scripts when loading untrusted, external, or third-party web 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.
5

Components NEVER execute raw `invoke()` calls within a shared child webview context without checking the runtime origin context and assigned capability permissions.

Components NEVER execute raw `invoke()` calls within a shared child webview context without checking the runtime origin context and assigned capability permissions.

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 Multi-WebView IPC Isolation & Dynamic Context Inheritance Guardrail critical for AI coding assistants?

Enforces strict process sandboxing, capability scoping, and deterministic origin-scoped message port validation when spawning decoupled native child windows and embedded webviews in Tauri 2.0. Prevents untrusted frame elevation, privilege leaks across secondary webview contexts, and arbitrary IPC execution on mobile viewports. Guarantees that dynamically initialized contexts inherit exclusively minimized, cryptographically verifiable access boundaries. 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 (Spawning Decoupled Secondary WebViews with Implicit Root IPC Capability Inheritance and Unfiltered PostMessage Handshakes) 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