This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: webauthn-l3-prf-hardware-key-derivation-invariant

WebAuthn Level 3 PRF Extension Hardware Key-Derivation Invariant

Enforces zero-knowledge client-side encryption key derivation via WebAuthn Level 3 PRF (Pseudo-Random Function) authenticator outputs. Guarantees raw hardware-derived cryptographic seeds are immediately imported as non-extractable Web Crypto handles, memory buffers are explicitly zeroized, and intermediate keying material is never serialized or transmitted across boundaries.

Prohibited Anti-Pattern: Exposing, serializing, or retaining raw WebAuthn PRF output buffers instead of immediate non-extractable CryptoKey ingestion and memory wiping

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn Level 3 PRF Extension Hardware Key-Derivation Invariant - Enforces zero-knowledge client-side encryption key derivation via WebAuthn Level 3 PRF (Pseudo-Random Function) authenticator outputs. Guarantees raw hardware-derived cryptographic seeds are immediately imported as non-extractable Web Crypto handles, memory buffers are explicitly zeroized, and intermediate keying material is never serialized or transmitted across boundaries.
globs: src/**/*.{ts,tsx}, lib/**/*.{ts,tsx}, services/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-l3-prf-hardware-key-derivation-invariant"
---

# WebAuthn Level 3 PRF Extension Hardware Key-Derivation Invariant

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Exposing, serializing, or retaining raw WebAuthn PRF output buffers instead of immediate non-extractable CryptoKey ingestion and memory wiping

## System Constraints
You are a Principal Security Architect enforcing the WebAuthn Level 3 PRF Hardware Key-Derivation Invariant. Your objective is to ensure that all client-side cryptographic key derivations utilizing the WebAuthn PRF extension treat raw PRF outputs as ephemeral, high-entropy secrets. You must enforce immediate encapsulation into non-extractable Web Crypto keys, explicit zeroization of intermediate ArrayBuffers, and strict prevention of key leakage via memory, logs, local persistence, or network transmission.

## Strict Guidelines
- Engineers MUST ALWAYS request PRF extension outputs using typed, deterministic 32-byte salts within `navigator.credentials.get()`.
- Engineers MUST NOT transmit raw PRF extension outputs or intermediate keying material over HTTP, WebSockets, IPC, or log them to consoles.
- Engineers MUST ALWAYS immediately import raw PRF outputs into the Web Crypto API (`crypto.subtle.importKey`) with `extractable: false`.
- Code MUST explicitly zeroize the ephemeral raw `Uint8Array` or `ArrayBuffer` PRF output immediately following `crypto.subtle.importKey` consumption.
- Services MUST derive application-specific encryption keys (e.g., AES-GCM) strictly using HKDF or PBKDF2 passing explicit context labels and info strings.
- Derived application encryption keys MUST be marked `extractable: false` to prevent programmatic memory extraction by browser extensions or XSS payloads.
- Components NEVER persist PRF results, derived key bytes, or master secrets to `localStorage`, `sessionStorage`, `IndexedDB`, or browser state managers.

## Bad vs Good Implementations
### Insecure PRF Output Handling (Extraction and Storage)

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Raw hardware PRF output is extracted into a garbage-collected immutable string, cached in localStorage, and exposed to XSS and memory-scraping attacks. The raw seed is never encapsulated in Web Crypto and buffers are left intact in memory.
```typescript
export async function deriveKeyFromAuthenticator(credentialId: BufferSource, salt: Uint8Array): Promise<string> {
  const credential = 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 extensionResults = credential.getClientExtensionResults();
  const rawPrf = extensionResults.prf?.results?.first;
  if (!rawPrf) throw new Error('PRF unsupported');

  // CRITICAL VULNERABILITY: Converting raw PRF seed to hex, retaining in string memory,
  // and persisting hardware master entropy to client-side unencrypted storage.
  const hexSeed = Array.from(new Uint8Array(rawPrf))
    .map((b) => b.toString(16).padStart(2, '0'))
    .join('');
  localStorage.setItem('user_master_seed', hexSeed);
  return hexSeed;
}
```

