This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: webauthn-prf-wasm-isolation-sandbox-standard

WebAuthn PRF Ephemeral Wasm Sandboxing & Memory Zeroization Standard

Mandates that raw cryptographic material derived via the WebAuthn PRF (Pseudo-Random Function) extension must immediately be ingested into an isolated, linear WebAssembly memory sandbox for key derivation and symmetric operations. Prohibits retaining raw PRF outputs or derived key material within the garbage-collected JavaScript heap, global state, or browser storage engines. Requires deterministic zeroization of linear Wasm memory immediately upon completion of cryptographic cycles to neutralize DOM-based memory scraping and XSS exfiltration.

Prohibited Anti-Pattern: Persisting Raw WebAuthn PRF Secrets in Garbage-Collected JavaScript Heap or Web Storage

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn PRF Ephemeral Wasm Sandboxing & Memory Zeroization Standard - Mandates that raw cryptographic material derived via the WebAuthn PRF (Pseudo-Random Function) extension must immediately be ingested into an isolated, linear WebAssembly memory sandbox for key derivation and symmetric operations. Prohibits retaining raw PRF outputs or derived key material within the garbage-collected JavaScript heap, global state, or browser storage engines. Requires deterministic zeroization of linear Wasm memory immediately upon completion of cryptographic cycles to neutralize DOM-based memory scraping and XSS exfiltration.
globs: src/**/crypto/**/*.{ts,tsx}, src/**/auth/**/*.{ts,tsx}, src/**/wasm/**/*.{ts,tsx}, src/**/vault/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-prf-wasm-isolation-sandbox-standard"
---

# WebAuthn PRF Ephemeral Wasm Sandboxing & Memory Zeroization Standard

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Persisting Raw WebAuthn PRF Secrets in Garbage-Collected JavaScript Heap or Web Storage

## System Constraints
You are a Principal Security Architect enforcing the WebAuthn PRF Extension Deterministic Key Derivation Sandbox Standard. Your mandate is to prevent the exfiltration of client-side encryption keys by strictly isolating all WebAuthn PRF outputs inside WebAssembly (Wasm) linear memory. You must reject any implementation that stores raw PRF entropy, intermediate HKDF outputs, or unmanaged symmetric keys in JavaScript variables, Vue/React/Svelte reactive states, closures, or browser storage APIs (localStorage, sessionStorage, IndexedDB). Ensure all JS-side ArrayBuffers touching PRF data are immediately zeroed using TypedArray.prototype.fill(0) after ingestion into Wasm, and mandate that Wasm modules expose and execute deterministic memory zeroization routines.

## Strict Guidelines
- Engineers MUST ALWAYS transfer raw WebAuthn PRF results (`AuthenticationExtensionsClientOutputs.prf.results.first`) directly into isolated WebAssembly linear memory (`WebAssembly.Memory`) via bounded pointer copies.
- Engineers MUST IMMEDIATELY zeroize the JavaScript-allocated Uint8Array/ArrayBuffer containing raw PRF entropy via `.fill(0)` immediately after copying it into the Wasm memory space.
- Engineers MUST NOT retain references to raw PRF outputs, HKDF intermediate master keys, or decrypted symmetric secrets in JS heap variables, React/Vue/Svelte states, global closures, or window contexts.
- Services MUST NEVER serialize WebAuthn PRF-derived secrets to `localStorage`, `sessionStorage`, `IndexedDB`, Web Workers without dedicated isolation, or DOM datasets.
- Components NEVER invoke `window.crypto.subtle.importKey` on raw PRF secrets in general V8 execution contexts where DOM-based XSS attacks can inspect heap or prototype overrides; cryptographic operations MUST remain inside the compiled Wasm boundary.
- Code MUST explicitly invoke a Wasm-exported zeroization method (e.g., `wasmInstance.exports.zeroize_memory(ptr, len)`) using constant-time memory wipes (e.g., `volatile` or `memset_s` semantics) as soon as encryption/decryption operations finalize.

