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

WebAuthn PRF Extension Client-Side Symmetric Key Derivation & Zero-Leakage Standard

Mandates strict zero-knowledge client-side symmetric key derivation using the WebAuthn PRF (Pseudo-Random Function) extension. Requires intermediate PRF outputs to pass through HKDF domain separation and strictly prohibits leaking authenticator-derived secrets to servers or persistent storage.

Prohibited Anti-Pattern: Leaking WebAuthn PRF outputs to backend APIs or using raw PRF material directly as symmetric cipher keys.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn PRF Extension Client-Side Symmetric Key Derivation & Zero-Leakage Standard - Mandates strict zero-knowledge client-side symmetric key derivation using the WebAuthn PRF (Pseudo-Random Function) extension. Requires intermediate PRF outputs to pass through HKDF domain separation and strictly prohibits leaking authenticator-derived secrets to servers or persistent storage.
globs: src/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-prf-client-key-derivation"
---

# WebAuthn PRF Extension Client-Side Symmetric Key Derivation & Zero-Leakage Standard

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Leaking WebAuthn PRF outputs to backend APIs or using raw PRF material directly as symmetric cipher keys.

## System Constraints
You are a Principal Security Architect enforcing secure client-side symmetric key derivation via the WebAuthn PRF extension. Enforce strict isolation between the hardware-derived PRF output and remote server endpoints. Mandate HKDF (RFC 5869) key expansion with context-specific domain separation before utilizing symmetric ciphers. Ensure in-memory ephemeral buffers are zeroized post-derivation and strictly forbidden from being transmitted over the wire or stored in persistent client storage.

## Strict Guidelines
- Engineers MUST ALWAYS treat WebAuthn PRF outputs (AuthenticationExtensionsPRFOutputs) as Intermediate Key Material (IKM) and process them through HKDF (HMAC-based Extract-and-Expand) via Web Crypto API before encryption or decryption.
- Engineers MUST NOT transmit raw PRF outputs, evaluation results, or derived symmetric keys to the application server or log sinks; the server MUST only receive standard assertion fields (authenticatorData, clientDataJSON, signature, credentialId).
- Code MUST verify authenticator PRF support during credential registration by checking credential.getClientExtensionResults().prf?.enabled before attempting client-side E2EE workflows.
- Services MUST supply deterministic, cryptographically secure 32-byte salts for PRF evaluation ('eval.first') scoped distinctly by environment and security domain.
- Components NEVER store PRF output buffers or derived CryptoKey instances in localStorage, sessionStorage, or unencrypted IndexedDB, and MUST zeroize raw byte arrays immediately after CryptoKey importation.

## Bad vs Good Implementations
### Client-Side PRF Key Derivation with HKDF Domain Separation and Memory Zeroing

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Transmits raw PRF entropy across the network to the server, breaking zero-knowledge guarantees and exposing the hardware master credential output. Fails to derive purpose-separated keys via HKDF and leaves raw key material vulnerable in memory and transit.
```typescript
import { startAuthentication } from '@simplewebauthn/browser';

export async function unlockUserVault(assertionOptions: any) {
  // Anti-pattern: Sending PRF output back to server or using raw PRF as AES key
  const assertion = await startAuthentication(assertionOptions);
  const extensionResults = assertion.clientExtensionResults as any;
  const rawPrf = extensionResults?.prf?.results?.first;

  // CRITICAL VULNERABILITY: Raw PRF transmitted directly to backend
  await fetch('/api/vault/unlock', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      credential: assertion,
      rawKeyMaterial: Array.from(new Uint8Array(rawPrf)), // Leaking authenticator entropy
    }),
  });
}
```

