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

WebAuthn PRF Zero-Knowledge Client-Side Key Derivation Standard

Enforces strict client-side key derivation using the WebAuthn Pseudo-Random Function (PRF) extension (HMAC-secret) to derive hardware-bound symmetric encryption keys directly within the client sandbox. Prohibits transmission of PRF raw outputs, unhashed inputs, or derived master keys to remote backends, maintaining strict zero-knowledge security guarantees against server-side credential escrow vulnerabilities.

Prohibited Anti-Pattern: Transmitting WebAuthn PRF Outputs or Deriving Cryptographic Storage Keys on the Backend

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 key derivation using the WebAuthn Pseudo-Random Function (PRF) extension (HMAC-secret) to derive hardware-bound symmetric encryption keys directly within the client sandbox. Prohibits transmission of PRF raw outputs, unhashed inputs, or derived master keys to remote backends, maintaining strict zero-knowledge security guarantees against server-side credential escrow vulnerabilities.
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-side-zk-encryption-standard"
---

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

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Transmitting WebAuthn PRF Outputs or Deriving Cryptographic Storage Keys on the Backend

## System Constraints
You are a Principal Security Architect enforcing the WebAuthn PRF Client-Side Zero-Knowledge Encryption Standard. You must reject any architecture or implementation where raw authenticator PRF outputs, master root encryption keys, or hardware-bound entropy are transmitted across the network, logged, or retained in persistent client storage (LocalStorage/IndexedDB/cookies). Mandate that the WebAuthn PRF extension is evaluated exclusively via navigator.credentials.get/create with application-specific salts, and that the resulting PRF byte buffer is immediately ingested into WebCrypto HKDF-SHA256 to produce scoped, non-exportable CryptoKeys.

## Strict Guidelines
- Engineers MUST ALWAYS evaluate the WebAuthn PRF extension on the client using a cryptographically randomized, server-provided or contextual salt (minimum 32 bytes).
- Engineers MUST NEVER transmit the raw authenticator PRF output (`results.prf.results.first` or `results.prf.results.second`) to an external API endpoint or server.
- Code MUST pipe the raw PRF evaluation output immediately into `window.crypto.subtle.importKey` as raw HKDF key material (`HKDF`), followed by `window.crypto.subtle.deriveKey` to derive separate, scoped keys (e.g., AES-GCM-256 for data encryption, HMAC for integrity).
- Components NEVER store derived master symmetric encryption keys in LocalStorage, SessionStorage, or unencrypted IndexedDB; derived keys must remain non-exportable (`extractable: false`) within browser memory.
- Services MUST verify authenticator PRF capability flags (`authenticatorExtensions.prf.supported`) during registration before committing users to zero-knowledge encrypted workflows.
- Code MUST properly handle WebAuthn PRF feature detection and surface actionable errors when an authenticator does not support the HMAC-secret/PRF extension.

## Bad vs Good Implementations
### Client-Side PRF Key Derivation with HKDF and Non-Exportable CryptoKey

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Sending the raw PRF output to the backend introduces server-side key escrow, allowing an attacker with server or network access to read the master key and decrypt client vaults, totally defeating the zero-knowledge model.
```typescript
// BAD: Transmitting PRF evaluation result directly to backend for server-side decryption
export async function unlockUserVault(credentialId: Uint8Array, salt: Uint8Array): Promise<void> {
  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 rawPrf = new Uint8Array(extensionResults.prf?.results?.first!);

  // INSECURE: Transmitting raw hardware-bound secret to server destroys Zero-Knowledge
  await fetch('/api/vault/decrypt', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      credentialId: Array.from(credentialId),
      rawMasterKey: Array.from(rawPrf)
    })
  });
}
```