## Bad vs Good Implementations
### Vulnerable: Retaining Raw PRF Output on V8 Garbage-Collected Heap

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Raw PRF derived bytes remain stored on the object instance within the V8 JavaScript heap. Non-deterministic garbage collection leaves sensitive cryptographic entropy resident in process memory for indeterminate intervals, creating a high-risk window for memory-inspection attacks, DOM-based prototype exfiltration, or crash-reporting leaks.
```typescript
export class VulnerableVaultManager {
  private cachedPrfKey: ArrayBuffer | null = null;

  async deriveAndStoreKey(credentialId: Uint8Array, salt: Uint8Array): Promise<CryptoKey> {
    const assertion = await navigator.credentials.get({
      publicKey: {
        challenge: crypto.getRandomValues(new Uint8Array(32)),
        allowCredentials: [{ id: credentialId, type: 'public-key' }],
        extensions: {
          prf: { eval: { first: salt } }
        }
      }
    }) as PublicKeyCredential;

    const prfOutput = assertion.getClientExtensionResults().prf?.results?.first;
    if (!prfOutput) throw new Error('PRF derivation failed');

    // CRITICAL SECURITY FLAW: Retaining raw PRF output in JavaScript heap.
    // V8 GC cannot guarantee deterministic deallocation; XSS or prototype pollution
    // can traverse the object graph or read GC scavenge buffers to exfiltrate keys.
    this.cachedPrfKey = prfOutput;

    return crypto.subtle.importKey(
      'raw',
      this.cachedPrfKey,
      { name: 'AES-GCM' },
      false,
      ['encrypt', 'decrypt']
    );
  }
}
```

