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

Tauri 2.0 Deep Link Cryptographic Signature & Webview Ingestion Guardrails

Enforces cryptographic HMAC/Ed25519 signature validation and strict scheme/path canonicalization for all Tauri 2.0 deep links and app links prior to webview routing. Prevents malicious intent injection, path traversal, and unauthorized Tauri IPC command invocations initiated via untrusted external mobile application intents.

Prohibited Anti-Pattern: Direct Webview Routing of Unauthenticated and Unsanitized Mobile Deep Links

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Deep Link Cryptographic Signature & Webview Ingestion Guardrails - Enforces cryptographic HMAC/Ed25519 signature validation and strict scheme/path canonicalization for all Tauri 2.0 deep links and app links prior to webview routing. Prevents malicious intent injection, path traversal, and unauthorized Tauri IPC command invocations initiated via untrusted external mobile application intents.
globs: src-tauri/src/**/*.{rs}, src/**/*.{ts,tsx,js,jsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/tauri-v2-deep-link-signature-origin-sanitization"
---

# Tauri 2.0 Deep Link Cryptographic Signature & Webview Ingestion Guardrails

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Direct Webview Routing of Unauthenticated and Unsanitized Mobile Deep Links

## System Constraints
You are a Principal Security Architect enforcing secure deep link handling in Tauri 2.0 mobile applications (iOS and Android). Mandate that all incoming OS-level intent URIs are intercepted in the Rust core layer, authenticated via cryptographic HMAC/Ed25519 verification when containing sensitive payloads, strictly validated against an origin/path allowlist, and sanitized to prevent directory traversal before emission into the webview layer. Under no circumstances should unvalidated deep link parameters directly trigger Tauri IPC invoke commands or dynamic window navigation.

## Strict Guidelines
- Engineers MUST ALWAYS process deep links in the Rust host process (e.g., using `tauri-plugin-deep-link`) before forwarding payloads to the webview context.
- Engineers MUST cryptographically verify signatures (e.g., HMAC-SHA256 or Ed25519) on any deep link that authorizes sessions, triggers state mutations, or initiates IPC transactions.
- Engineers MUST NOT directly pass deep link query strings, hashes, or path segments into `window.location.assign`, React Router, or Tauri IPC `invoke` bindings without schema parsing (e.g., Zod) and path normalization.
- Rust and frontend handlers MUST reject URIs containing path traversal primitives (`..`, `//`, `\`, `%2e%2e`, `%2f`) and validate paths strictly against an explicit whitelist of route identifiers.
- Services MUST enforce expiration timestamps (`exp` or `nonce`) inside signed deep link payloads to mitigate replay attacks on mobile devices.
- Components NEVER execute raw JavaScript or evaluation strings embedded within deep link fragments or query parameters.

## Bad vs Good Implementations
### Unsafe Client-Side Deep Link Consumption vs. Authenticated Rust-Side Ingestion

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: This implementation processes raw deep links directly inside the webview without verifying origin authenticity or cryptographic signatures. An attacker can construct malicious custom URIs (or trigger them from hostile mobile apps) to execute arbitrary Tauri IPC handlers or initiate open redirects and path traversal.
```typescript
import { onOpenUrl } from '@tauri-apps/plugin-deep-link';
import { invoke } from '@tauri-apps/api/core';

// ANTI-PATTERN: Direct webview-side ingestion with path traversal and unverified IPC invocation
onOpenUrl(async (urls) => {
  for (const urlStr of urls) {
    const parsed = new URL(urlStr);
    const action = parsed.searchParams.get('action');
    const targetPath = parsed.searchParams.get('path');
    
    // Vulnerability: Blind execution of arbitrary IPC action based on external intent
    if (action) {
      await invoke(action, { payload: parsed.searchParams.get('data') });
    }
    
    // Vulnerability: Path traversal / open redirect inside webview
    if (targetPath) {
      window.location.href = `/${targetPath}`;
    }
  }
});
```

#### Production Standard (Correct)
> **Standard**: The production pattern enforces strict URL protocol checking, Zod schema validation against an explicit route whitelist, replay prevention with timestamp checks, and offloads cryptographic signature verification to the secure Rust backend before emitting any navigation events.
```typescript
import { onOpenUrl } from '@tauri-apps/plugin-deep-link';
import { invoke } from '@tauri-apps/api/core';
import { z } from 'zod';

const SafeDeepLinkPayloadSchema = z.object({
  route: z.enum(['dashboard', 'billing/invoice', 'settings']),
  id: z.string().uuid().optional(),
  signature: z.string().regex(/^[a-f0-9]{64}$/i),
  timestamp: z.number().int().positive()
});

type SafeDeepLinkPayload = z.infer<typeof SafeDeepLinkPayloadSchema>;

onOpenUrl(async (urls) => {
  for (const rawUrl of urls) {
    try {
      const parsed = new URL(rawUrl);
      
      if (parsed.protocol !== 'myapp:') {
        console.error('Unauthorized protocol:', parsed.protocol);
        continue;
      }

      const candidate = {
        route: parsed.pathname.replace(/^\/+/, ''),
        id: parsed.searchParams.get('id') ?? undefined,
        signature: parsed.searchParams.get('sig') ?? '',
        timestamp: Number(parsed.searchParams.get('ts') ?? 0)
      };

      const validated = SafeDeepLinkPayloadSchema.parse(candidate);

      // Replay prevention: reject links older than 60 seconds
      const now = Math.floor(Date.now() / 1000);
      if (Math.abs(now - validated.timestamp) > 60) {
        throw new Error('Deep link has expired');
      }

      // Invariant: Delegate cryptographic signature validation to Rust core
      const isVerified = await invoke<boolean>('verify_deep_link_hmac', {
        route: validated.route,
        id: validated.id ?? null,
        timestamp: validated.timestamp,
        signature: validated.signature
      });

      if (!isVerified) {
        throw new Error('Invalid deep link cryptographic signature');
      }

      // Safe state navigation via explicit whitelist routing
      window.dispatchEvent(new CustomEvent('app:navigate', { detail: validated.route }));
    } catch (err) {
      console.error('Rejected malicious or malformed deep link:', err);
    }
  }
});
```

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 Deep Link Cryptographic Signature & Webview Ingestion Guardrails

Tauri 2.0 Deep Link Cryptographic Signature & Webview Ingestion Guardrails defines an industrial-grade behavioral standard for mobile engineering. Enforces cryptographic HMAC/Ed25519 signature validation and strict scheme/path canonicalization for all Tauri 2.0 deep links and app links prior to webview routing. Prevents malicious intent injection, path traversal, and unauthorized Tauri IPC command invocations initiated via untrusted external mobile application intents. 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: Direct Webview Routing of Unauthenticated and Unsanitized Mobile Deep Links 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 DriftDirect Webview Routing of Unauthenticated and Unsanitized Mobile Deep LinksCritical
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 process deep links in the Rust host process (e.g., using `tauri-plugin-deep-link`) before forwarding payloads to the webview context.

Engineers MUST ALWAYS process deep links in the Rust host process (e.g., using `tauri-plugin-deep-link`) before forwarding payloads to the webview context.

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 cryptographically verify signatures (e.g., HMAC-SHA256 or Ed25519) on any deep link that authorizes sessions, triggers state mutations, or initiates IPC transactions.

Engineers MUST cryptographically verify signatures (e.g., HMAC-SHA256 or Ed25519) on any deep link that authorizes sessions, triggers state mutations, or initiates IPC transactions.

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

Engineers MUST NOT directly pass deep link query strings, hashes, or path segments into `window.location.assign`, React Router, or Tauri IPC `invoke` bindings without schema parsing (e.g., Zod) and path normalization.

Engineers MUST NOT directly pass deep link query strings, hashes, or path segments into `window.location.assign`, React Router, or Tauri IPC `invoke` bindings without schema parsing (e.g., Zod) and path normalization.

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

Rust and frontend handlers MUST reject URIs containing path traversal primitives (`..`, `//`, `\`, `%2e%2e`, `%2f`) and validate paths strictly against an explicit whitelist of route identifiers.

Rust and frontend handlers MUST reject URIs containing path traversal primitives (`..`, `//`, `\`, `%2e%2e`, `%2f`) and validate paths strictly against an explicit whitelist of route identifiers.

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

Services MUST enforce expiration timestamps (`exp` or `nonce`) inside signed deep link payloads to mitigate replay attacks on mobile devices.

Services MUST enforce expiration timestamps (`exp` or `nonce`) inside signed deep link payloads to mitigate replay attacks on mobile devices.

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.
6

Components NEVER execute raw JavaScript or evaluation strings embedded within deep link fragments or query parameters.

Components NEVER execute raw JavaScript or evaluation strings embedded within deep link fragments or query 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.
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 Deep Link Cryptographic Signature & Webview Ingestion Guardrails critical for AI coding assistants?

Enforces cryptographic HMAC/Ed25519 signature validation and strict scheme/path canonicalization for all Tauri 2.0 deep links and app links prior to webview routing. Prevents malicious intent injection, path traversal, and unauthorized Tauri IPC command invocations initiated via untrusted external mobile application intents. 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 (Direct Webview Routing of Unauthenticated and Unsanitized Mobile Deep Links) 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