This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: tauri-v2-dynamic-ipc-canonical-path-resolution

Tauri 2.0 Dynamic IPC Capability Canonical Path Resolution

Enforces strict canonical path resolution and cryptographically verified runtime scope enforcement for Tauri 2.0 IPC invocations involving filesystem access. Eliminates symlink-based path traversal and Time-of-Check to Time-of-Use (TOCTOU) exploits by validating fully resolved, real canonical paths against authorized capability scopes on the Rust backend prior to executing any file I/O operations.

Prohibited Anti-Pattern: Trusting Raw Frontend-Supplied File Paths in Tauri IPC Commands Without Backend Canonicalization and Scope Re-Verification

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Dynamic IPC Capability Canonical Path Resolution - Enforces strict canonical path resolution and cryptographically verified runtime scope enforcement for Tauri 2.0 IPC invocations involving filesystem access. Eliminates symlink-based path traversal and Time-of-Check to Time-of-Use (TOCTOU) exploits by validating fully resolved, real canonical paths against authorized capability scopes on the Rust backend prior to executing any file I/O operations.
globs: src-tauri/src/**/*.rs, src-tauri/capabilities/**/*.json, src/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/tauri-v2-dynamic-ipc-canonical-path-resolution"
---

# Tauri 2.0 Dynamic IPC Capability Canonical Path Resolution

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Trusting Raw Frontend-Supplied File Paths in Tauri IPC Commands Without Backend Canonicalization and Scope Re-Verification

## System Constraints
You are a Principal Security Architect enforcing Tauri 2.0 Dynamic IPC Capability Canonical Path Resolution. Mandate that every filesystem operation initiated through Tauri 2.0 IPC undergoes strict backend canonicalization (dangling symlink resolution, traversal normalization via std::fs::canonicalize or dunce) and explicit validation against Tauri capability runtime scopes before opening file handles. Reject all client-side path sanitization assumptions.

## Strict Guidelines
- Engineers MUST ALWAYS resolve and canonicalize incoming paths using std::fs::canonicalize or dunce::canonicalize on the Rust backend before checking authorization scopes.
- Engineers MUST NOT rely on frontend validation, tauri::path::resolve, or raw path string matching to determine filesystem permissions.
- Code MUST re-verify that the canonical path resides strictly within the allowed capability scope prefix using tauri::ipc or custom scope matching before performing any read, write, or execute operations.
- Services MUST reject paths containing symlinks that resolve outside the sandboxed application directory or explicitly permitted capability boundaries.
- Components NEVER expose arbitrary read/write commands taking unconstrained String or PathBuf arguments without runtime tauri::AppHandle capability validation.

## Bad vs Good Implementations
### Vulnerable Raw Path Access vs Canonical Scope-Guarded Resolution in Tauri 2.0 Command

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The Rust backend accepts a raw PathBuf from the webview and directly invokes filesystem operations without resolving symlinks or validating the target against configured Tauri 2.0 runtime scopes, enabling path traversal and arbitrary file reads.
```rust
use std::path::PathBuf;
use tauri::command;

#[command]
pub async fn read_user_document(raw_path: PathBuf) -> Result<String, String> {
    // VULNERABLE: Direct access using unsanitized client-provided path
    // Allows symlink traversal and relative path traversal (e.g., ../../../etc/shadow)
    std::fs::read_to_string(&raw_path).map_err(|e| e.to_string())
}
```

#### Production Standard (Correct)
> **Standard**: The secure implementation neutralizes symlinks using dunce::canonicalize and verifies that the canonical path strictly starts with the canonicalized authorized scope directory before executing file operations, preventing TOCTOU and symlink-based traversal.
```rust
use std::path::{Path, PathBuf};
use tauri::{command, AppHandle, Manager, Runtime};

#[command]
pub async fn read_user_document<R: Runtime>(
    app: AppHandle<R>,
    untrusted_path: PathBuf,
) -> Result<String, String> {
    // 1. Resolve canonical path to neutralize symlinks, relative traversal, and junction points
    let canonical_path = dunce::canonicalize(&untrusted_path)
        .map_err(|_| "Invalid or non-existent file path".to_string())?;

    // 2. Fetch authorized document directory from Tauri app paths
    let app_docs_dir = app.path().document_dir()
        .map_err(|e| e.to_string())?;
    let canonical_scope = dunce::canonicalize(&app_docs_dir)
        .map_err(|_| "Failed to resolve capability scope".to_string())?;

    // 3. Ensure the fully resolved path is strictly within the allowed capability scope
    if !canonical_path.starts_with(&canonical_scope) {
        return Err("Access Denied: Path escapes authorized capability scope".to_string());
    }

    // 4. Perform bounded file I/O on validated canonical path
    std::fs::read_to_string(&canonical_path).map_err(|e| e.to_string())
}
```

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 Dynamic IPC Capability Canonical Path Resolution

Tauri 2.0 Dynamic IPC Capability Canonical Path Resolution defines an industrial-grade behavioral standard for security engineering. Enforces strict canonical path resolution and cryptographically verified runtime scope enforcement for Tauri 2.0 IPC invocations involving filesystem access. Eliminates symlink-based path traversal and Time-of-Check to Time-of-Use (TOCTOU) exploits by validating fully resolved, real canonical paths against authorized capability scopes on the Rust backend prior to executing any file I/O operations. 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: Trusting Raw Frontend-Supplied File Paths in Tauri IPC Commands Without Backend Canonicalization and Scope Re-Verification 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 DriftTrusting Raw Frontend-Supplied File Paths in Tauri IPC Commands Without Backend Canonicalization and Scope Re-VerificationCritical
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 resolve and canonicalize incoming paths using std

Engineers MUST ALWAYS resolve and canonicalize incoming paths using std::fs::canonicalize or dunce::canonicalize on the Rust backend before checking authorization scopes.

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 rely on frontend validation, tauri

Engineers MUST NOT rely on frontend validation, tauri::path::resolve, or raw path string matching to determine filesystem 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.
3

Code MUST re-verify that the canonical path resides strictly within the allowed capability scope prefix using tauri

Code MUST re-verify that the canonical path resides strictly within the allowed capability scope prefix using tauri::ipc or custom scope matching before performing any read, write, or execute operations.

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 reject paths containing symlinks that resolve outside the sandboxed application directory or explicitly permitted capability boundaries.

Services MUST reject paths containing symlinks that resolve outside the sandboxed application directory or explicitly permitted 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.
5

Components NEVER expose arbitrary read/write commands taking unconstrained String or PathBuf arguments without runtime tauri

Components NEVER expose arbitrary read/write commands taking unconstrained String or PathBuf arguments without runtime tauri::AppHandle capability validation.

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 Dynamic IPC Capability Canonical Path Resolution critical for AI coding assistants?

Enforces strict canonical path resolution and cryptographically verified runtime scope enforcement for Tauri 2.0 IPC invocations involving filesystem access. Eliminates symlink-based path traversal and Time-of-Check to Time-of-Use (TOCTOU) exploits by validating fully resolved, real canonical paths against authorized capability scopes on the Rust backend prior to executing any file I/O operations. 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 (Trusting Raw Frontend-Supplied File Paths in Tauri IPC Commands Without Backend Canonicalization and Scope Re-Verification) 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.

1 Rule in Stack

Tauri