#### Production Standard (Correct)
> **Standard**: The hardware PRF output is imported as an unextractable HKDF key handle, used to derive a scoped AES-GCM key with domain separation, and the original raw buffer is explicitly zeroized in a finally block to prevent memory retention.
```typescript
export async function deriveHardwareBoundKey(
  credentialId: BufferSource,
  salt: Uint8Array,
  info: Uint8Array
): Promise<CryptoKey> {
  const credential = (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 prfResults = credential.getClientExtensionResults().prf?.results;
  if (!prfResults?.first) {
    throw new Error('Authenticator did not return PRF output');
  }

  // Copy to a mutable view for mandatory zeroization
  const rawOutput = new Uint8Array(prfResults.first.slice(0));
  let masterPrfKey: CryptoKey | null = null;

  try {
    masterPrfKey = await crypto.subtle.importKey(
      'raw',
      rawOutput,
      'HKDF',
      false, // non-extractable
      ['deriveKey']
    );

    return await crypto.subtle.deriveKey(
      {
        name: 'HKDF',
        hash: 'SHA-256',
        salt: salt,
        info: info,
      },
      masterPrfKey,
      { name: 'AES-GCM', length: 256 },
      false, // non-extractable
      ['encrypt', 'decrypt']
    );
  } finally {
    // Wipe the raw hardware PRF output buffer immediately from memory
    rawOutput.fill(0);
    masterPrfKey = null;
  }
}
```

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: WebAuthn Level 3 PRF Extension Hardware Key-Derivation Invariant

WebAuthn Level 3 PRF Extension Hardware Key-Derivation Invariant defines an industrial-grade behavioral standard for security engineering. Enforces zero-knowledge client-side encryption key derivation via WebAuthn Level 3 PRF (Pseudo-Random Function) authenticator outputs. Guarantees raw hardware-derived cryptographic seeds are immediately imported as non-extractable Web Crypto handles, memory buffers are explicitly zeroized, and intermediate keying material is never serialized or transmitted across boundaries. 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: Exposing, serializing, or retaining raw WebAuthn PRF output buffers instead of immediate non-extractable CryptoKey ingestion and memory wiping 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 DriftExposing, serializing, or retaining raw WebAuthn PRF output buffers instead of immediate non-extractable CryptoKey ingestion and memory wipingCritical
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 request PRF extension outputs using typed, deterministic 32-byte salts within `navigator.credentials.get()`.

Engineers MUST ALWAYS request PRF extension outputs using typed, deterministic 32-byte salts within `navigator.credentials.get()`.

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 transmit raw PRF extension outputs or intermediate keying material over HTTP, WebSockets, IPC, or log them to consoles.

Engineers MUST NOT transmit raw PRF extension outputs or intermediate keying material over HTTP, WebSockets, IPC, or log them to consoles.

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 ALWAYS immediately import raw PRF outputs into the Web Crypto API (`crypto.subtle.importKey`) with `extractable

Engineers MUST ALWAYS immediately import raw PRF outputs into the Web Crypto API (`crypto.subtle.importKey`) with `extractable: false`.

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

Code MUST explicitly zeroize the ephemeral raw `Uint8Array` or `ArrayBuffer` PRF output immediately following `crypto.subtle.importKey` consumption.

Code MUST explicitly zeroize the ephemeral raw `Uint8Array` or `ArrayBuffer` PRF output immediately following `crypto.subtle.importKey` consumption.

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 derive application-specific encryption keys (e.g., AES-GCM) strictly using HKDF or PBKDF2 passing explicit context labels and info strings.

Services MUST derive application-specific encryption keys (e.g., AES-GCM) strictly using HKDF or PBKDF2 passing explicit context labels and info strings.

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

Derived application encryption keys MUST be marked `extractable

Derived application encryption keys MUST be marked `extractable: false` to prevent programmatic memory extraction by browser extensions or XSS payloads.

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

Components NEVER persist PRF results, derived key bytes, or master secrets to `localStorage`, `sessionStorage`, `IndexedDB`, or browser state managers.

Components NEVER persist PRF results, derived key bytes, or master secrets to `localStorage`, `sessionStorage`, `IndexedDB`, or browser state managers.

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 Level 3 PRF Extension Hardware Key-Derivation Invariant critical for AI coding assistants?

Enforces zero-knowledge client-side encryption key derivation via WebAuthn Level 3 PRF (Pseudo-Random Function) authenticator outputs. Guarantees raw hardware-derived cryptographic seeds are immediately imported as non-extractable Web Crypto handles, memory buffers are explicitly zeroized, and intermediate keying material is never serialized or transmitted across boundaries. 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 (Exposing, serializing, or retaining raw WebAuthn PRF output buffers instead of immediate non-extractable CryptoKey ingestion and memory wiping) 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