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

WebAuthn PRF Extension Zero-Knowledge Master Key Derivation Standard

Enforces strict client-side derivation of zero-knowledge symmetric master keys using the WebAuthn Pseudo-Random Function (PRF) extension. Mandates that PRF output bytes never cross the network boundary to Relying Party (RP) servers, requires HKDF domain separation for secondary key expansion, and enforces non-extractable WebCrypto key representations.

Prohibited Anti-Pattern: Exposing Raw Authenticator PRF Outputs to Backend Servers or Reusing PRF Entropy Directly as Symmetric Cipher Keys

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn PRF Extension Zero-Knowledge Master Key Derivation Standard - Enforces strict client-side derivation of zero-knowledge symmetric master keys using the WebAuthn Pseudo-Random Function (PRF) extension. Mandates that PRF output bytes never cross the network boundary to Relying Party (RP) servers, requires HKDF domain separation for secondary key expansion, and enforces non-extractable WebCrypto key representations.
globs: src/**/*.{ts,tsx}, lib/**/*.{ts,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-prf-zk-key-derivation-standard-webauthn-prf-ext-194"
---

# WebAuthn PRF Extension Zero-Knowledge Master Key Derivation Standard

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Exposing Raw Authenticator PRF Outputs to Backend Servers or Reusing PRF Entropy Directly as Symmetric Cipher Keys

## System Constraints
You are a Principal Cryptography and Security Architect enforcing the WebAuthn PRF Extension Zero-Knowledge Master Key Derivation Standard. You must ensure that authenticator PRF outputs remain strictly client-side, are hardened using HKDF (RFC 5869) with domain-specific salt and info parameters, and generate non-extractable CryptoKey handles to prevent key exfiltration.

## Strict Guidelines
- Engineers MUST ALWAYS isolate PRF outputs on the client; PRF results retrieved from `assertion.getClientExtensionResults().prf` MUST NEVER be forwarded to the Relying Party (RP) backend inside the authentication response payload.
- Engineers MUST ALWAYS feed raw PRF secret outputs into a Key Derivation Function (HKDF-SHA256 via SubtleCrypto.deriveKey) using an application-unique cryptographic salt and domain-separated `info` parameter before performing bulk encryption.
- Engineers MUST NEVER use raw PRF output directly as an AES-GCM or ChaCha20-Poly1305 symmetric key.
- Code MUST import the derived master key as a non-extractable `CryptoKey` (`extractable: false`) within WebCrypto to prevent in-memory inspection or malicious cross-script leakage.
- Services MUST gracefully verify whether the authenticator supports the `prf` extension during registration and authentication, handling authenticators that lack HMAC-secret/PRF capability without hanging or degrading without warning.

## Bad vs Good Implementations
### Client-Side Zero-Knowledge Key Derivation via WebAuthn PRF

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The flawed implementation transmits the raw PRF entropy to the server, completely defeating the zero-knowledge guarantee. It also bypasses HKDF domain separation and imports the key as 'extractable: true', allowing XSS payloads to inspect and exfiltrate the master key from memory.
```typescript
// BAD: Transmitting PRF output to server and using raw bytes directly as AES key
export async function unlockUserVault(credentialId: string, challenge: Uint8Array) {
  const credential = (await navigator.credentials.get({
    publicKey: {
      challenge,
      allowCredentials: [{ id: Uint8Array.from(atob(credentialId), c => c.charCodeAt(0)), type: 'public-key' }],
      extensions: {
        prf: {
          eval: { first: new Uint8Array(32).fill(0x01) } // Static unversioned salt
        }
      }
    }
  })) as PublicKeyCredential;

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

  // CRITICAL VULNERABILITY: Leaking raw zero-knowledge secret to backend API
  await fetch('/api/vault/verify-and-sync', {
    method: 'POST',
    body: JSON.stringify({
      credential,
      rawKeyBytes: Array.from(new Uint8Array(rawPrf as ArrayBuffer))
    })
  });

  // CRITICAL VULNERABILITY: Raw PRF bytes used directly without HKDF; extractable key
  return window.crypto.subtle.importKey(
    'raw',
    rawPrf as ArrayBuffer,
    { name: 'AES-GCM' },
    true, // Extractable! Accessible by XSS
    ['encrypt', 'decrypt']
  );
}
```

#### Production Standard (Correct)
> **Standard**: The correct implementation maintains strict zero-knowledge invariants. The raw PRF evaluation is never bundled into server payloads, is imported purely as HKDF IKM, and derives a non-extractable AES-256-GCM CryptoKey using domain-separated static context.
```typescript
// GOOD: PRF output remains client-side, is expanded via HKDF, and kept non-extractable
const DOMAIN_SALT = new TextEncoder().encode('zk-vault-v1:hkdf-salt:app.example.com');
const KEY_INFO = new TextEncoder().encode('zk-vault-v1:client-storage-master-key');

export async function deriveZeroKnowledgeMasterKey(
  credentialId: Uint8Array,
  challenge: Uint8Array,
  prfInputSalt: Uint8Array
): Promise<CryptoKey> {
  const credential = (await navigator.credentials.get({
    publicKey: {
      challenge,
      allowCredentials: [{ id: credentialId, type: 'public-key' }],
      extensions: {
        prf: {
          eval: { first: prfInputSalt }
        }
      }
    }
  })) as PublicKeyCredential | null;

  if (!credential) {
    throw new Error('Authentication assertion failed: null credential returned.');
  }

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

  if (!prfResult) {
    throw new Error('Authenticator does not support or failed to evaluate WebAuthn PRF extension.');
  }

  // Import raw PRF output strictly as an HKDF initial keying material (IKM)
  const ikmKey = await window.crypto.subtle.importKey(
    'raw',
    prfResult,
    { name: 'HKDF' },
    false,
    ['deriveKey']
  );

  // Derive non-extractable AES-GCM-256 master storage key with strict domain separation
  return window.crypto.subtle.deriveKey(
    {
      name: 'HKDF',
      hash: 'SHA-256',
      salt: DOMAIN_SALT,
      info: KEY_INFO
    },
    ikmKey,
    { name: 'AES-GCM', length: 256 },
    false, // Enforce non-extractable: cannot be exported or leaked via XSS memory dumping
    ['encrypt', 'decrypt']
  );
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: WebAuthn PRF Extension Zero-Knowledge Master Key Derivation Standard

WebAuthn PRF Extension Zero-Knowledge Master Key Derivation Standard defines an industrial-grade behavioral standard for security engineering. Enforces strict client-side derivation of zero-knowledge symmetric master keys using the WebAuthn Pseudo-Random Function (PRF) extension. Mandates that PRF output bytes never cross the network boundary to Relying Party (RP) servers, requires HKDF domain separation for secondary key expansion, and enforces non-extractable WebCrypto key representations. 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 Authenticator PRF Outputs to Backend Servers or Reusing PRF Entropy Directly as Symmetric Cipher Keys 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 Authenticator PRF Outputs to Backend Servers or Reusing PRF Entropy Directly as Symmetric Cipher KeysCritical
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 isolate PRF outputs on the client

Engineers MUST ALWAYS isolate PRF outputs on the client; PRF results retrieved from `assertion.getClientExtensionResults().prf` MUST NEVER be forwarded to the Relying Party (RP) backend inside the authentication response payload.

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 feed raw PRF secret outputs into a Key Derivation Function (HKDF-SHA256 via SubtleCrypto.deriveKey) using an application-unique cryptographic salt and domain-separated `info` parameter before performing bulk encryption.

Engineers MUST ALWAYS feed raw PRF secret outputs into a Key Derivation Function (HKDF-SHA256 via SubtleCrypto.deriveKey) using an application-unique cryptographic salt and domain-separated `info` parameter before performing bulk encryption.

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 use raw PRF output directly as an AES-GCM or ChaCha20-Poly1305 symmetric key.

Engineers MUST NEVER use raw PRF output directly as an AES-GCM or ChaCha20-Poly1305 symmetric 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.
4

Code MUST import the derived master key as a non-extractable `CryptoKey` (`extractable

Code MUST import the derived master key as a non-extractable `CryptoKey` (`extractable: false`) within WebCrypto to prevent in-memory inspection or malicious cross-script leakage.

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 gracefully verify whether the authenticator supports the `prf` extension during registration and authentication, handling authenticators that lack HMAC-secret/PRF capability without hanging or degrading without warning.

Services MUST gracefully verify whether the authenticator supports the `prf` extension during registration and authentication, handling authenticators that lack HMAC-secret/PRF capability without hanging or degrading without warning.

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

Enforces strict client-side derivation of zero-knowledge symmetric master keys using the WebAuthn Pseudo-Random Function (PRF) extension. Mandates that PRF output bytes never cross the network boundary to Relying Party (RP) servers, requires HKDF domain separation for secondary key expansion, and enforces non-extractable WebCrypto key representations. 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 Authenticator PRF Outputs to Backend Servers or Reusing PRF Entropy Directly as Symmetric Cipher Keys) 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