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

Deterministic Client-Side Key Derivation via WebAuthn Level 3 PRF Extension

Enforces hardware-backed, deterministic client-side symmetric key derivation using the WebAuthn Level 3 pseudo-random function (PRF) extension. Mandates that root cryptographic seeds remain exclusively within authenticator hardware bounds, using HMAC-SHA-256 HKDF expansion client-side for zero-knowledge end-to-end encryption without transmitting master secrets or raw PRF outputs to the server.

Prohibited Anti-Pattern: Deriving Encryption Keys from Server Secrets, Passwords, or Sending Raw PRF Outputs Across Network Boundaries

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Deterministic Client-Side Key Derivation via WebAuthn Level 3 PRF Extension - Enforces hardware-backed, deterministic client-side symmetric key derivation using the WebAuthn Level 3 pseudo-random function (PRF) extension. Mandates that root cryptographic seeds remain exclusively within authenticator hardware bounds, using HMAC-SHA-256 HKDF expansion client-side for zero-knowledge end-to-end encryption without transmitting master secrets or raw PRF outputs to the server.
globs: src/**/*.{ts,tsx,js,mjs}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-prf-key-derivation-standard-webauthn-level-3-782"
---

# Deterministic Client-Side Key Derivation via WebAuthn Level 3 PRF Extension

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Deriving Encryption Keys from Server Secrets, Passwords, or Sending Raw PRF Outputs Across Network Boundaries

## System Constraints
You are a Principal Security Architect enforcing the WebAuthn Level 3 PRF Extension Key Derivation Standard. You must mandate that client-side encryption keys are deterministically derived via the authenticator PRF extension with constant salt inputs, HKDF-SHA-256 expansion, and strict zero-knowledge memory safety. Never allow raw PRF outputs, master derivation seeds, or plaintext keys to be serialized into logs, transmitted to server endpoints, stored in Web Storage, or held in unmanaged memory buffers.

## Strict Guidelines
- Engineers MUST ALWAYS verify client and authenticator support for the PRF extension via PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable() and client extension capability checks before initiating key derivation ceremonies.
- Engineers MUST ALWAYS supply a cryptographically secure, application-scoped salt (at least 32 bytes) within `extensions.prf.eval.first` during `navigator.credentials.get()` assertions.
- Engineers MUST ALWAYS feed the returned `prf.results.first` ArrayBuffer into Web Crypto API `subtle.importKey('raw', ...)` followed by HKDF (HMAC-SHA-256) expansion with domain separation tags to derive operational keys (e.g., AES-GCM-256).
- Engineers MUST NOT transmit the raw PRF result or derived master encryption keys to any backend server, telemetry collector, or persistent client-side storage (localStorage, IndexedDB, sessionStorage).
- Code MUST explicitly zero out transient ArrayBuffers containing PRF output using `crypto.getRandomValues()` or in-place typed array overwrites immediately after HKDF operational key derivation.
- Services MUST validate assertion signatures and authenticator data on the backend while treating the derived E2EE operational keys as completely zero-knowledge to the server.

## Bad vs Good Implementations
### Deterministic Symmetric Key Derivation via WebAuthn PRF and HKDF

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Fails to request the WebAuthn Level 3 PRF extension, derives keys from non-secret public values (credential ID), and transmits sensitive key material across the network boundary, violating zero-knowledge guarantees.
```typescript
// ANTI-PATTERN: Requesting credential assertion without PRF extension, or shipping raw credential ID/derived key to server
export async function getClientEncryptionKey(credentialId: Uint8Array): Promise<CryptoKey> {
  const credential = (await navigator.credentials.get({
    publicKey: {
      challenge: new Uint8Array(32),
      allowCredentials: [{ id: credentialId, type: 'public-key' }],
      userVerification: 'required',
    },
  })) as PublicKeyCredential;

  // Insecure: Deriving encryption key directly from public credential ID or client data
  const rawMaterial = new TextEncoder().encode(credential.id);
  const key = await crypto.subtle.importKey('raw', rawMaterial.slice(0, 32), 'AES-GCM', false, ['encrypt', 'decrypt']);
  
  // Insecure: Leaking derived key or raw PRF results to server
  await fetch('/api/store-key', {
    method: 'POST',
    body: JSON.stringify({ keyMaterial: Array.from(rawMaterial) }),
  });

  return key;
}
```

