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

Hardware-Anchored Zero-Knowledge Vault Encryption via WebAuthn PRF Extension

Enforces zero-knowledge client cryptographic vault encryption anchored directly to hardware-backed FIDO2 authenticators via the WebAuthn PRF (Pseudo-Random Function) extension. Requires non-extractable CryptoKey handles derived via HKDF domain separation and strictly prohibits transmitting PRF outputs, master derivation seeds, or plaintext vault encryption keys to any remote server.

Prohibited Anti-Pattern: Exposing raw WebAuthn PRF outputs over network transport or deriving extractable vault keys without HKDF domain separation.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Hardware-Anchored Zero-Knowledge Vault Encryption via WebAuthn PRF Extension - Enforces zero-knowledge client cryptographic vault encryption anchored directly to hardware-backed FIDO2 authenticators via the WebAuthn PRF (Pseudo-Random Function) extension. Requires non-extractable CryptoKey handles derived via HKDF domain separation and strictly prohibits transmitting PRF outputs, master derivation seeds, or plaintext vault encryption keys to any remote server.
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-vault-key-derivation-standard"
---

# Hardware-Anchored Zero-Knowledge Vault Encryption via WebAuthn PRF Extension

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Exposing raw WebAuthn PRF outputs over network transport or deriving extractable vault keys without HKDF domain separation.

## System Constraints
You are a Principal Security Architect enforcing the WebAuthn PRF Extension Client-Side End-to-End Vault Key Derivation Standard. You must mandate strict zero-knowledge invariants: PRF outputs must never leave client execution context, intermediate raw keys must be derived into non-extractable WebCrypto handles using HKDF domain separation, and authenticators must strictly validate PRF extension support.

## Strict Guidelines
- Engineers MUST ALWAYS import raw PRF outputs into WebCrypto as non-extractable HKDF master keys before deriving final AES-256-GCM Vault Encryption Keys (VEKs).
- Engineers MUST NOT transmit raw PRF output buffers, unencrypted vault keys, or intermediate Key Encryption Keys (KEKs) to the server or any external logging sink.
- Code SHOULD enforce strict domain separation strings (info parameters) in HKDF derivation to isolate different vault operational contexts (e.g., encryption vs. search indices).
- Services MUST verify the presence and success of the PRF extension result (`results.prf.results.first`) and gracefully abort execution if the authenticator lacks PRF support.
- Components NEVER store PRF derivation outputs or decrypted vault secrets in persistent client-side storage (`localStorage`, `IndexedDB`, or service worker caches) in unencrypted format.

## Bad vs Good Implementations
### Insecure PRF handling: transmitting raw PRF secret to server & using extractable keys without HKDF

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Transmits raw authenticator-derived PRF output to a remote server, violating zero-knowledge guarantees. Furthermore, it directly imports the raw PRF result as an extractable AES-GCM key without HKDF domain separation, creating key reuse and extraction risks.
```typescript
export async function unlockVault(credentialId: string, salt: Uint8Array) {
  const credential = (await navigator.credentials.get({
    publicKey: {
      challenge: new Uint8Array(32),
      allowCredentials: [{ id: Uint8Array.from(atob(credentialId), c => c.charCodeAt(0)), type: 'public-key' }],
      extensions: {
        prf: { eval: { first: salt } }
      }
    }
  })) as PublicKeyCredential;

  const extensionResults = credential.getClientExtensionResults();
  const rawPrf = (extensionResults as any).prf?.results?.first;

  // CRITICAL VULNERABILITY: Leaking raw PRF output to the backend server
  await fetch('/api/vault/unlock', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ prfSecret: Array.from(new Uint8Array(rawPrf)) })
  });

  // Insecure: Using raw PRF output directly as extractable AES key without HKDF
  return window.crypto.subtle.importKey(
    'raw',
    rawPrf,
    { name: 'AES-GCM', length: 256 },
    true, // CRITICAL: Extractable key material in browser memory
    ['decrypt', 'encrypt']
  );
}
```

