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

WebAuthn PRF Zero-Knowledge Client-Side Key Derivation Standard

Enforces strict client-side evaluation of WebAuthn Pseudo-Random Function (PRF) extension outputs and secure derivation of non-extractable symmetric encryption keys via Web Crypto HKDF. Guarantees that raw PRF outputs, intermediate salts, and derived plaintext keys never egress beyond ephemeral browser memory or traverse server boundaries, preserving end-to-end zero-knowledge confidentiality.

Prohibited Anti-Pattern: Transmitting Raw WebAuthn PRF Outputs to Backends or Storing Derived Keys in Persistent Client Storage

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn PRF Zero-Knowledge Client-Side Key Derivation Standard - Enforces strict client-side evaluation of WebAuthn Pseudo-Random Function (PRF) extension outputs and secure derivation of non-extractable symmetric encryption keys via Web Crypto HKDF. Guarantees that raw PRF outputs, intermediate salts, and derived plaintext keys never egress beyond ephemeral browser memory or traverse server boundaries, preserving end-to-end zero-knowledge confidentiality.
globs: src/**/*.{ts,tsx}, lib/**/*.{ts,tsx}
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-783"
---

# WebAuthn PRF Zero-Knowledge Client-Side Key Derivation Standard

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Transmitting Raw WebAuthn PRF Outputs to Backends or Storing Derived Keys in Persistent Client Storage

## System Constraints
You are a Principal Security Architect enforcing the WebAuthn PRF Extension Client-Side Key Derivation Standard. You must strictly mandate that all cryptographic operations leveraging WebAuthn PRF extension evaluate inside hardware authenticators, process intermediate material solely through client-side SubtleCrypto primitives, instantiate keys with extractable: false, and completely isolate raw cryptographic material from network transmission and persistent client storage.

## Strict Guidelines
- Engineers MUST ALWAYS verify client and authenticator support for the WebAuthn PRF extension via PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable() and credential extension capabilities before invoking PRF evaluations.
- Engineers MUST ALWAYS derive final symmetric cipher keys (e.g., AES-256-GCM) using crypto.subtle.deriveKey with HKDF-SHA-256, feeding the PRF evaluation output as initial key material along with a domain-separated salt and info parameter.
- Engineers MUST ALWAYS mark derived symmetric CryptoKey instances as extractable: false to prevent memory dumping or exfiltration via client-side script injection.
- Engineers MUST NEVER transmit raw PRF seed inputs, intermediate PRF outputs, or derived encryption keys to any remote API or server boundary.
- Code MUST NEVER persist raw PRF evaluation bytes or derived keys in localStorage, sessionStorage, IndexedDB, or unencrypted cookies.
- Components MUST zero out or overwrite temporary Uint8Array buffers containing raw PRF evaluations immediately after HKDF key derivation.

## Bad vs Good Implementations
### Client-Side Zero-Knowledge Encryption Key Derivation using WebAuthn PRF

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The anti-pattern leaks raw PRF evaluation outputs across the network to a backend endpoint, destroying zero-knowledge confidentiality and exposing user data to server-side compromise. It also persists sensitive raw key material in unencrypted localStorage.
```typescript
export async function unlockUserVault(credentialId: string, prfSalt: Uint8Array): Promise<void> {
  const credential = await navigator.credentials.get({
    publicKey: {
      challenge: new Uint8Array(32),
      allowCredentials: [{ id: Uint8Array.from(atob(credentialId), c => c.charCodeAt(0)), type: 'public-key' }],
      extensions: {
        prf: {
          eval: { first: prfSalt }
        }
      } as any
    }
  }) as PublicKeyCredential;

  const extensionResults = credential.getClientExtensionResults() as any;
  const rawPrfKey = new Uint8Array(extensionResults.prf.results.first);

  // SECURITY VIOALTION: Transmitting zero-knowledge PRF outputs to backend
  await fetch('/api/vault/unlock', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      credentialId,
      prfKey: Array.from(rawPrfKey)
    })
  });

  // SECURITY VIOLATION: Storing raw derived key bytes in persistent localStorage
  localStorage.setItem('vault_key', btoa(String.fromCharCode(...rawPrfKey)));
}
```

