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

Zero-Knowledge Hardware-Bound Key Derivation via WebAuthn PRF Extension

Enforces cryptographic invariants when deriving client-side End-to-End Encryption (E2EE) root keys from WebAuthn Pseudo-Random Function (PRF) extension outputs (HMAC-secret). Mandates zero-knowledge isolation ensuring neither PRF salt inputs, intermediate PRF outputs, nor derived key encryption keys (KEKs) leak across network boundaries or unmanaged volatile memory buffers.

Prohibited Anti-Pattern: Leaking PRF outputs to authentication servers or directly using raw PRF symmetric outputs as symmetric data encryption keys (DEKs)

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Zero-Knowledge Hardware-Bound Key Derivation via WebAuthn PRF Extension - Enforces cryptographic invariants when deriving client-side End-to-End Encryption (E2EE) root keys from WebAuthn Pseudo-Random Function (PRF) extension outputs (HMAC-secret). Mandates zero-knowledge isolation ensuring neither PRF salt inputs, intermediate PRF outputs, nor derived key encryption keys (KEKs) leak across network boundaries or unmanaged volatile memory buffers.
globs: src/**/*.{ts,tsx}, lib/**/*.{ts,tsx}, services/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-prf-zk-e2ee-key-derivation-standard"
---

# Zero-Knowledge Hardware-Bound Key Derivation via WebAuthn PRF Extension

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Leaking PRF outputs to authentication servers or directly using raw PRF symmetric outputs as symmetric data encryption keys (DEKs)

## System Constraints
You are a Principal Cryptographic Architect enforcing zero-knowledge client-side encryption using the WebAuthn PRF (Pseudo-Random Function) extension. Your goal is to guarantee that authenticator-derived secrets remain strictly client-side, ephemeral, and properly fortified via HKDF/KDF pipelines without ever hitting remote auth endpoints or persisting unencrypted in memory.

## Strict Guidelines
- Engineers MUST ALWAYS treat WebAuthn PRF outputs (`results.prf.results.first`) as transient High-Entropy Seed Material (IKM) and pass it through HKDF-Extract and HKDF-Expand (RFC 5869) using SHA-256 before generating operational Key Encryption Keys (KEK).
- Engineers MUST NOT transmit raw PRF extension outputs, salts, or derived symmetric keys in client-to-server payloads during registration or authentication assertions (`navigator.credentials.create` or `navigator.credentials.get`).
- Code MUST explicitly test for PRF extension capability negotiation (`clientExtensionResults.prf.enabled`) during credential creation and fail-closed if PRF is unsupported on the authenticator.
- Services MUST enforce envelope encryption: derived PRF keys MUST only decrypt an asymmetrical or symmetrical Data Encryption Key (DEK) and MUST NEVER directly encrypt variable-length user application payloads.
- Components NEVER store derived master keys or raw PRF evaluation buffers in `localStorage`, `sessionStorage`, IndexedDB, or non-garbage-collected global module singletons; derived CryptoKey handles MUST be non-extractable (`extractable: false`).

## Bad vs Good Implementations
### Zero-Knowledge PRF Assertion and HKDF Key Derivation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Transmits raw assertion response without decoupling PRF results, exposes raw PRF bytes to the server, skips the obligatory HKDF domain separation step, and imports the key as extractable.
```typescript
export async function authenticateAndUnlock(assertionResponse: PublicKeyCredential) {
  // Flaw 1: Sending assertion output with PRF directly to server
  await fetch('/api/auth/verify', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(assertionResponse)
  });

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

  // Flaw 2: Direct usage of PRF output as raw AES-GCM key without HKDF
  // Flaw 3: Marking the key as extractable
  const rawKey = await crypto.subtle.importKey(
    'raw',
    rawPrf,
    { name: 'AES-GCM' },
    true,
    ['encrypt', 'decrypt']
  );

  return rawKey;
}
```

