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

WebAuthn Level 3 PRF Zero-Knowledge Hardware Key Derivation Standard

Enforces client-side zero-knowledge encryption using WebAuthn Level 3 Pseudo-Random Function (PRF) extension outputs (HMAC-SHA-256) combined with HKDF for symmetric key derivation. Guarantees that raw PRF outputs and derived symmetric encryption keys never traverse network boundaries, remain strictly scoped to hardware authenticator bounds, and use ephemeral salt challenges to prevent replay and key-reuse vulnerabilities.

Prohibited Anti-Pattern: Transmitting Raw PRF Outputs or Deriving Symmetrical Payload Keys on the Server

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn Level 3 PRF Zero-Knowledge Hardware Key Derivation Standard - Enforces client-side zero-knowledge encryption using WebAuthn Level 3 Pseudo-Random Function (PRF) extension outputs (HMAC-SHA-256) combined with HKDF for symmetric key derivation. Guarantees that raw PRF outputs and derived symmetric encryption keys never traverse network boundaries, remain strictly scoped to hardware authenticator bounds, and use ephemeral salt challenges to prevent replay and key-reuse 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-zero-knowledge-encryption"
---

# WebAuthn Level 3 PRF Zero-Knowledge Hardware Key Derivation Standard

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Transmitting Raw PRF Outputs or Deriving Symmetrical Payload Keys on the Server

## System Constraints
You are a Principal Security Architect enforcing the WebAuthn Level 3 PRF (Pseudo-Random Function) Client-Side Zero-Knowledge Encryption Standard. Mandate that all symmetric key derivation from hardware authenticators executes strictly in the user's browser runtime using Web Cryptography primitives. You must prevent server-side exposure of PRF evaluation results, require HKDF-SHA-256 key derivation with persistent unique salts, enforce AES-256-GCM authenticated encryption for payload storage, and ensure proper fallback handling when PRF is unsupported by client hardware.

## Strict Guidelines
- Engineers MUST ALWAYS evaluate the WebAuthn `prf` extension via `navigator.credentials.get` exclusively inside the client runtime and derive symmetric keys locally using `window.crypto.subtle`.
- Engineers MUST NOT transmit raw PRF output (`results.prf.first` or `results.prf.second`), raw derived keys, or unencrypted plaintext payloads to the server or any intermediary API.
- Services MUST deliver a cryptographically secure, per-user or per-document public salt (32 bytes) to be supplied into `eval.first` or HKDF expand steps, preventing cross-domain and multi-document key collision.
- Code MUST pass raw PRF output through HKDF-SHA-256 (`crypto.subtle.deriveKey`) with an application-specific info context to produce an AES-GCM-256 key, rather than using raw PRF output directly as a cipher key.
- Components NEVER store derived `CryptoKey` instances in persistent storage (`localStorage`, `IndexedDB`, or unencrypted cookies); keys must reside only in ephemeral memory and be cleared upon session termination.

## Bad vs Good Implementations
### Client-Side PRF Evaluation and HKDF AES-GCM Key Derivation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Sends the raw PRF output over the network to the backend server. This completely breaks zero-knowledge guarantees, exposing the hardware authenticator's derived secret to the server, and uses a hardcoded non-random salt.
```typescript
export async function unlockUserVault(credentialId: string, serverChallenge: string): Promise<void> {
  // Anti-pattern: Sending authenticator PRF output or relying on server to decrypt
  const assertion = await navigator.credentials.get({
    publicKey: {
      challenge: Uint8Array.from(atob(serverChallenge), c => c.charCodeAt(0)),
      allowCredentials: [{ id: Uint8Array.from(atob(credentialId), c => c.charCodeAt(0)), type: 'public-key' }],
      extensions: {
        prf: {
          eval: { first: new Uint8Array(32).fill(1) }
        }
      }
    }
  }) as PublicKeyCredential;

  const extensionResults = assertion.getClientExtensionResults();
  const rawPrf = extensionResults.prf?.results?.first;

  // CRITICAL VULNERABILITY: Leaking raw PRF hardware secret to server API
  await fetch('/api/vault/decrypt', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      credentialId,
      prfOutput: Array.from(new Uint8Array(rawPrf!))
    })
  });
}
```

