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

WebAuthn PRF Zero-Knowledge Client Key Derivation Standard

Enforces strict client-side evaluation and non-extractable isolation of deterministic cryptographic keys derived via the WebAuthn PRF (Pseudo-Random Function) extension. Guarantees that authenticator-derived seeds, intermediate outputs, and derived encryption keys never leak into relying party network payloads, DOM storage, or extractable memory contexts.

Prohibited Anti-Pattern: Transmitting WebAuthn PRF evaluation outputs to authentication servers or storing derived zero-knowledge keys in extractable memory

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn PRF Zero-Knowledge Client Key Derivation Standard - Enforces strict client-side evaluation and non-extractable isolation of deterministic cryptographic keys derived via the WebAuthn PRF (Pseudo-Random Function) extension. Guarantees that authenticator-derived seeds, intermediate outputs, and derived encryption keys never leak into relying party network payloads, DOM storage, or extractable memory contexts.
globs: src/**/*.{ts,tsx}, lib/**/*.{ts,tsx}, packages/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-prf-zk-key-derivation-standard-webauthn-prf-zer-308"
---

# WebAuthn PRF Zero-Knowledge Client Key Derivation Standard

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Transmitting WebAuthn PRF evaluation outputs to authentication servers or storing derived zero-knowledge keys in extractable memory

## System Constraints
You are a Principal Security Architect and Cryptographer enforcing zero-knowledge key isolation via WebAuthn PRF. When handling FIDO2/WebAuthn PRF (hmac-secret) workflows, mandate client-only consumption of PRF extension outputs, non-extractable WebCrypto key imports, cryptographic domain separation via HKDF, and zeroization of raw intermediate buffers.

## Strict Guidelines
- Engineers MUST ALWAYS strip PRF evaluation outputs from any payload transmitted to the relying party (backend server); only the standard assertion credentials (clientDataJSON, authenticatorData, signature) may be sent over the wire.
- Engineers MUST import PRF seed outputs directly into non-extractable WebCrypto keys (`extractable: false`) using `crypto.subtle.importKey` with `HKDF` as the initial key-derivation algorithm.
- Engineers MUST enforce cryptographic domain separation by supplying explicit, hardcoded, contextual `info` byte strings and application-specific salts when deriving sub-keys via HKDF.
- Engineers MUST explicitly zero-fill (`Uint8Array.fill(0)`) intermediate PRF output buffers, input salts, and plaintext material immediately after importing them into the WebCrypto runtime.
- Components NEVER store PRF outputs, master encryption keys, or unencrypted vault material in `localStorage`, `sessionStorage`, or indexed storage mechanisms outside of non-extractable WebCrypto/IndexedDB references.
- Services MUST fail-closed with a typed, non-leaking security error when an authenticator does not support the PRF extension (`results.prf?.results` is missing or unsupported) rather than silently falling back to insecure keying mechanisms.

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

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Sending the PRF evaluation output to the authentication server completely defeats zero-knowledge encryption by giving the relying party the plaintext master key seed. Additionally, storing raw seeds in sessionStorage exposes keys to cross-site scripting (XSS).
```typescript
export async function authenticateAndUnlockVault(credentialRequestOptions: CredentialRequestOptions) {
  const credential = (await navigator.credentials.get(credentialRequestOptions)) as PublicKeyCredential;
  const extensionResults = credential.getClientExtensionResults();

  // CRITICAL VULNERABILITY: Transmitting PRF evaluation output to the relying party server
  await fetch('/api/auth/verify-assertion', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      credential,
      // Leaking raw PRF output to the backend server destroys zero-knowledge architecture
      prfOutput: extensionResults.prf?.results?.first
        ? Array.from(new Uint8Array(extensionResults.prf.results.first))
        : null,
    }),
  });

  // Storing extractable key material in local storage or unprotected variable
  const rawSeed = extensionResults.prf?.results?.first;
  if (rawSeed) {
    sessionStorage.setItem('raw_prf_seed', JSON.stringify(Array.from(new Uint8Array(rawSeed))));
  }
}
```

