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

WebAuthn Level 3 PRF Hardware-Enforced Root Key Derivation

Enforces hardware-backed deterministic root key derivation via the WebAuthn Level 3 PRF (Pseudo-Random Function) extension for zero-knowledge client-side storage encryption. Mandates strict client-side negotiation verification, user-verification enforcement, ephemeral in-memory lifecycle bounds, and mandatory HKDF domain separation prior to operational key generation.

Prohibited Anti-Pattern: Deriving Storage Encryption Keys via Software KDFs or Caching Raw PRF Secrets in Insecure Storage

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn Level 3 PRF Hardware-Enforced Root Key Derivation - Enforces hardware-backed deterministic root key derivation via the WebAuthn Level 3 PRF (Pseudo-Random Function) extension for zero-knowledge client-side storage encryption. Mandates strict client-side negotiation verification, user-verification enforcement, ephemeral in-memory lifecycle bounds, and mandatory HKDF domain separation prior to operational key generation.
globs: src/**/crypto/**/*.{ts,tsx}, src/**/auth/**/*.{ts,tsx}, src/**/security/**/*.{ts,tsx}, src/**/storage/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-l3-prf-hardware-key-derivation-standard"
---

# WebAuthn Level 3 PRF Hardware-Enforced Root Key Derivation

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Deriving Storage Encryption Keys via Software KDFs or Caching Raw PRF Secrets in Insecure Storage

## System Constraints
You are a Principal Cryptography and Security Engineer enforcing the WebAuthn Level 3 PRF Hardware Key Derivation Standard. You must reject any client-side encryption mechanism that uses software passwords, bypasses authenticator-level PRF evaluation, persists raw root seeds in persistent browser storage, or transmits derived tenant master keys to any server.

## Strict Guidelines
- Engineers MUST ALWAYS enforce `userVerification: 'required'` during WebAuthn credential assertion and creation when invoking the PRF extension.
- Engineers MUST ALWAYS verify that `assertion.getClientExtensionResults().prf` returns a valid evaluation output before proceeding with data decryption or key material derivation.
- Engineers MUST NEVER persist raw PRF output (`results.prf.results.first`) into persistent browser storage such as `localStorage`, `sessionStorage`, or unencrypted `IndexedDB`.
- Code MUST pipe the raw PRF evaluation output through HKDF (RFC 5869) using `crypto.subtle.deriveKey` or `crypto.subtle.deriveBits` with an explicit, distinct `info` context string to enforce strict cryptographic domain separation.
- Services MUST NEVER send client-side PRF inputs, PRF outputs, or derived tenant encryption keys to relying party backend servers over any transport.
- Components NEVER hold derived CryptoKey handles globally; operational keys MUST be scoped ephemerally to active authenticated session memory and scrubbed/dereferenced on lock or sign-out.

## Bad vs Good Implementations
### WebAuthn PRF Hardware Key Derivation and HKDF Domain Separation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The bad example falls back to a software PBKDF2 seed stored in insecure `localStorage`, uses `userVerification: 'preferred'` which bypasses biometric/PIN enforcement, fails to request the WebAuthn Level 3 `prf` extension, and exposes extractable operational keys.
```typescript
export async function getTenantEncryptionKey(credentialId: string, salt: Uint8Array): Promise<CryptoKey> {
  // ANTI-PATTERN: Bypassing hardware PRF evaluation and deriving keys from a cached password
  const cachedSecret = localStorage.getItem('tenant_master_seed');
  if (cachedSecret) {
    const rawKey = new TextEncoder().encode(cachedSecret);
    const baseKey = await crypto.subtle.importKey('raw', rawKey, 'PBKDF2', false, ['deriveKey']);
    return crypto.subtle.deriveKey(
      { name: 'PBKDF2', salt, iterations: 100000, hash: 'SHA-256' },
      baseKey,
      { name: 'AES-GCM', length: 256 },
      true,
      ['encrypt', 'decrypt']
    );
  }

  // ANTI-PATTERN: Authenticator called without PRF extension and without userVerification: 'required'
  const credential = await navigator.credentials.get({
    publicKey: {
      challenge: crypto.getRandomValues(new Uint8Array(32)),
      allowCredentials: [{ id: Uint8Array.from(atob(credentialId), c => c.charCodeAt(0)), type: 'public-key' }],
      userVerification: 'preferred'
    }
  }) as PublicKeyCredential;

  // Fallback to storing insecure client material
  const simulatedSecret = crypto.randomUUID();
  localStorage.setItem('tenant_master_seed', simulatedSecret);
  throw new Error('Fallback invoked without PRF hardware binding');
}
```

