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

WebAuthn PRF Extension Client-Side Key Derivation and Zero-Knowledge Isolation

Enforces zero-knowledge client-side encryption key derivation using the WebAuthn Level 3 PRF (HMAC-Secret) extension directly inside hardware-backed authenticators. Guarantees that raw PRF outputs and derived symmetric encryption keys never traverse the network, bypass browser cryptographic memory boundaries, or touch relying party application servers.

Prohibited Anti-Pattern: Exposing Raw Authenticator PRF Outputs or Delegating Symmetric Key Derivation to Server Runtimes

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn PRF Extension Client-Side Key Derivation and Zero-Knowledge Isolation - Enforces zero-knowledge client-side encryption key derivation using the WebAuthn Level 3 PRF (HMAC-Secret) extension directly inside hardware-backed authenticators. Guarantees that raw PRF outputs and derived symmetric encryption keys never traverse the network, bypass browser cryptographic memory boundaries, or touch relying party application servers.
globs: src/**/*.{ts,tsx,js,mjs}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-prf-client-key-derivation-guardrail-webauthn-prf-ext-507"
---

# WebAuthn PRF Extension Client-Side Key Derivation and Zero-Knowledge Isolation

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Exposing Raw Authenticator PRF Outputs or Delegating Symmetric Key Derivation to Server Runtimes

## System Constraints
You are a Principal Security Architect enforcing strict Zero-Knowledge WebAuthn PRF (pseudo-random function) key derivation invariants. Authenticator PRF outputs represent high-entropy master seeds. You must mandate that all key material derived from the WebAuthn PRF extension is handled strictly in browser memory via the Web Cryptography API (`crypto.subtle`), marked as non-extractable (`extractable: false`), and never transmitted to the Relying Party (RP) backend.

## Strict Guidelines
- Engineers MUST ALWAYS evaluate WebAuthn PRF outputs strictly on the client using `navigator.credentials.get` with the `prf` extension and feed the resulting seed directly into `window.crypto.subtle.importKey` using format `'raw'` and algorithm `'HKDF'`.
- Engineers MUST NEVER serialize, log, or transmit raw PRF output buffers (`extensions.prf.results.first` or `second`) to relying party backends or external telemetry services.
- Engineers MUST ALWAYS set `extractable: false` when importing PRF seed material or deriving operational symmetric keys (`AES-GCM`) via `crypto.subtle.deriveKey`.
- Code MUST explicitly zero out transient `Uint8Array` buffers containing intermediate cryptographic keys or PRF outputs via `.fill(0)` immediately after key derivation.
- Engineers MUST define deterministic, domain-separated cryptographic salt/info parameters for HKDF client-side derivation to prevent cross-context key reuse attacks across different datastores.
- Components NEVER store derived symmetric keys in unencrypted browser storage (`localStorage`, `sessionStorage`, or unencrypted IndexedDB entries).

## Bad vs Good Implementations
### Client-side WebAuthn PRF key derivation vs. server-side transmission leak

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Transmitting raw PRF authenticator outputs to the server breaks zero-knowledge guarantees, exposing the master secret to MITM attacks, backend compromise, and infrastructure log pollution.
```typescript
import { client } from './api';

export async function unlockUserVault(credentialId: Uint8Array, salt: Uint8Array) {
  // ANTI-PATTERN: Executing PRF and transmitting the raw secret to backend
  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 extensionResults = assertion.getClientExtensionResults();
  const rawPrfSecret = new Uint8Array(extensionResults.prf?.results?.first!);

  // CRITICAL SECURITY FLAW: Sending PRF secret to server breaks zero-knowledge invariant
  const response = await client.post('/api/vault/unlock', {
    credentialId: Array.from(credentialId),
    prfOutput: Array.from(rawPrfSecret)
  });

  return response.data;
}
```

