This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: tauri2-scoped-protocol-origin-poisoning-barrier

Tauri 2.0 Origin-Bound Custom Protocol Capability & Asset Isolation Guardrail

Enforces strict origin-bound verification, canonical path isolation, and capability verification on custom asset protocol handlers in Tauri 2.0 mobile webviews. Prevents cross-origin privilege escalation, directory traversal, and unauthorized capability execution across Android and iOS webview runtime contexts.

Prohibited Anti-Pattern: Unrestricted Custom Protocol Asset Fetching Permitting Webview Origin Spoofing and Arbitrary Sandbox Traversal

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Origin-Bound Custom Protocol Capability & Asset Isolation Guardrail - Enforces strict origin-bound verification, canonical path isolation, and capability verification on custom asset protocol handlers in Tauri 2.0 mobile webviews. Prevents cross-origin privilege escalation, directory traversal, and unauthorized capability execution across Android and iOS webview runtime contexts.
globs: src/**/*.{ts,tsx}, src-tauri/src/**/*.{rs,toml}, src-tauri/capabilities/**/*.json
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/tauri2-scoped-protocol-origin-poisoning-barrier"
---

# Tauri 2.0 Origin-Bound Custom Protocol Capability & Asset Isolation Guardrail

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Unrestricted Custom Protocol Asset Fetching Permitting Webview Origin Spoofing and Arbitrary Sandbox Traversal

## System Constraints
You are a Principal Security Architect enforcing Tauri 2.0 Scoped Custom Protocol Origin Poisoning Barriers on mobile platforms (Android/iOS). Mandate strict origin verification, canonical path sandboxing, and capability scope enforcement on all custom URI schemes and webview IPC bridges.

## Strict Guidelines
- Engineers MUST ALWAYS validate the Request Origin and Referer headers against the canonical mobile app origin (e.g., `tauri://localhost` on Android or custom bundled scheme on iOS) before resolving resources from custom protocols.
- Engineers MUST NOT configure custom protocol capability scopes with wildcard permissions (`**`) or resolve un-canonicalized relative paths containing directory traversal sequences (`../`).
- Code SHOULD utilize Tauri 2.0 `convertFileSrc` and scoped asset permissions rather than custom untyped string-interpolated URI handlers for local media and document access.
- Services MUST cryptographically isolate local file caches and databases behind capability permissions defined in Tauri 2.0 ACL manifests (`src-tauri/capabilities/`), denying ambient access to any webview context without explicit capability grant.
- Components NEVER bind untrusted webview contexts (such as third-party iframes or remote URLs) to custom protocol handlers or native mobile IPC plugins.

## Bad vs Good Implementations
### Enforcing Origin Validation and Canonical Path Scope in Custom Asset Resolvers

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Directly concatenating dynamic inputs into custom URI schemes without path normalization or origin verification enables path traversal and local file disclosure within the mobile webview's application sandbox.
```typescript
// Vulnerable: Dynamic custom protocol URL construction without origin verification or path traversal defense
export async function loadUserMedia(fileName: string): Promise<string> {
  // Anti-pattern: Untrusted input directly concatenated to custom protocol
  // Allows directory traversal: fileName = "../../../../data/data/com.app/databases/secret.db"
  const protocolUrl = `asset://localhost/${fileName}`;
  const response = await fetch(protocolUrl);
  return await response.text();
}
```

#### Production Standard (Correct)
> **Standard**: Validates the calling origin against Tauri mobile runtime origins, normalizes and confines the target path to an explicit subdirectory using path primitives, and leverages Tauri's core `convertFileSrc` API governed by scoped capability manifests.
```typescript
import { convertFileSrc } from '@tauri-apps/api/core';
import { appDataDir, join, normalize } from '@tauri-apps/api/path';

const TRUSTED_ORIGIN = 'tauri://localhost';

export async function loadUserMedia(fileName: string): Promise<string> {
  if (window.location.origin !== TRUSTED_ORIGIN && !window.location.origin.startsWith('http://tauri.localhost')) {
    throw new SecurityError('Origin verification failed: Unauthorized webview context');
  }

  const safeBaseDir = await appDataDir();
  const targetPath = await normalize(await join(safeBaseDir, 'media', fileName));
  
  // Defense-in-depth: Ensure target path remains strictly inside the designated media directory
  const expectedPrefix = await normalize(await join(safeBaseDir, 'media'));
  if (!targetPath.startsWith(expectedPrefix)) {
    throw new SecurityError('Path traversal attempt detected');
  }

  const secureAssetUrl = convertFileSrc(targetPath, 'asset');
  const response = await fetch(secureAssetUrl);
  
  if (!response.ok) {
    throw new Error(`Failed to load asset: ${response.statusText}`);
  }
  return await response.text();
}
```

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 Origin-Bound Custom Protocol Capability & Asset Isolation Guardrail

Tauri 2.0 Origin-Bound Custom Protocol Capability & Asset Isolation Guardrail defines an industrial-grade behavioral standard for mobile engineering. Enforces strict origin-bound verification, canonical path isolation, and capability verification on custom asset protocol handlers in Tauri 2.0 mobile webviews. Prevents cross-origin privilege escalation, directory traversal, and unauthorized capability execution across Android and iOS webview runtime 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: Unrestricted Custom Protocol Asset Fetching Permitting Webview Origin Spoofing and Arbitrary Sandbox Traversal 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 DriftUnrestricted Custom Protocol Asset Fetching Permitting Webview Origin Spoofing and Arbitrary Sandbox TraversalCritical
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 validate the Request Origin and Referer headers against the canonical mobile app origin (e.g., `tauri

Engineers MUST ALWAYS validate the Request Origin and Referer headers against the canonical mobile app origin (e.g., `tauri://localhost` on Android or custom bundled scheme on iOS) before resolving resources from custom protocols.

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 custom protocol capability scopes with wildcard permissions (`**`) or resolve un-canonicalized relative paths containing directory traversal sequences (`../`).

Engineers MUST NOT configure custom protocol capability scopes with wildcard permissions (`**`) or resolve un-canonicalized relative paths containing directory traversal sequences (`../`).

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 2.0 `convertFileSrc` and scoped asset permissions rather than custom untyped string-interpolated URI handlers for local media and document access.

Code SHOULD utilize Tauri 2.0 `convertFileSrc` and scoped asset permissions rather than custom untyped string-interpolated URI handlers for local media and document 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.
4

Services MUST cryptographically isolate local file caches and databases behind capability permissions defined in Tauri 2.0 ACL manifests (`src-tauri/capabilities/`), denying ambient access to any webview context without explicit capability grant.

Services MUST cryptographically isolate local file caches and databases behind capability permissions defined in Tauri 2.0 ACL manifests (`src-tauri/capabilities/`), denying ambient access to any webview context without explicit capability grant.

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 bind untrusted webview contexts (such as third-party iframes or remote URLs) to custom protocol handlers or native mobile IPC plugins.

Components NEVER bind untrusted webview contexts (such as third-party iframes or remote URLs) to custom protocol handlers or native mobile IPC plugins.

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 Origin-Bound Custom Protocol Capability & Asset Isolation Guardrail critical for AI coding assistants?

Enforces strict origin-bound verification, canonical path isolation, and capability verification on custom asset protocol handlers in Tauri 2.0 mobile webviews. Prevents cross-origin privilege escalation, directory traversal, and unauthorized capability execution across Android and iOS webview runtime 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 (Unrestricted Custom Protocol Asset Fetching Permitting Webview Origin Spoofing and Arbitrary Sandbox Traversal) 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