#### Production Standard (Correct)
> **Standard**: The good example correctly declares `userVerification: 'required'`, requests the Level 3 `prf` extension with an authenticator-evaluated salt, verifies the extension result exists, treats the hardware output as HKDF key material with cryptographic domain separation, and sets `extractable: false` on derived keys.
```typescript
export interface PrfDerivationOptions {
  credentialId: Uint8Array;
  challenge: Uint8Array;
  domainSalt: Uint8Array;
  contextInfo: Uint8Array;
}

export async function deriveHardwareTenantKey(
  options: PrfDerivationOptions
): Promise<CryptoKey> {
  const assertion = (await navigator.credentials.get({
    publicKey: {
      challenge: options.challenge,
      allowCredentials: [{
        id: options.credentialId,
        type: 'public-key',
        transports: ['internal', 'usb', 'nfc', 'ble']
      }],
      userVerification: 'required',
      extensions: {
        prf: {
          eval: {
            first: options.domainSalt
          }
        }
      }
    }
  })) as PublicKeyCredential;

  if (!assertion) {
    throw new Error('Authenticator assertion rejected or unavailable');
  }

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

  if (!prfResult) {
    throw new Error('WebAuthn PRF extension not supported or failed evaluation by authenticator');
  }

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

  // Deterministically derive operational AES-GCM key with domain separation
  return crypto.subtle.deriveKey(
    {
      name: 'HKDF',
      hash: 'SHA-256',
      salt: options.domainSalt,
      info: options.contextInfo
    },
    rootKeyMaterial,
    {
      name: 'AES-GCM',
      length: 256
    },
    false,
    ['encrypt', 'decrypt']
  );
}
```

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 Hardware-Enforced Root Key Derivation

WebAuthn Level 3 PRF Hardware-Enforced Root Key Derivation defines an industrial-grade behavioral standard for security engineering. Enforces hardware-backed deterministic root key derivation via the WebAuthn Level 3 PRF (Pseudo-Random Function) extension for zero-knowledge client-side storage encryption. Mandates strict client-side negotiation verification, user-verification enforcement, ephemeral in-memory lifecycle bounds, and mandatory HKDF domain separation prior to operational key generation. 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 Storage Encryption Keys via Software KDFs or Caching Raw PRF Secrets in Insecure 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 DriftDeriving Storage Encryption Keys via Software KDFs or Caching Raw PRF Secrets in Insecure 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 enforce `userVerification

Engineers MUST ALWAYS enforce `userVerification: 'required'` during WebAuthn credential assertion and creation when invoking the 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.
2

Engineers MUST ALWAYS verify that `assertion.getClientExtensionResults().prf` returns a valid evaluation output before proceeding with data decryption or key material derivation.

Engineers MUST ALWAYS verify that `assertion.getClientExtensionResults().prf` returns a valid evaluation output before proceeding with data decryption or key material 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.
3

Engineers MUST NEVER persist raw PRF output (`results.prf.results.first`) into persistent browser storage such as `localStorage`, `sessionStorage`, or unencrypted `IndexedDB`.

Engineers MUST NEVER persist raw PRF output (`results.prf.results.first`) into persistent browser storage such as `localStorage`, `sessionStorage`, or unencrypted `IndexedDB`.

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 pipe the raw PRF evaluation output through HKDF (RFC 5869) using `crypto.subtle.deriveKey` or `crypto.subtle.deriveBits` with an explicit, distinct `info` context string to enforce strict cryptographic domain separation.

Code MUST pipe the raw PRF evaluation output through HKDF (RFC 5869) using `crypto.subtle.deriveKey` or `crypto.subtle.deriveBits` with an explicit, distinct `info` context string to enforce strict cryptographic domain separation.

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 NEVER send client-side PRF inputs, PRF outputs, or derived tenant encryption keys to relying party backend servers over any transport.

Services MUST NEVER send client-side PRF inputs, PRF outputs, or derived tenant encryption keys to relying party backend servers over any transport.

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 NEVER hold derived CryptoKey handles globally

Components NEVER hold derived CryptoKey handles globally; operational keys MUST be scoped ephemerally to active authenticated session memory and scrubbed/dereferenced on lock or sign-out.

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

Enforces hardware-backed deterministic root key derivation via the WebAuthn Level 3 PRF (Pseudo-Random Function) extension for zero-knowledge client-side storage encryption. Mandates strict client-side negotiation verification, user-verification enforcement, ephemeral in-memory lifecycle bounds, and mandatory HKDF domain separation prior to operational key generation. 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 Storage Encryption Keys via Software KDFs or Caching Raw PRF Secrets in Insecure 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