#### Production Standard (Correct)
> **Standard**: Enforces zero-knowledge by keeping all derivation on the client. Validates PRF extension support, imports PRF bytes as an unextractable HKDF master key, applies cryptographic domain separation, and outputs a non-extractable AES-GCM CryptoKey handle without ever transmitting keys over the network.
```typescript
export async function deriveVaultEncryptionKey(
  credentialId: Uint8Array,
  prfSalt: Uint8Array,
  infoContext: string
): Promise<CryptoKey> {
  const credential = (await navigator.credentials.get({
    publicKey: {
      challenge: window.crypto.getRandomValues(new Uint8Array(32)),
      allowCredentials: [{ id: credentialId, type: 'public-key' }],
      userVerification: 'required',
      extensions: {
        prf: { eval: { first: prfSalt } }
      }
    }
  })) as PublicKeyCredential | null;

  if (!credential) {
    throw new Error('Authentication aborted or credential missing.');
  }

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

  // 1. Import PRF output as non-extractable HKDF keying material
  const prfKeyMaterial = await window.crypto.subtle.importKey(
    'raw',
    prfResult,
    { name: 'HKDF' },
    false,
    ['deriveKey']
  );

  // 2. Derive non-extractable AES-256-GCM Vault Key using domain separation
  const encoder = new TextEncoder();
  const vaultKey = await window.crypto.subtle.deriveKey(
    {
      name: 'HKDF',
      hash: 'SHA-256',
      salt: prfSalt,
      info: encoder.encode(`vault-e2ee-key-v1:${infoContext}`)
    },
    prfKeyMaterial,
    { name: 'AES-GCM', length: 256 },
    false,
    ['encrypt', 'decrypt']
  );

  // PRF secret buffer is dropped; vaultKey is held in browser crypto subsystem
  return vaultKey;
}
```

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: Hardware-Anchored Zero-Knowledge Vault Encryption via WebAuthn PRF Extension

Hardware-Anchored Zero-Knowledge Vault Encryption via WebAuthn PRF Extension defines an industrial-grade behavioral standard for security engineering. Enforces zero-knowledge client cryptographic vault encryption anchored directly to hardware-backed FIDO2 authenticators via the WebAuthn PRF (Pseudo-Random Function) extension. Requires non-extractable CryptoKey handles derived via HKDF domain separation and strictly prohibits transmitting PRF outputs, master derivation seeds, or plaintext vault encryption keys to any remote 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: Exposing raw WebAuthn PRF outputs over network transport or deriving extractable vault keys without HKDF domain separation. 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 DriftExposing raw WebAuthn PRF outputs over network transport or deriving extractable vault keys without HKDF domain separation.Critical
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 import raw PRF outputs into WebCrypto as non-extractable HKDF master keys before deriving final AES-256-GCM Vault Encryption Keys (VEKs).

Engineers MUST ALWAYS import raw PRF outputs into WebCrypto as non-extractable HKDF master keys before deriving final AES-256-GCM Vault Encryption Keys (VEKs).

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 buffers, unencrypted vault keys, or intermediate Key Encryption Keys (KEKs) to the server or any external logging sink.

Engineers MUST NOT transmit raw PRF output buffers, unencrypted vault keys, or intermediate Key Encryption Keys (KEKs) to the server or any external logging sink.

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 SHOULD enforce strict domain separation strings (info parameters) in HKDF derivation to isolate different vault operational contexts (e.g., encryption vs. search indices).

Code SHOULD enforce strict domain separation strings (info parameters) in HKDF derivation to isolate different vault operational contexts (e.g., encryption vs. search indices).

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

Services MUST verify the presence and success of the PRF extension result (`results.prf.results.first`) and gracefully abort execution if the authenticator lacks PRF support.

Services MUST verify the presence and success of the PRF extension result (`results.prf.results.first`) and gracefully abort execution if the authenticator lacks PRF support.

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 derivation outputs or decrypted vault secrets in persistent client-side storage (`localStorage`, `IndexedDB`, or service worker caches) in unencrypted format.

Components NEVER store PRF derivation outputs or decrypted vault secrets in persistent client-side storage (`localStorage`, `IndexedDB`, or service worker caches) in unencrypted format.

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 Hardware-Anchored Zero-Knowledge Vault Encryption via WebAuthn PRF Extension critical for AI coding assistants?

Enforces zero-knowledge client cryptographic vault encryption anchored directly to hardware-backed FIDO2 authenticators via the WebAuthn PRF (Pseudo-Random Function) extension. Requires non-extractable CryptoKey handles derived via HKDF domain separation and strictly prohibits transmitting PRF outputs, master derivation seeds, or plaintext vault encryption keys to any remote 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 (Exposing raw WebAuthn PRF outputs over network transport or deriving extractable vault keys without HKDF domain separation.) 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

Hardware-Anchored