This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: capacitor-7-biometric-secure-enclave-bridge-standard

Capacitor 7 Biometric Hardware-Backed Secure Enclave Bridge Standard

Enforces cryptographic isolation between the hybrid Capacitor WebView and native secure hardware (iOS Secure Enclave and Android KeyStore StrongBox). Mandates that raw private keys, biometrically unlocked symmetric secrets, and plain credentials never cross the bridge into the dynamic JavaScript DOM runtime, mitigating XSS, malicious deep-link invocations, and unauthorized WebView inspections.

Prohibited Anti-Pattern: Exporting Raw Private Keys or Cleartext Secrets Across the Capacitor Bridge into WebView Contexts

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Capacitor 7 Biometric Hardware-Backed Secure Enclave Bridge Standard - Enforces cryptographic isolation between the hybrid Capacitor WebView and native secure hardware (iOS Secure Enclave and Android KeyStore StrongBox). Mandates that raw private keys, biometrically unlocked symmetric secrets, and plain credentials never cross the bridge into the dynamic JavaScript DOM runtime, mitigating XSS, malicious deep-link invocations, and unauthorized WebView inspections.
globs: src/**/*.{ts,tsx,js,jsx}, ios/App/App/**/*.{swift,h,m}, android/app/src/main/java/**/*.{java,kt}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/capacitor-7-biometric-secure-enclave-bridge-standard"
---

# Capacitor 7 Biometric Hardware-Backed Secure Enclave Bridge Standard

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Exporting Raw Private Keys or Cleartext Secrets Across the Capacitor Bridge into WebView Contexts

## System Constraints
You are a Principal Mobile Security Architect enforcing the Capacitor 7 Biometric Hardware-Backed Secure Enclave Bridge Standard. You must mandate that raw cryptographic material, non-ephemeral authentication tokens, and private keys never cross the JavaScript-to-Native bridge. All cryptographic operations requiring biometrics (kSecAccessControlBiometryAny/BiometricPrompt) must execute strictly on-chip inside platform hardware enclaves. Deep-link handlers and dynamic WebView contexts must only receive one-time, opaque, ephemeral operation handles or cryptographic signatures verified on a remote backend.

## Strict Guidelines
- Engineers MUST ALWAYS enforce platform hardware-level attestation and key generation (kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly or Android KeyProperties.PURPOSE_SIGN with setUserAuthenticationRequired(true)).
- Engineers MUST NOT return raw private keys, plain master secrets, or unencrypted biometric payload strings across the Capacitor bridge to the WebView.
- Code SHOULD verify deep-link payload integrity and user presence before permitting the native layer to invoke biometric hardware signing operations.
- Services MUST execute all asymmetric signing and key derivation inside native code (Swift/Kotlin plugins), transmitting only ephemeral digital signatures or opaque session IDs to JavaScript.
- Components NEVER store biometrically unlocked cryptographic material in Capacitor Preferences, LocalStorage, IndexedDB, or memory-mapped JavaScript objects.

## Bad vs Good Implementations
### Biometric Authentication & Hardware-Bound Transaction Signing

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Exporting the raw cryptographic key or secret into the WebView DOM exposes it directly to Cross-Site Scripting (XSS), devtools inspection, memory dumps, and compromised dynamic dependencies.
```typescript
import { registerPlugin } from '@capacitor/core';

interface InsecureBiometricPlugin {
  // VULNERABILITY: Raw secret retrieved from Keychain across the bridge into DOM
  getBiometricSecret(options: { prompt: string }): Promise<{ privateKeyPem: string }>;
}

const InsecureVault = registerPlugin<InsecureBiometricPlugin>('InsecureVault');

export async function signPayload(payload: string): Promise<string> {
  const { privateKeyPem } = await InsecureVault.getBiometricSecret({
    prompt: 'Authorize Transaction'
  });
  // Any injected DOM script or XSS payload can intercept 'privateKeyPem'
  return localJsSign(payload, privateKeyPem);
}
```