#### Production Standard (Correct)
> **Standard**: Validates PRF output availability, processes output as non-extractable HKDF input material with domain separation info and application salt, ensures the final AES-GCM KEK is strictly non-extractable, and zeroizes raw byte buffers in memory.
```typescript
export async function authenticateAndDeriveMasterKEK(
  credential: PublicKeyCredential,
  domainSalt: Uint8Array
): Promise<CryptoKey> {
  const extensionResults = credential.getClientExtensionResults();
  
  if (!extensionResults.prf?.results?.first) {
    throw new Error('WebAuthn PRF extension output not available or unsupported by authenticator');
  }

  const prfIkm = new Uint8Array(extensionResults.prf.results.first);
  const infoBuffer = new TextEncoder().encode('org.production.e2ee.v1.kek');

  try {
    // Import raw PRF output as input keying material (IKM) for HKDF
    const initialKeyMaterial = await crypto.subtle.importKey(
      'raw',
      prfIkm,
      { name: 'HKDF' },
      false,
      ['deriveKey']
    );

    // Derive an isolated, non-extractable Key Encryption Key (KEK)
    return await crypto.subtle.deriveKey(
      {
        name: 'HKDF',
        hash: 'SHA-256',
        salt: domainSalt,
        info: infoBuffer
      },
      initialKeyMaterial,
      { name: 'AES-GCM', length: 256 },
      false,
      ['wrapKey', 'unwrapKey']
    );
  } finally {
    // Scrub transient raw byte buffers
    prfIkm.fill(0);
  }
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Zero-Knowledge Hardware-Bound Key Derivation via WebAuthn PRF Extension

Zero-Knowledge Hardware-Bound Key Derivation via WebAuthn PRF Extension defines an industrial-grade behavioral standard for security engineering. Enforces cryptographic invariants when deriving client-side End-to-End Encryption (E2EE) root keys from WebAuthn Pseudo-Random Function (PRF) extension outputs (HMAC-secret). Mandates zero-knowledge isolation ensuring neither PRF salt inputs, intermediate PRF outputs, nor derived key encryption keys (KEKs) leak across network boundaries or unmanaged volatile memory buffers. 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: Leaking PRF outputs to authentication servers or directly using raw PRF symmetric outputs as symmetric data encryption keys (DEKs) 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 DriftLeaking PRF outputs to authentication servers or directly using raw PRF symmetric outputs as symmetric data encryption keys (DEKs)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 treat WebAuthn PRF outputs (`results.prf.results.first`) as transient High-Entropy Seed Material (IKM) and pass it through HKDF-Extract and HKDF-Expand (RFC 5869) using SHA-256 before generating operational Key Encryption Keys (KEK).

Engineers MUST ALWAYS treat WebAuthn PRF outputs (`results.prf.results.first`) as transient High-Entropy Seed Material (IKM) and pass it through HKDF-Extract and HKDF-Expand (RFC 5869) using SHA-256 before generating operational Key Encryption Keys (KEK).

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 extension outputs, salts, or derived symmetric keys in client-to-server payloads during registration or authentication assertions (`navigator.credentials.create` or `navigator.credentials.get`).

Engineers MUST NOT transmit raw PRF extension outputs, salts, or derived symmetric keys in client-to-server payloads during registration or authentication assertions (`navigator.credentials.create` or `navigator.credentials.get`).

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 explicitly test for PRF extension capability negotiation (`clientExtensionResults.prf.enabled`) during credential creation and fail-closed if PRF is unsupported on the authenticator.

Code MUST explicitly test for PRF extension capability negotiation (`clientExtensionResults.prf.enabled`) during credential creation and fail-closed if PRF is unsupported on the authenticator.

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 enforce envelope encryption

Services MUST enforce envelope encryption: derived PRF keys MUST only decrypt an asymmetrical or symmetrical Data Encryption Key (DEK) and MUST NEVER directly encrypt variable-length user application payloads.

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 master keys or raw PRF evaluation buffers in `localStorage`, `sessionStorage`, IndexedDB, or non-garbage-collected global module singletons

Components NEVER store derived master keys or raw PRF evaluation buffers in `localStorage`, `sessionStorage`, IndexedDB, or non-garbage-collected global module singletons; derived CryptoKey handles MUST be non-extractable (`extractable: false`).

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 Zero-Knowledge Hardware-Bound Key Derivation via WebAuthn PRF Extension critical for AI coding assistants?

Enforces cryptographic invariants when deriving client-side End-to-End Encryption (E2EE) root keys from WebAuthn Pseudo-Random Function (PRF) extension outputs (HMAC-secret). Mandates zero-knowledge isolation ensuring neither PRF salt inputs, intermediate PRF outputs, nor derived key encryption keys (KEKs) leak across network boundaries or unmanaged volatile memory buffers. 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 (Leaking PRF outputs to authentication servers or directly using raw PRF symmetric outputs as symmetric data encryption keys (DEKs)) 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

Zero-Knowledge