#### Production Standard (Correct)
> **Standard**: Correctly invokes `extensions.prf.eval.first`, consumes the hardware PRF output through HKDF-SHA-256 to produce an extractable:false AES-GCM-256 CryptoKey, cleanses raw volatile memory buffers via getRandomValues(), and never exposes secrets to the network.
```typescript
// PRODUCTION-GRADE: Deterministic derivation via WebAuthn L3 PRF extension with HKDF expansion and zeroization
const APP_PRF_SALT = new TextEncoder().encode('org.production.e2ee.v1.prf-salt-fixed-32B!');
const HKDF_INFO_TAG = new TextEncoder().encode('org.production.e2ee.aes-gcm-operational-v1');

export async function deriveHardwareBoundKey(credentialId: Uint8Array, challenge: Uint8Array): Promise<CryptoKey> {
  const credential = (await navigator.credentials.get({
    publicKey: {
      challenge,
      allowCredentials: [{ id: credentialId, type: 'public-key' }],
      userVerification: 'required',
      extensions: {
        prf: {
          eval: {
            first: APP_PRF_SALT,
          },
        },
      },
    },
  })) as PublicKeyCredential & { getClientExtensionResults: () => { prf?: { results?: { first: ArrayBuffer } } } };

  const prfResults = credential.getClientExtensionResults().prf?.results;
  if (!prfResults?.first) {
    throw new Error('Authenticator hardware does not support or refused PRF extension evaluation.');
  }

  const prfBytes = new Uint8Array(prfResults.first);

  try {
    // Import PRF output as HKDF key material
    const basePrfKey = await crypto.subtle.importKey(
      'raw',
      prfBytes,
      { name: 'HKDF' },
      false,
      ['deriveKey']
    );

    // Derive scoped operational AES-GCM-256 key
    return await crypto.subtle.deriveKey(
      {
        name: 'HKDF',
        hash: 'SHA-256',
        salt: new Uint8Array(32), // Pre-shared HKDF salt or domain parameter
        info: HKDF_INFO_TAG,
      },
      basePrfKey,
      { name: 'AES-GCM', length: 256 },
      false, // non-extractable
      ['encrypt', 'decrypt']
    );
  } finally {
    // Invariant: Secure zeroization of raw PRF output in volatile memory
    crypto.getRandomValues(prfBytes);
  }
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Deterministic Client-Side Key Derivation via WebAuthn Level 3 PRF Extension

Deterministic Client-Side Key Derivation via WebAuthn Level 3 PRF Extension defines an industrial-grade behavioral standard for security engineering. Enforces hardware-backed, deterministic client-side symmetric key derivation using the WebAuthn Level 3 pseudo-random function (PRF) extension. Mandates that root cryptographic seeds remain exclusively within authenticator hardware bounds, using HMAC-SHA-256 HKDF expansion client-side for zero-knowledge end-to-end encryption without transmitting master secrets or raw PRF outputs to the server. 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: Deriving Encryption Keys from Server Secrets, Passwords, or Sending Raw PRF Outputs Across Network Boundaries 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 DriftDeriving Encryption Keys from Server Secrets, Passwords, or Sending Raw PRF Outputs Across Network BoundariesCritical
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 PRF extension via PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable() and client extension capability checks before initiating key derivation ceremonies.

Engineers MUST ALWAYS verify client and authenticator support for the PRF extension via PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable() and client extension capability checks before initiating key derivation ceremonies.

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 supply a cryptographically secure, application-scoped salt (at least 32 bytes) within `extensions.prf.eval.first` during `navigator.credentials.get()` assertions.

Engineers MUST ALWAYS supply a cryptographically secure, application-scoped salt (at least 32 bytes) within `extensions.prf.eval.first` during `navigator.credentials.get()` assertions.

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 feed the returned `prf.results.first` ArrayBuffer into Web Crypto API `subtle.importKey('raw', ...)` followed by HKDF (HMAC-SHA-256) expansion with domain separation tags to derive operational keys (e.g., AES-GCM-256).

Engineers MUST ALWAYS feed the returned `prf.results.first` ArrayBuffer into Web Crypto API `subtle.importKey('raw', ...)` followed by HKDF (HMAC-SHA-256) expansion with domain separation tags to derive operational keys (e.g., AES-GCM-256).

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 NOT transmit the raw PRF result or derived master encryption keys to any backend server, telemetry collector, or persistent client-side storage (localStorage, IndexedDB, sessionStorage).

Engineers MUST NOT transmit the raw PRF result or derived master encryption keys to any backend server, telemetry collector, or persistent client-side storage (localStorage, IndexedDB, sessionStorage).

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 explicitly zero out transient ArrayBuffers containing PRF output using `crypto.getRandomValues()` or in-place typed array overwrites immediately after HKDF operational key derivation.

Code MUST explicitly zero out transient ArrayBuffers containing PRF output using `crypto.getRandomValues()` or in-place typed array overwrites immediately after HKDF operational 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.
6

Services MUST validate assertion signatures and authenticator data on the backend while treating the derived E2EE operational keys as completely zero-knowledge to the server.

Services MUST validate assertion signatures and authenticator data on the backend while treating the derived E2EE operational keys as completely zero-knowledge to the 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.
Technical Questions & Answers

Frequently Asked Technical Questions

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

Q:Why is Deterministic Client-Side Key Derivation via WebAuthn Level 3 PRF Extension critical for AI coding assistants?

Enforces hardware-backed, deterministic client-side symmetric key derivation using the WebAuthn Level 3 pseudo-random function (PRF) extension. Mandates that root cryptographic seeds remain exclusively within authenticator hardware bounds, using HMAC-SHA-256 HKDF expansion client-side for zero-knowledge end-to-end encryption without transmitting master secrets or raw PRF outputs to the server. 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 (Deriving Encryption Keys from Server Secrets, Passwords, or Sending Raw PRF Outputs Across Network Boundaries) 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

Deterministic