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

Tauri 2.0 Mobile IPC Ephemeral Capability Token Guardrail

Enforces single-use, cryptographically verified capability tokens for all Tauri 2.0 mobile IPC invocations across iOS and Android bridge boundaries. This prevents cross-site scripting (XSS) or hijacked webview contexts from abusing ambient bridge permissions to execute sensitive native device APIs, file system modifications, or hardware sensors without a validated, one-time execution grant. The native Rust layer verifies token entropy, lifespan, and caller bounds before immediately revoking the token from memory.

Prohibited Anti-Pattern: Ambient-Authority Mobile IPC Invocations Vulnerable to Webview Hijacking

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Mobile IPC Ephemeral Capability Token Guardrail - Enforces single-use, cryptographically verified capability tokens for all Tauri 2.0 mobile IPC invocations across iOS and Android bridge boundaries. This prevents cross-site scripting (XSS) or hijacked webview contexts from abusing ambient bridge permissions to execute sensitive native device APIs, file system modifications, or hardware sensors without a validated, one-time execution grant. The native Rust layer verifies token entropy, lifespan, and caller bounds before immediately revoking the token from memory.
globs: src-tauri/src/**/*.rs, src/**/*.ts, src/**/*.tsx
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/tauri-mobile-ipc-ephemeral-token-guardrail"
---

# Tauri 2.0 Mobile IPC Ephemeral Capability Token Guardrail

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Ambient-Authority Mobile IPC Invocations Vulnerable to Webview Hijacking

## System Constraints
You are a Principal Security Architect enforcing zero-trust IPC security in Tauri 2.0 mobile applications. Mandate that all native plugin commands requiring privileged mobile capabilities (e.g., biometric auth, keychain, camera, secure storage) require an ephemeral, single-use, cryptographically generated capability token minted by the Rust core and invalidated immediately upon first consumption. Prohibit naked, ambient-authority `invoke()` calls from frontend JavaScript or TypeScript code.

## Strict Guidelines
- Engineers MUST ALWAYS require a single-use ephemeral capability token for any Tauri IPC command interacting with mobile native plugins or sensitive subsystems.
- Engineers MUST NOT expose native mobile plugin methods with ambient, persistent authority or unauthenticated command handlers.
- Code SHOULD enforce strict cryptographic challenge-response or HMAC validation with a maximum token time-to-live (TTL) of 30 seconds before rejection.
- Services MUST atomically consume and invalidate the ephemeral token in Rust core memory before executing the requested native mobile routine to prevent replay attacks.
- Components NEVER store or cache capability tokens in webview-accessible state such as `localStorage`, `sessionStorage`, or global window variables.

## Bad vs Good Implementations
### Invoking Privileged Mobile IPC with Ephemeral Capability Token Verification

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Directly invokes the sensitive mobile plugin without proving current authorization or presenting an ephemeral cryptographic capability grant. If the webview is compromised via XSS or prototype pollution, the attacker has ambient authority to overwrite device secrets.
```typescript
import { invoke } from '@tauri-apps/api/core';

// CRITICAL SECURITY FLAW: Ambient authority invoke call.
// An XSS payload or rogue injected webview script can call this command at will
// with arbitrary payloads without native session validation.
export async function writeSecurePin(pin: string): Promise<void> {
  await invoke('plugin:secure-storage|set_pin', {
    pin,
  });
}
```

#### Production Standard (Correct)
> **Standard**: Requires an ephemeral, single-use capability token generated and cryptographically tracked by the Rust backend. The native plugin handler verifies the signature and burns the token instantly upon receipt, mitigating replay and bridge escalation attacks from compromised frontend scripts.
```typescript
import { invoke } from '@tauri-apps/api/core';

interface EphemeralGrant {
  tokenId: string;
  signature: string;
  expiresAt: number;
}

// SECURE: Capability token acquired via authenticated handshake, consumed once, and revoked.
export async function writeSecurePin(pin: string): Promise<void> {
  // 1. Request an ephemeral capability grant for the specific action
  const grant = await invoke<EphemeralGrant>('request_capability_token', {
    action: 'secure-storage:set_pin',
  });

  // 2. Transmit the single-use token along with the payload
  await invoke('plugin:secure-storage|set_pin', {
    pin,
    token: grant.tokenId,
    signature: grant.signature,
  });
}
```

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 Mobile IPC Ephemeral Capability Token Guardrail

Tauri 2.0 Mobile IPC Ephemeral Capability Token Guardrail defines an industrial-grade behavioral standard for mobile engineering. Enforces single-use, cryptographically verified capability tokens for all Tauri 2.0 mobile IPC invocations across iOS and Android bridge boundaries. This prevents cross-site scripting (XSS) or hijacked webview contexts from abusing ambient bridge permissions to execute sensitive native device APIs, file system modifications, or hardware sensors without a validated, one-time execution grant. The native Rust layer verifies token entropy, lifespan, and caller bounds before immediately revoking the token from memory. 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: Ambient-Authority Mobile IPC Invocations Vulnerable to Webview Hijacking 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 DriftAmbient-Authority Mobile IPC Invocations Vulnerable to Webview HijackingCritical
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 require a single-use ephemeral capability token for any Tauri IPC command interacting with mobile native plugins or sensitive subsystems.

Engineers MUST ALWAYS require a single-use ephemeral capability token for any Tauri IPC command interacting with mobile native plugins or sensitive subsystems.

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 native mobile plugin methods with ambient, persistent authority or unauthenticated command handlers.

Engineers MUST NOT expose native mobile plugin methods with ambient, persistent authority or unauthenticated command handlers.

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 strict cryptographic challenge-response or HMAC validation with a maximum token time-to-live (TTL) of 30 seconds before rejection.

Code SHOULD enforce strict cryptographic challenge-response or HMAC validation with a maximum token time-to-live (TTL) of 30 seconds before rejection.

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 atomically consume and invalidate the ephemeral token in Rust core memory before executing the requested native mobile routine to prevent replay attacks.

Services MUST atomically consume and invalidate the ephemeral token in Rust core memory before executing the requested native mobile routine to prevent replay attacks.

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 store or cache capability tokens in webview-accessible state such as `localStorage`, `sessionStorage`, or global window variables.

Components NEVER store or cache capability tokens in webview-accessible state such as `localStorage`, `sessionStorage`, or global window variables.

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 Mobile IPC Ephemeral Capability Token Guardrail critical for AI coding assistants?

Enforces single-use, cryptographically verified capability tokens for all Tauri 2.0 mobile IPC invocations across iOS and Android bridge boundaries. This prevents cross-site scripting (XSS) or hijacked webview contexts from abusing ambient bridge permissions to execute sensitive native device APIs, file system modifications, or hardware sensors without a validated, one-time execution grant. The native Rust layer verifies token entropy, lifespan, and caller bounds before immediately revoking the token from memory. 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 (Ambient-Authority Mobile IPC Invocations Vulnerable to Webview Hijacking) 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