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-guardrail-webauthn-prf-ext-843

WebAuthn PRF Extension Zero-Knowledge Key Derivation Standard

Enforces strict cryptographic invariants for authenticating with the WebAuthn Pseudo-Random Function (PRF) extension (HMAC-secret). Guarantees that symmetric encryption keys are derived from hardware-isolated authenticator secrets combined with client-side HKDF, preventing plaintext application master keys or credential passphrases from ever touching host memory or network transit.

Prohibited Anti-Pattern: Deriving client encryption keys from user passphrases in memory or transmitting raw PRF outputs over the wire

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn PRF Extension Zero-Knowledge Key Derivation Standard - Enforces strict cryptographic invariants for authenticating with the WebAuthn Pseudo-Random Function (PRF) extension (HMAC-secret). Guarantees that symmetric encryption keys are derived from hardware-isolated authenticator secrets combined with client-side HKDF, preventing plaintext application master keys or credential passphrases from ever touching host memory or network transit.
globs: src/**/auth/**/*.{ts,tsx}, src/**/crypto/**/*.{ts,tsx}, src/**/vault/**/*.{ts,tsx}, src/**/services/webauthn*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-prf-zk-key-derivation-guardrail-webauthn-prf-ext-843"
---

# WebAuthn PRF Extension Zero-Knowledge Key Derivation Standard

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Deriving client encryption keys from user passphrases in memory or transmitting raw PRF outputs over the wire

## System Constraints
You are a Principal Cryptographic Systems Architect enforcing hardware-bound zero-knowledge key management via the WebAuthn PRF (HMAC-secret) extension. Mandate that all symmetric key derivations leverage navigator.credentials.get with prf extensions, using cryptographically stable salts and standard HKDF-SHA256 expansions directly into non-extractable CryptoKey handles. Strictly prohibit fallback to user-entered passphrases in application memory, storing raw PRF secrets, or leaking derived keys to analytics, telemetry, or network payloads.

## Strict Guidelines
- Engineers MUST ALWAYS evaluate navigator.credentials.get with extensions: { prf: { eval: { first: saltBuffer } } } using a 32-byte cryptographically secure, application-scoped salt.
- Engineers MUST import PRF output bytes into WebCrypto as a non-extractable CryptoKey handle immediately after derivation, zeroing out intermediate Uint8Arrays.
- Engineers MUST NOT expose the raw PRF output or derived root encryption keys to server payloads, LocalStorage, IndexedDB, window state, or telemetry streams.
- Engineers MUST execute HKDF-SHA256 with distinct domain-separation context strings ('info' parameter) for distinct cryptographic intents (e.g., encryption vs authentication vs signing).
- Services MUST verify authenticator PRF support via ClientCapabilities or credentials.create({ extensions: { prf: {} } }) during registration and reject insecure client-side polyfills or plaintext fallback mechanisms.
- Components NEVER accept plain master passwords in React/Vue/Svelte form state when the zero-knowledge hardware PRF profile is active.

## Bad vs Good Implementations
### Hardware PRF Derivation vs In-Memory PBKDF2 Password Derivation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Derives keys from in-memory user inputs, leaks the key through extractable WebCrypto handles, and leaves the application susceptible to process memory scraping, XSS credential harvesting, and lack of hardware isolation.
```typescript
// BAD: Accepting a user master passphrase in host memory and deriving keys with in-memory PBKDF2
// Memory dumps, XSS, or rogue dependencies can extract the master plaintext secret.
export async function deriveVaultKey(userProvidedPassphrase: string, salt: Uint8Array): Promise<CryptoKey> {
  const enc = new TextEncoder();
  const rawKeyMaterial = enc.encode(userProvidedPassphrase);
  
  const baseKey = await window.crypto.subtle.importKey(
    'raw',
    rawKeyMaterial,
    'PBKDF2',
    false,
    ['deriveKey']
  );

  return window.crypto.subtle.deriveKey(
    {
      name: 'PBKDF2',
      salt: salt,
      iterations: 100000,
      hash: 'SHA-256'
    },
    baseKey,
    { name: 'AES-GCM', length: 256 },
    true, // CRITICAL: Extractable key in memory!
    ['encrypt', 'decrypt']
  );
}
```