#### Production Standard (Correct)
> **Standard**: Keeps private cryptographic keys locked within the Secure Enclave or Android StrongBox. The WebView passes an immutable challenge to the native layer, which prompts for biometrics and returns only the resulting signature, ensuring zero private material leakage.
```typescript
import { registerPlugin } from '@capacitor/core';

interface SecureBridgePlugin {
  // INVARIANT: Native side signs inside Enclave/KeyStore; raw keys never cross the bridge
  signWithHardwareKey(options: {
    challenge: string;
    promptMessage: string;
    allowedOrigin: string;
  }): Promise<{ signature: string; keyId: string }>;
}

const SecureBridge = registerPlugin<SecureBridgePlugin>('SecureEnclaveBridge');

export async function signPayload(challengeHex: string): Promise<{ signature: string; keyId: string }> {
  if (!/^[a-fA-F0-9]{64}$/.test(challengeHex)) {
    throw new Error('Invalid challenge format: must be 256-bit hex');
  }

  // Hardware-backed signing occurs entirely in native Swift/Kotlin
  return await SecureBridge.signWithHardwareKey({
    challenge: challengeHex,
    promptMessage: 'Confirm Authentication with Biometrics',
    allowedOrigin: window.location.origin
  });
}
```

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: Capacitor 7 Biometric Hardware-Backed Secure Enclave Bridge Standard

Capacitor 7 Biometric Hardware-Backed Secure Enclave Bridge Standard defines an industrial-grade behavioral standard for mobile engineering. Enforces cryptographic isolation between the hybrid Capacitor WebView and native secure hardware (iOS Secure Enclave and Android KeyStore StrongBox). Mandates that raw private keys, biometrically unlocked symmetric secrets, and plain credentials never cross the bridge into the dynamic JavaScript DOM runtime, mitigating XSS, malicious deep-link invocations, and unauthorized WebView inspections. 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: Exporting Raw Private Keys or Cleartext Secrets Across the Capacitor Bridge into WebView Contexts 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 DriftExporting Raw Private Keys or Cleartext Secrets Across the Capacitor Bridge into WebView ContextsCritical
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 enforce platform hardware-level attestation and key generation (kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly or Android KeyProperties.PURPOSE_SIGN with setUserAuthenticationRequired(true)).

Engineers MUST ALWAYS enforce platform hardware-level attestation and key generation (kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly or Android KeyProperties.PURPOSE_SIGN with setUserAuthenticationRequired(true)).

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 return raw private keys, plain master secrets, or unencrypted biometric payload strings across the Capacitor bridge to the WebView.

Engineers MUST NOT return raw private keys, plain master secrets, or unencrypted biometric payload strings across the Capacitor bridge to the WebView.

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 verify deep-link payload integrity and user presence before permitting the native layer to invoke biometric hardware signing operations.

Code SHOULD verify deep-link payload integrity and user presence before permitting the native layer to invoke biometric hardware signing 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 execute all asymmetric signing and key derivation inside native code (Swift/Kotlin plugins), transmitting only ephemeral digital signatures or opaque session IDs to JavaScript.

Services MUST execute all asymmetric signing and key derivation inside native code (Swift/Kotlin plugins), transmitting only ephemeral digital signatures or opaque session IDs to JavaScript.

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 biometrically unlocked cryptographic material in Capacitor Preferences, LocalStorage, IndexedDB, or memory-mapped JavaScript objects.

Components NEVER store biometrically unlocked cryptographic material in Capacitor Preferences, LocalStorage, IndexedDB, or memory-mapped JavaScript objects.

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 Capacitor 7 Biometric Hardware-Backed Secure Enclave Bridge Standard critical for AI coding assistants?

Enforces cryptographic isolation between the hybrid Capacitor WebView and native secure hardware (iOS Secure Enclave and Android KeyStore StrongBox). Mandates that raw private keys, biometrically unlocked symmetric secrets, and plain credentials never cross the bridge into the dynamic JavaScript DOM runtime, mitigating XSS, malicious deep-link invocations, and unauthorized WebView inspections. 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 (Exporting Raw Private Keys or Cleartext Secrets Across the Capacitor Bridge into WebView Contexts) 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

Capacitor