#### Production Standard (Correct)
> **Standard**: Evaluates the PRF extension via hardware passkey, imports it directly into Web Crypto as an unextractable HKDF key, derives an AES-GCM-256 key without exporting key bytes, zeroes out intermediate memory buffers, and strictly preserves the client cryptographic boundary without network leakage.
```typescript
export async function deriveVaultEncryptionKey(
  credentialId: Uint8Array,
  prfInputSalt: Uint8Array,
  vaultContextSalt: Uint8Array
): Promise<CryptoKey> {
  const credential = await navigator.credentials.get({
    publicKey: {
      challenge: crypto.getRandomValues(new Uint8Array(32)),
      allowCredentials: [{ id: credentialId, type: 'public-key' }],
      userVerification: 'required',
      extensions: {
        prf: {
          eval: { first: prfInputSalt }
        }
      } as AuthenticationExtensionsClientInputs
    }
  }) as PublicKeyCredential | null;

  if (!credential) {
    throw new Error('WebAuthn assertion failed or was cancelled.');
  }

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

  if (!extensionResults.prf?.results?.first) {
    throw new Error('Authenticator does not support or failed PRF extension evaluation.');
  }

  const prfRawBuffer = new Uint8Array(extensionResults.prf.results.first);

  try {
    // Import PRF output into WebCrypto HKDF master key wrapper (extractable: false)
    const masterKey = await crypto.subtle.importKey(
      'raw',
      prfRawBuffer,
      'HKDF',
      false,
      ['deriveKey']
    );

    // Derive dedicated AES-256-GCM symmetric key with domain-specific info
    return await crypto.subtle.deriveKey(
      {
        name: 'HKDF',
        hash: 'SHA-256',
        salt: vaultContextSalt,
        info: new TextEncoder().encode('zeroknowledge:vault:aes-gcm-256:v1')
      },
      masterKey,
      { name: 'AES-GCM', length: 256 },
      false, // Invariant: Must remain non-extractable
      ['encrypt', 'decrypt']
    );
  } finally {
    // Invariant: Wipe sensitive transient buffers from client memory
    prfRawBuffer.fill(0);
  }
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: WebAuthn PRF Zero-Knowledge Client-Side Key Derivation Standard

WebAuthn PRF Zero-Knowledge Client-Side Key Derivation Standard defines an industrial-grade behavioral standard for security engineering. Enforces strict client-side evaluation of WebAuthn Pseudo-Random Function (PRF) extension outputs and secure derivation of non-extractable symmetric encryption keys via Web Crypto HKDF. Guarantees that raw PRF outputs, intermediate salts, and derived plaintext keys never egress beyond ephemeral browser memory or traverse server boundaries, preserving end-to-end zero-knowledge confidentiality. 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: Transmitting Raw WebAuthn PRF Outputs to Backends or Storing Derived Keys in Persistent Client 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 DriftTransmitting Raw WebAuthn PRF Outputs to Backends or Storing Derived Keys in Persistent Client 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 verify client and authenticator support for the WebAuthn PRF extension via PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable() and credential extension capabilities before invoking PRF evaluations.

Engineers MUST ALWAYS verify client and authenticator support for the WebAuthn PRF extension via PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable() and credential extension capabilities before invoking PRF evaluations.

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 ALWAYS derive final symmetric cipher keys (e.g., AES-256-GCM) using crypto.subtle.deriveKey with HKDF-SHA-256, feeding the PRF evaluation output as initial key material along with a domain-separated salt and info parameter.

Engineers MUST ALWAYS derive final symmetric cipher keys (e.g., AES-256-GCM) using crypto.subtle.deriveKey with HKDF-SHA-256, feeding the PRF evaluation output as initial key material along with a domain-separated salt and info parameter.

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 mark derived symmetric CryptoKey instances as extractable

Engineers MUST ALWAYS mark derived symmetric CryptoKey instances as extractable: false to prevent memory dumping or exfiltration via client-side script injection.

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

Engineers MUST NEVER transmit raw PRF seed inputs, intermediate PRF outputs, or derived encryption keys to any remote API or server boundary.

Engineers MUST NEVER transmit raw PRF seed inputs, intermediate PRF outputs, or derived encryption keys to any remote API or server 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.
5

Code MUST NEVER persist raw PRF evaluation bytes or derived keys in localStorage, sessionStorage, IndexedDB, or unencrypted cookies.

Code MUST NEVER persist raw PRF evaluation bytes or derived keys in localStorage, sessionStorage, IndexedDB, or unencrypted cookies.

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 MUST zero out or overwrite temporary Uint8Array buffers containing raw PRF evaluations immediately after HKDF key derivation.

Components MUST zero out or overwrite temporary Uint8Array buffers containing raw PRF evaluations immediately after HKDF 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.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is WebAuthn PRF Zero-Knowledge Client-Side Key Derivation Standard critical for AI coding assistants?

Enforces strict client-side evaluation of WebAuthn Pseudo-Random Function (PRF) extension outputs and secure derivation of non-extractable symmetric encryption keys via Web Crypto HKDF. Guarantees that raw PRF outputs, intermediate salts, and derived plaintext keys never egress beyond ephemeral browser memory or traverse server boundaries, preserving end-to-end zero-knowledge confidentiality. 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 (Transmitting Raw WebAuthn PRF Outputs to Backends or Storing Derived Keys in Persistent Client 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