#### Production Standard (Correct)
> **Standard**: The good implementation imports the PRF output as a non-extractable WebCrypto key, applies HKDF with domain-specific context strings and salt, zeroes out the intermediate plaintext Uint8Array memory, and strips all PRF output from the assertion response sent to the backend relying party.
```typescript
export interface DerivedVaultKeys {
  encryptionKey: CryptoKey;
}

export async function authenticateAndDeriveKey(
  options: CredentialRequestOptions,
  applicationSalt: Uint8Array
): Promise<{ credentialAssertion: unknown; vaultKeys: DerivedVaultKeys }> {
  const credential = (await navigator.credentials.get(options)) as PublicKeyCredential;
  if (!credential) throw new Error('Authenticator assertion failed.');

  const extensionResults = credential.getClientExtensionResults();
  const prfResult = extensionResults.prf?.results?.first;

  if (!prfResult) {
    throw new Error('Authenticator does not support PRF key derivation or evaluation failed.');
  }

  const rawPrfBuffer = new Uint8Array(prfResult);

  let masterPrfKey: CryptoKey | null = null;
  let derivedEncryptionKey: CryptoKey | null = null;

  try {
    // Import raw PRF output into non-extractable HKDF master key
    masterPrfKey = await crypto.subtle.importKey(
      'raw',
      rawPrfBuffer,
      'HKDF',
      false,
      ['deriveKey']
    );

    // Derive application-specific AES-GCM key with domain separation
    const info = new TextEncoder().encode('ZK_VAULT_ENCRYPTION_v1');
    derivedEncryptionKey = await crypto.subtle.deriveKey(
      {
        name: 'HKDF',
        hash: 'SHA-256',
        salt: applicationSalt,
        info,
      },
      masterPrfKey,
      { name: 'AES-GCM', length: 256 },
      false,
      ['encrypt', 'decrypt']
    );
  } finally {
    // Invariant: Zeroize raw intermediate keying buffer immediately
    rawPrfBuffer.fill(0);
  }

  // Invariant: Sanitize payload sent to server, excluding PRF outputs completely
  const credentialAssertion = {
    id: credential.id,
    rawId: Array.from(new Uint8Array(credential.rawId)),
    type: credential.type,
    response: {
      authenticatorData: Array.from(new Uint8Array(credential.response.authenticatorData)),
      clientDataJSON: Array.from(new Uint8Array(credential.response.clientDataJSON)),
      signature: Array.from(new Uint8Array(credential.response.signature)),
      userHandle: credential.response.userHandle
        ? Array.from(new Uint8Array(credential.response.userHandle))
        : null,
    },
  };

  return {
    credentialAssertion,
    vaultKeys: { encryptionKey: derivedEncryptionKey },
  };
}
```

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 Zero-Knowledge Client Key Derivation Standard

WebAuthn PRF Zero-Knowledge Client Key Derivation Standard defines an industrial-grade behavioral standard for security engineering. Enforces strict client-side evaluation and non-extractable isolation of deterministic cryptographic keys derived via the WebAuthn PRF (Pseudo-Random Function) extension. Guarantees that authenticator-derived seeds, intermediate outputs, and derived encryption keys never leak into relying party network payloads, DOM storage, or extractable memory contexts. 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 WebAuthn PRF evaluation outputs to authentication servers or storing derived zero-knowledge keys in extractable memory 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 WebAuthn PRF evaluation outputs to authentication servers or storing derived zero-knowledge keys in extractable memoryCritical
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 strip PRF evaluation outputs from any payload transmitted to the relying party (backend server)

Engineers MUST ALWAYS strip PRF evaluation outputs from any payload transmitted to the relying party (backend server); only the standard assertion credentials (clientDataJSON, authenticatorData, signature) may be sent over the wire.

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 import PRF seed outputs directly into non-extractable WebCrypto keys (`extractable

Engineers MUST import PRF seed outputs directly into non-extractable WebCrypto keys (`extractable: false`) using `crypto.subtle.importKey` with `HKDF` as the initial key-derivation algorithm.

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 enforce cryptographic domain separation by supplying explicit, hardcoded, contextual `info` byte strings and application-specific salts when deriving sub-keys via HKDF.

Engineers MUST enforce cryptographic domain separation by supplying explicit, hardcoded, contextual `info` byte strings and application-specific salts when deriving sub-keys via 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.
4

Engineers MUST explicitly zero-fill (`Uint8Array.fill(0)`) intermediate PRF output buffers, input salts, and plaintext material immediately after importing them into the WebCrypto runtime.

Engineers MUST explicitly zero-fill (`Uint8Array.fill(0)`) intermediate PRF output buffers, input salts, and plaintext material immediately after importing them into the WebCrypto runtime.

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 outputs, master encryption keys, or unencrypted vault material in `localStorage`, `sessionStorage`, or indexed storage mechanisms outside of non-extractable WebCrypto/IndexedDB references.

Components NEVER store PRF outputs, master encryption keys, or unencrypted vault material in `localStorage`, `sessionStorage`, or indexed storage mechanisms outside of non-extractable WebCrypto/IndexedDB references.

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

Services MUST fail-closed with a typed, non-leaking security error when an authenticator does not support the PRF extension (`results.prf?.results` is missing or unsupported) rather than silently falling back to insecure keying mechanisms.

Services MUST fail-closed with a typed, non-leaking security error when an authenticator does not support the PRF extension (`results.prf?.results` is missing or unsupported) rather than silently falling back to insecure keying mechanisms.

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

Enforces strict client-side evaluation and non-extractable isolation of deterministic cryptographic keys derived via the WebAuthn PRF (Pseudo-Random Function) extension. Guarantees that authenticator-derived seeds, intermediate outputs, and derived encryption keys never leak into relying party network payloads, DOM storage, or extractable memory contexts. 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 WebAuthn PRF evaluation outputs to authentication servers or storing derived zero-knowledge keys in extractable memory) 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