#### Production Standard (Correct)
> **Standard**: Properly performs PRF evaluation using a per-document salt, validates the PRF response client-side, derives a 256-bit AES-GCM key using HKDF with domain-specific info, and performs payload decryption in local browser memory without leaking keys.
```typescript
export async function decryptClientPayload(
  credentialId: Uint8Array,
  challenge: Uint8Array,
  documentSalt: Uint8Array,
  encryptedPayload: Uint8Array,
  iv: Uint8Array
): Promise<ArrayBuffer> {
  const assertion = await navigator.credentials.get({
    publicKey: {
      challenge,
      allowCredentials: [{ id: credentialId, type: 'public-key' }],
      extensions: {
        prf: {
          eval: { first: documentSalt }
        }
      }
    }
  }) as PublicKeyCredential;

  const prfResult = assertion.getClientExtensionResults().prf?.results?.first;
  if (!prfResult) {
    throw new Error('Authenticator did not return PRF output; extension unsupported or blocked.');
  }

  // Import PRF output as raw key material for HKDF
  const prfKeyMaterial = await window.crypto.subtle.importKey(
    'raw',
    prfResult,
    'HKDF',
    false,
    ['deriveKey']
  );

  // Derive AES-GCM-256 key with domain separation
  const encryptionKey = await window.crypto.subtle.deriveKey(
    {
      name: 'HKDF',
      salt: documentSalt,
      info: new TextEncoder().encode('WebAuthn-Level3-PRF-Zero-Knowledge-Storage-v1'),
      hash: 'SHA-256'
    },
    prfKeyMaterial,
    { name: 'AES-GCM', length: 256 },
    false,
    ['decrypt']
  );

  // Decrypt payload locally within client memory
  return window.crypto.subtle.decrypt(
    { name: 'AES-GCM', iv },
    encryptionKey,
    encryptedPayload
  );
}
```

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 Level 3 PRF Zero-Knowledge Hardware Key Derivation Standard

WebAuthn Level 3 PRF Zero-Knowledge Hardware Key Derivation Standard defines an industrial-grade behavioral standard for security engineering. Enforces client-side zero-knowledge encryption using WebAuthn Level 3 Pseudo-Random Function (PRF) extension outputs (HMAC-SHA-256) combined with HKDF for symmetric key derivation. Guarantees that raw PRF outputs and derived symmetric encryption keys never traverse network boundaries, remain strictly scoped to hardware authenticator bounds, and use ephemeral salt challenges to prevent replay and key-reuse 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 Raw PRF Outputs or Deriving Symmetrical Payload Keys on the Server 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 PRF Outputs or Deriving Symmetrical Payload Keys on the ServerCritical
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 via `navigator.credentials.get` exclusively inside the client runtime and derive symmetric keys locally using `window.crypto.subtle`.

Engineers MUST ALWAYS evaluate the WebAuthn `prf` extension via `navigator.credentials.get` exclusively inside the client runtime and derive symmetric keys locally using `window.crypto.subtle`.

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 output (`results.prf.first` or `results.prf.second`), raw derived keys, or unencrypted plaintext payloads to the server or any intermediary API.

Engineers MUST NOT transmit raw PRF output (`results.prf.first` or `results.prf.second`), raw derived keys, or unencrypted plaintext payloads to the server or any intermediary API.

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

Services MUST deliver a cryptographically secure, per-user or per-document public salt (32 bytes) to be supplied into `eval.first` or HKDF expand steps, preventing cross-domain and multi-document key collision.

Services MUST deliver a cryptographically secure, per-user or per-document public salt (32 bytes) to be supplied into `eval.first` or HKDF expand steps, preventing cross-domain and multi-document key collision.

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 pass raw PRF output through HKDF-SHA-256 (`crypto.subtle.deriveKey`) with an application-specific info context to produce an AES-GCM-256 key, rather than using raw PRF output directly as a cipher key.

Code MUST pass raw PRF output through HKDF-SHA-256 (`crypto.subtle.deriveKey`) with an application-specific info context to produce an AES-GCM-256 key, rather than using raw PRF output directly as a cipher key.

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 derived `CryptoKey` instances in persistent storage (`localStorage`, `IndexedDB`, or unencrypted cookies)

Components NEVER store derived `CryptoKey` instances in persistent storage (`localStorage`, `IndexedDB`, or unencrypted cookies); keys must reside only in ephemeral memory and be cleared upon session termination.

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 Level 3 PRF Zero-Knowledge Hardware Key Derivation Standard critical for AI coding assistants?

Enforces client-side zero-knowledge encryption using WebAuthn Level 3 Pseudo-Random Function (PRF) extension outputs (HMAC-SHA-256) combined with HKDF for symmetric key derivation. Guarantees that raw PRF outputs and derived symmetric encryption keys never traverse network boundaries, remain strictly scoped to hardware authenticator bounds, and use ephemeral salt challenges to prevent replay and key-reuse 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 Raw PRF Outputs or Deriving Symmetrical Payload Keys on the Server) 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