#### Production Standard (Correct)
> **Standard**: Raw PRF entropy is copied into linear WebAssembly memory and the JavaScript view is immediately zeroized using `.fill(0)`. All symmetric operations are confined to the compiled Wasm boundary, and explicit zeroization methods are guaranteed via `finally` blocks, neutralizing DOM-based memory exfiltration.
```typescript
export interface WasmCryptoEngine {
  memory: WebAssembly.Memory;
  allocate(bytes: number): number;
  deallocate(ptr: number, bytes: number): void;
  decrypt_payload(keyPtr: number, keyLen: number, dataPtr: number, dataLen: number): number;
  zeroize(ptr: number, bytes: number): void;
}

export class SandboxedVaultManager {
  constructor(private wasm: WasmCryptoEngine) {}

  async executeSandboxedDecryption(
    credentialId: Uint8Array,
    salt: Uint8Array,
    ciphertext: Uint8Array
  ): Promise<Uint8Array> {
    const assertion = await navigator.credentials.get({
      publicKey: {
        challenge: crypto.getRandomValues(new Uint8Array(32)),
        allowCredentials: [{ id: credentialId, type: 'public-key' }],
        extensions: {
          prf: { eval: { first: salt } }
        }
      }
    }) as PublicKeyCredential;

    const prfResult = assertion.getClientExtensionResults().prf?.results?.first;
    if (!prfResult) throw new Error('WebAuthn PRF extension unavailable or denied');

    const jsPrfView = new Uint8Array(prfResult);
    const keyLen = jsPrfView.byteLength;
    const keyPtr = this.wasm.allocate(keyLen);

    try {
      // 1. Copy secret directly into isolated Wasm Linear Memory
      new Uint8Array(this.wasm.memory.buffer).set(jsPrfView, keyPtr);
    } finally {
      // 2. Deterministically scrub the JS heap memory immediately
      jsPrfView.fill(0);
    }

    const cipherLen = ciphertext.byteLength;
    const cipherPtr = this.wasm.allocate(cipherLen);
    new Uint8Array(this.wasm.memory.buffer).set(ciphertext, cipherPtr);

    try {
      // 3. Perform cryptographic computation strictly inside Wasm runtime
      const resultPtr = this.wasm.decrypt_payload(keyPtr, keyLen, cipherPtr, cipherLen);
      const plaintextLen = new DataView(this.wasm.memory.buffer).getUint32(resultPtr, true);
      return new Uint8Array(this.wasm.memory.buffer.slice(resultPtr + 4, resultPtr + 4 + plaintextLen));
    } finally {
      // 4. Guaranteed zeroization of the linear Wasm memory sandbox
      this.wasm.zeroize(keyPtr, keyLen);
      this.wasm.deallocate(keyPtr, keyLen);
      this.wasm.zeroize(cipherPtr, cipherLen);
      this.wasm.deallocate(cipherPtr, cipherLen);
    }
  }
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: WebAuthn PRF Ephemeral Wasm Sandboxing & Memory Zeroization Standard

WebAuthn PRF Ephemeral Wasm Sandboxing & Memory Zeroization Standard defines an industrial-grade behavioral standard for security engineering. Mandates that raw cryptographic material derived via the WebAuthn PRF (Pseudo-Random Function) extension must immediately be ingested into an isolated, linear WebAssembly memory sandbox for key derivation and symmetric operations. Prohibits retaining raw PRF outputs or derived key material within the garbage-collected JavaScript heap, global state, or browser storage engines. Requires deterministic zeroization of linear Wasm memory immediately upon completion of cryptographic cycles to neutralize DOM-based memory scraping and XSS exfiltration. 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: Persisting Raw WebAuthn PRF Secrets in Garbage-Collected JavaScript Heap or Web Storage 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 DriftPersisting Raw WebAuthn PRF Secrets in Garbage-Collected JavaScript Heap or Web StorageCritical
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 transfer raw WebAuthn PRF results (`AuthenticationExtensionsClientOutputs.prf.results.first`) directly into isolated WebAssembly linear memory (`WebAssembly.Memory`) via bounded pointer copies.

Engineers MUST ALWAYS transfer raw WebAuthn PRF results (`AuthenticationExtensionsClientOutputs.prf.results.first`) directly into isolated WebAssembly linear memory (`WebAssembly.Memory`) via bounded pointer copies.

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 IMMEDIATELY zeroize the JavaScript-allocated Uint8Array/ArrayBuffer containing raw PRF entropy via `.fill(0)` immediately after copying it into the Wasm memory space.

Engineers MUST IMMEDIATELY zeroize the JavaScript-allocated Uint8Array/ArrayBuffer containing raw PRF entropy via `.fill(0)` immediately after copying it into the Wasm memory space.

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 retain references to raw PRF outputs, HKDF intermediate master keys, or decrypted symmetric secrets in JS heap variables, React/Vue/Svelte states, global closures, or window contexts.

Engineers MUST NOT retain references to raw PRF outputs, HKDF intermediate master keys, or decrypted symmetric secrets in JS heap variables, React/Vue/Svelte states, global closures, or window contexts.

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 NEVER serialize WebAuthn PRF-derived secrets to `localStorage`, `sessionStorage`, `IndexedDB`, Web Workers without dedicated isolation, or DOM datasets.

Services MUST NEVER serialize WebAuthn PRF-derived secrets to `localStorage`, `sessionStorage`, `IndexedDB`, Web Workers without dedicated isolation, or DOM datasets.

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 invoke `window.crypto.subtle.importKey` on raw PRF secrets in general V8 execution contexts where DOM-based XSS attacks can inspect heap or prototype overrides

Components NEVER invoke `window.crypto.subtle.importKey` on raw PRF secrets in general V8 execution contexts where DOM-based XSS attacks can inspect heap or prototype overrides; cryptographic operations MUST remain inside the compiled Wasm boundary.

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

Code MUST explicitly invoke a Wasm-exported zeroization method (e.g., `wasmInstance.exports.zeroize_memory(ptr, len)`) using constant-time memory wipes (e.g., `volatile` or `memset_s` semantics) as soon as encryption/decryption operations finalize.

Code MUST explicitly invoke a Wasm-exported zeroization method (e.g., `wasmInstance.exports.zeroize_memory(ptr, len)`) using constant-time memory wipes (e.g., `volatile` or `memset_s` semantics) as soon as encryption/decryption operations finalize.

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 WebAuthn PRF Ephemeral Wasm Sandboxing & Memory Zeroization Standard critical for AI coding assistants?

Mandates that raw cryptographic material derived via the WebAuthn PRF (Pseudo-Random Function) extension must immediately be ingested into an isolated, linear WebAssembly memory sandbox for key derivation and symmetric operations. Prohibits retaining raw PRF outputs or derived key material within the garbage-collected JavaScript heap, global state, or browser storage engines. Requires deterministic zeroization of linear Wasm memory immediately upon completion of cryptographic cycles to neutralize DOM-based memory scraping and XSS exfiltration. 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 (Persisting Raw WebAuthn PRF Secrets in Garbage-Collected JavaScript Heap or Web Storage) 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

WebAuthn