#### Production Standard (Correct)
> **Standard**: Derives a 256-bit AES-GCM key inside the WebCrypto subsystem from hardware authenticator HMAC output. The derived key is non-extractable, the raw PRF buffer is instantly scrubbed from memory with fill(0), and no application password ever enters the DOM or runtime environment.
```typescript
// GOOD: Hardware-isolated zero-knowledge key derivation using WebAuthn PRF extension
// Plaintext root secrets never exist in application host memory.
export async function deriveVaultKeyWithWebAuthnPRF(
  credentialId: Uint8Array,
  staticVaultSalt: Uint8Array
): Promise<CryptoKey> {
  if (staticVaultSalt.byteLength !== 32) {
    throw new Error('PRF input salt must be exactly 32 bytes.');
  }

  const assertion = await navigator.credentials.get({
    publicKey: {
      challenge: crypto.getRandomValues(new Uint8Array(32)),
      allowCredentials: [{ id: credentialId, type: 'public-key' }],
      userVerification: 'required',
      extensions: {
        prf: {
          eval: {
            first: staticVaultSalt
          }
        }
      }
    }
  }) as PublicKeyCredential;

  const extensionResults = assertion.getClientExtensionResults();
  const prfResults = extensionResults.prf?.results?.first;
  if (!prfResults) {
    throw new Error('Authenticator did not return PRF output or PRF extension unsupported');
  }

  const prfBytes = new Uint8Array(prfResults);

  try {
    // Import PRF output as non-extractable HKDF master key
    const hkdfKey = await window.crypto.subtle.importKey(
      'raw',
      prfBytes,
      'HKDF',
      false,
      ['deriveKey']
    );

    const infoBuffer = new TextEncoder().encode('vault-aes-gcm-encryption-v1');
    const saltBuffer = new Uint8Array(32); // Domain isolation salt

    return await window.crypto.subtle.deriveKey(
      {
        name: 'HKDF',
        hash: 'SHA-256',
        salt: saltBuffer,
        info: infoBuffer
      },
      hkdfKey,
      { name: 'AES-GCM', length: 256 },
      false, // Invariant: Non-extractable, host cannot dump raw key
      ['encrypt', 'decrypt']
    );
  } finally {
    // Immediately zero-out memory copy of the raw PRF result
    prfBytes.fill(0);
  }
}
```

Architectural Specification & Invariant Rationale

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

WebAuthn PRF Extension Zero-Knowledge Key Derivation Standard defines an industrial-grade behavioral standard for security engineering. Enforces strict cryptographic invariants for authenticating with the WebAuthn Pseudo-Random Function (PRF) extension (HMAC-secret). Guarantees that symmetric encryption keys are derived from hardware-isolated authenticator secrets combined with client-side HKDF, preventing plaintext application master keys or credential passphrases from ever touching host memory or network transit. 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 client encryption keys from user passphrases in memory or transmitting raw PRF outputs over the wire 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 client encryption keys from user passphrases in memory or transmitting raw PRF outputs over the wireCritical
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 evaluate navigator.credentials.get with extensions

Engineers MUST ALWAYS evaluate navigator.credentials.get with extensions: { prf: { eval: { first: saltBuffer } } } using a 32-byte cryptographically secure, application-scoped salt.

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 import PRF output bytes into WebCrypto as a non-extractable CryptoKey handle immediately after derivation, zeroing out intermediate Uint8Arrays.

Engineers MUST import PRF output bytes into WebCrypto as a non-extractable CryptoKey handle immediately after derivation, zeroing out intermediate Uint8Arrays.

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 NOT expose the raw PRF output or derived root encryption keys to server payloads, LocalStorage, IndexedDB, window state, or telemetry streams.

Engineers MUST NOT expose the raw PRF output or derived root encryption keys to server payloads, LocalStorage, IndexedDB, window state, or telemetry streams.

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 execute HKDF-SHA256 with distinct domain-separation context strings ('info' parameter) for distinct cryptographic intents (e.g., encryption vs authentication vs signing).

Engineers MUST execute HKDF-SHA256 with distinct domain-separation context strings ('info' parameter) for distinct cryptographic intents (e.g., encryption vs authentication vs signing).

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 verify authenticator PRF support via ClientCapabilities or credentials.create({ extensions

Services MUST verify authenticator PRF support via ClientCapabilities or credentials.create({ extensions: { prf: {} } }) during registration and reject insecure client-side polyfills or plaintext fallback mechanisms.

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 accept plain master passwords in React/Vue/Svelte form state when the zero-knowledge hardware PRF profile is active.

Components NEVER accept plain master passwords in React/Vue/Svelte form state when the zero-knowledge hardware PRF profile is active.

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

Enforces strict cryptographic invariants for authenticating with the WebAuthn Pseudo-Random Function (PRF) extension (HMAC-secret). Guarantees that symmetric encryption keys are derived from hardware-isolated authenticator secrets combined with client-side HKDF, preventing plaintext application master keys or credential passphrases from ever touching host memory or network transit. 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 client encryption keys from user passphrases in memory or transmitting raw PRF outputs over the wire) 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