#### Production Standard (Correct)
> **Standard**: Keeps the PRF entropy isolated entirely within client memory. Uses HKDF to derive an AES-GCM-256 key with domain separation strings, prevents key export ('extractable: false'), and zeroes the raw byte array in a finally block.
```typescript
import { startAuthentication } from '@simplewebauthn/browser';

export async function unlockUserVault(assertionOptions: PublicKeyCredentialRequestOptionsJSON, domainSalt: Uint8Array): Promise<CryptoKey> {
  // Invariant: Evaluate PRF client-side with a scoped 32-byte salt
  const credential = await navigator.credentials.get({
    publicKey: {
      ...assertionOptions,
      extensions: {
        prf: {
          eval: {
            first: domainSalt,
          },
        },
      },
    },
  }) as PublicKeyCredential;

  const extResults = credential.getClientExtensionResults() as AuthenticationExtensionsClientOutputs & {
    prf?: { results?: { first?: ArrayBuffer } };
  };

  const rawPrf = extResults?.prf?.results?.first;
  if (!rawPrf) {
    throw new Error('Authenticator did not return PRF evaluation result or lacks PRF support.');
  }

  const prfBuffer = new Uint8Array(rawPrf);
  try {
    // Invariant: Import raw PRF output as HKDF key material
    const baseKey = await crypto.subtle.importKey(
      'raw',
      prfBuffer,
      'HKDF',
      false,
      ['deriveKey']
    );

    // Invariant: Derive distinct AES-GCM-256 key with domain separation context
    const encKey = await crypto.subtle.deriveKey(
      {
        name: 'HKDF',
        hash: 'SHA-256',
        salt: new TextEncoder().encode('vault-storage-v1-salt'),
        info: new TextEncoder().encode('vault-aes-gcm-encryption'),
      },
      baseKey,
      { name: 'AES-GCM', length: 256 },
      false,
      ['encrypt', 'decrypt']
    );

    return encKey;
  } finally {
    // Invariant: Securely zeroize the ephemeral raw PRF buffer
    prfBuffer.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 Symmetric Key Derivation & Zero-Leakage Standard

WebAuthn PRF Extension Client-Side Symmetric Key Derivation & Zero-Leakage Standard defines an industrial-grade behavioral standard for security engineering. Mandates strict zero-knowledge client-side symmetric key derivation using the WebAuthn PRF (Pseudo-Random Function) extension. Requires intermediate PRF outputs to pass through HKDF domain separation and strictly prohibits leaking authenticator-derived secrets to servers or persistent storage. 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: Leaking WebAuthn PRF outputs to backend APIs or using raw PRF material directly as symmetric cipher keys. 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 DriftLeaking WebAuthn PRF outputs to backend APIs or using raw PRF material directly as symmetric cipher keys.Critical
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 treat WebAuthn PRF outputs (AuthenticationExtensionsPRFOutputs) as Intermediate Key Material (IKM) and process them through HKDF (HMAC-based Extract-and-Expand) via Web Crypto API before encryption or decryption.

Engineers MUST ALWAYS treat WebAuthn PRF outputs (AuthenticationExtensionsPRFOutputs) as Intermediate Key Material (IKM) and process them through HKDF (HMAC-based Extract-and-Expand) via Web Crypto API before encryption or decryption.

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 outputs, evaluation results, or derived symmetric keys to the application server or log sinks

Engineers MUST NOT transmit raw PRF outputs, evaluation results, or derived symmetric keys to the application server or log sinks; the server MUST only receive standard assertion fields (authenticatorData, clientDataJSON, signature, credentialId).

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 MUST verify authenticator PRF support during credential registration by checking credential.getClientExtensionResults().prf?.enabled before attempting client-side E2EE workflows.

Code MUST verify authenticator PRF support during credential registration by checking credential.getClientExtensionResults().prf?.enabled before attempting client-side E2EE workflows.

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 supply deterministic, cryptographically secure 32-byte salts for PRF evaluation ('eval.first') scoped distinctly by environment and security domain.

Services MUST supply deterministic, cryptographically secure 32-byte salts for PRF evaluation ('eval.first') scoped distinctly by environment and security domain.

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 PRF output buffers or derived CryptoKey instances in localStorage, sessionStorage, or unencrypted IndexedDB, and MUST zeroize raw byte arrays immediately after CryptoKey importation.

Components NEVER store PRF output buffers or derived CryptoKey instances in localStorage, sessionStorage, or unencrypted IndexedDB, and MUST zeroize raw byte arrays immediately after CryptoKey importation.

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 Symmetric Key Derivation & Zero-Leakage Standard critical for AI coding assistants?

Mandates strict zero-knowledge client-side symmetric key derivation using the WebAuthn PRF (Pseudo-Random Function) extension. Requires intermediate PRF outputs to pass through HKDF domain separation and strictly prohibits leaking authenticator-derived secrets to servers or persistent storage. 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 (Leaking WebAuthn PRF outputs to backend APIs or using raw PRF material directly as symmetric cipher keys.) 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