#### Production Standard (Correct)
> **Standard**: The PRF seed is strictly retained inside browser memory, imported as non-extractable HKDF key material, derived into a local AES-GCM key with domain separation, and the transient buffer is securely wiped using fill(0).
```typescript
const HKDF_INFO = new TextEncoder().encode('org.production.vault.aes-gcm.v1');

export async function deriveClientVaultKey(
  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 extensionResults = assertion.getClientExtensionResults();
  const prfResult = extensionResults.prf?.results?.first;
  if (!prfResult) {
    throw new Error('Authenticator did not return a valid PRF extension output');
  }

  const rawPrfBytes = new Uint8Array(prfResult);

  try {
    // Import raw PRF seed as non-extractable HKDF key
    const initialKeyMaterial = await crypto.subtle.importKey(
      'raw',
      rawPrfBytes,
      'HKDF',
      false,
      ['deriveKey']
    );

    // Derive local operational AES-GCM encryption key without exposing secret
    return await crypto.subtle.deriveKey(
      {
        name: 'HKDF',
        hash: 'SHA-256',
        salt: salt,
        info: HKDF_INFO
      },
      initialKeyMaterial,
      { name: 'AES-GCM', length: 256 },
      false, // non-extractable
      ['encrypt', 'decrypt']
    );
  } finally {
    // Invariant: Secure zeroing of transient raw buffers
    rawPrfBytes.fill(0);
  }
}
```

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 PRF Extension Client-Side Key Derivation and Zero-Knowledge Isolation

WebAuthn PRF Extension Client-Side Key Derivation and Zero-Knowledge Isolation defines an industrial-grade behavioral standard for security engineering. Enforces zero-knowledge client-side encryption key derivation using the WebAuthn Level 3 PRF (HMAC-Secret) extension directly inside hardware-backed authenticators. Guarantees that raw PRF outputs and derived symmetric encryption keys never traverse the network, bypass browser cryptographic memory boundaries, or touch relying party application servers. 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 Raw Authenticator PRF Outputs or Delegating Symmetric Key Derivation to Server Runtimes 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 Raw Authenticator PRF Outputs or Delegating Symmetric Key Derivation to Server RuntimesCritical
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 evaluate WebAuthn PRF outputs strictly on the client using `navigator.credentials.get` with the `prf` extension and feed the resulting seed directly into `window.crypto.subtle.importKey` using format `'raw'` and algorithm `'HKDF'`.

Engineers MUST ALWAYS evaluate WebAuthn PRF outputs strictly on the client using `navigator.credentials.get` with the `prf` extension and feed the resulting seed directly into `window.crypto.subtle.importKey` using format `'raw'` and algorithm `'HKDF'`.

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 NEVER serialize, log, or transmit raw PRF output buffers (`extensions.prf.results.first` or `second`) to relying party backends or external telemetry services.

Engineers MUST NEVER serialize, log, or transmit raw PRF output buffers (`extensions.prf.results.first` or `second`) to relying party backends or external telemetry services.

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 set `extractable

Engineers MUST ALWAYS set `extractable: false` when importing PRF seed material or deriving operational symmetric keys (`AES-GCM`) via `crypto.subtle.deriveKey`.

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 zero out transient `Uint8Array` buffers containing intermediate cryptographic keys or PRF outputs via `.fill(0)` immediately after key derivation.

Code MUST explicitly zero out transient `Uint8Array` buffers containing intermediate cryptographic keys or PRF outputs via `.fill(0)` immediately after key derivation.

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

Engineers MUST define deterministic, domain-separated cryptographic salt/info parameters for HKDF client-side derivation to prevent cross-context key reuse attacks across different datastores.

Engineers MUST define deterministic, domain-separated cryptographic salt/info parameters for HKDF client-side derivation to prevent cross-context key reuse attacks across different datastores.

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 store derived symmetric keys in unencrypted browser storage (`localStorage`, `sessionStorage`, or unencrypted IndexedDB entries).

Components NEVER store derived symmetric keys in unencrypted browser storage (`localStorage`, `sessionStorage`, or unencrypted IndexedDB entries).

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 Extension Client-Side Key Derivation and Zero-Knowledge Isolation critical for AI coding assistants?

Enforces zero-knowledge client-side encryption key derivation using the WebAuthn Level 3 PRF (HMAC-Secret) extension directly inside hardware-backed authenticators. Guarantees that raw PRF outputs and derived symmetric encryption keys never traverse the network, bypass browser cryptographic memory boundaries, or touch relying party application servers. 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 Raw Authenticator PRF Outputs or Delegating Symmetric Key Derivation to Server Runtimes) 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