#### Production Standard (Correct)
> **Standard**: The raw PRF output is ingested immediately into the browser's WebCrypto subsystem as raw HKDF input key material. The derived AES-GCM key is non-exportable and never leaves client volatile memory, ensuring complete zero-knowledge isolation from the backend.
```typescript
// GOOD: Hardware PRF converted client-side to non-exportable AES-GCM key via HKDF
export async function deriveVaultKeyFromPrf(
  credentialId: Uint8Array,
  salt: Uint8Array,
  infoContext: string
): Promise<CryptoKey> {
  const assertion = await navigator.credentials.get({
    publicKey: {
      challenge: crypto.getRandomValues(new Uint8Array(32)),
      allowCredentials: [{ id: credentialId, type: 'public-key', transports: ['internal', 'hybrid'] }],
      userVerification: 'required',
      extensions: {
        prf: {
          eval: { first: salt }
        }
      }
    }
  }) as PublicKeyCredential | null;

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

  const extensionResults = assertion.getClientExtensionResults();
  const rawPrfBuffer = extensionResults.prf?.results?.first;
  if (!rawPrfBuffer) {
    throw new Error('Authenticator does not support PRF extension or eval failed');
  }

  // 1. Import PRF secret as HKDF Key Material
  const ikm = await window.crypto.subtle.importKey(
    'raw',
    rawPrfBuffer,
    'HKDF',
    false,
    ['deriveKey']
  );

  // 2. Derive non-exportable scoped AES-GCM-256 key strictly inside WebCrypto
  const encoder = new TextEncoder();
  const derivedKey = await window.crypto.subtle.deriveKey(
    {
      name: 'HKDF',
      hash: 'SHA-256',
      salt: salt,
      info: encoder.encode(infoContext)
    },
    ikm,
    { name: 'AES-GCM', length: 256 },
    false, // extractable: false prevents exfiltration
    ['encrypt', 'decrypt']
  );

  return derivedKey;
}
```

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-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 key derivation using the WebAuthn Pseudo-Random Function (PRF) extension (HMAC-secret) to derive hardware-bound symmetric encryption keys directly within the client sandbox. Prohibits transmission of PRF raw outputs, unhashed inputs, or derived master keys to remote backends, maintaining strict zero-knowledge security guarantees against server-side credential escrow vulnerabilities. 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 Outputs or Deriving Cryptographic Storage Keys on the Backend 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 Outputs or Deriving Cryptographic Storage Keys on the BackendCritical
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 the WebAuthn PRF extension on the client using a cryptographically randomized, server-provided or contextual salt (minimum 32 bytes).

Engineers MUST ALWAYS evaluate the WebAuthn PRF extension on the client using a cryptographically randomized, server-provided or contextual salt (minimum 32 bytes).

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 transmit the raw authenticator PRF output (`results.prf.results.first` or `results.prf.results.second`) to an external API endpoint or server.

Engineers MUST NEVER transmit the raw authenticator PRF output (`results.prf.results.first` or `results.prf.results.second`) to an external API endpoint or server.

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 pipe the raw PRF evaluation output immediately into `window.crypto.subtle.importKey` as raw HKDF key material (`HKDF`), followed by `window.crypto.subtle.deriveKey` to derive separate, scoped keys (e.g., AES-GCM-256 for data encryption, HMAC for integrity).

Code MUST pipe the raw PRF evaluation output immediately into `window.crypto.subtle.importKey` as raw HKDF key material (`HKDF`), followed by `window.crypto.subtle.deriveKey` to derive separate, scoped keys (e.g., AES-GCM-256 for data encryption, HMAC for integrity).

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

Components NEVER store derived master symmetric encryption keys in LocalStorage, SessionStorage, or unencrypted IndexedDB

Components NEVER store derived master symmetric encryption keys in LocalStorage, SessionStorage, or unencrypted IndexedDB; derived keys must remain non-exportable (`extractable: false`) within browser memory.

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 verify authenticator PRF capability flags (`authenticatorExtensions.prf.supported`) during registration before committing users to zero-knowledge encrypted workflows.

Services MUST verify authenticator PRF capability flags (`authenticatorExtensions.prf.supported`) during registration before committing users to zero-knowledge encrypted 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.
6

Code MUST properly handle WebAuthn PRF feature detection and surface actionable errors when an authenticator does not support the HMAC-secret/PRF extension.

Code MUST properly handle WebAuthn PRF feature detection and surface actionable errors when an authenticator does not support the HMAC-secret/PRF extension.

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 key derivation using the WebAuthn Pseudo-Random Function (PRF) extension (HMAC-secret) to derive hardware-bound symmetric encryption keys directly within the client sandbox. Prohibits transmission of PRF raw outputs, unhashed inputs, or derived master keys to remote backends, maintaining strict zero-knowledge security guarantees against server-side credential escrow vulnerabilities. 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 Outputs or Deriving Cryptographic Storage Keys on the Backend) 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