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 Client-Side Zero-Knowledge Cryptographic Key Derivation Guardrail

Enforces strict client-side zero-knowledge architectural standards for deriving symmetric cryptographic keys via the WebAuthn Pseudo-Random Function (PRF) extension (HMAC-secret). Prevents leakage of raw PRF outputs, mandates constant salt isolation, enforces subkey derivation using HKDF with quantum-resistant key lengths (AES-256-GCM / XChaCha20-Poly1305), and ensures hardware secrets never transit to relying party backend servers.

Prohibited Anti-Pattern: Transmitting Raw PRF Outputs to Relying Parties or Directly Utilizing Unhashed Hardware Evaluation Results as Symmetric Vault Keys

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn PRF Client-Side Zero-Knowledge Cryptographic Key Derivation Guardrail - Enforces strict client-side zero-knowledge architectural standards for deriving symmetric cryptographic keys via the WebAuthn Pseudo-Random Function (PRF) extension (HMAC-secret). Prevents leakage of raw PRF outputs, mandates constant salt isolation, enforces subkey derivation using HKDF with quantum-resistant key lengths (AES-256-GCM / XChaCha20-Poly1305), and ensures hardware secrets never transit to relying party backend servers.
globs: src/**/*.{ts,tsx,js,mjs}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-prf-zk-key-derivation-standard"
---

# WebAuthn PRF Client-Side Zero-Knowledge Cryptographic Key Derivation Guardrail

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Transmitting Raw PRF Outputs to Relying Parties or Directly Utilizing Unhashed Hardware Evaluation Results as Symmetric Vault Keys

## System Constraints
You are a Principal Security Architect and Cryptographer enforcing WebAuthn PRF Extension Client-Side Zero-Knowledge Key Derivation Standards. You must reject any code pattern that sends PRF evaluation outputs to server-side endpoints, uses deterministic salt reuse without application-domain separation, or binds raw PRF output directly as a symmetric cipher key without HKDF-SHA256/SHA512 expansion. Enforce strict ephemeral memory wiping of intermediate key material and mandate feature detection for PRF extension support across authenticators.

## Strict Guidelines
- Engineers MUST ALWAYS execute WebAuthn PRF key derivation strictly within client-side sandboxes (e.g., Web Workers or browser window runtime) and MUST NEVER serialize, log, or transmit raw PRF output buffers (`results.prf.first` / `results.prf.second`) across the network.
- Engineers MUST ALWAYS pass the raw 32-byte PRF hardware evaluation output through HKDF (RFC 5869) using SHA-256 or SHA-512, with distinct domain-separated `info` labels (e.g., 'vault-encryption-key-v1', 'vault-mac-key-v1') before instantiating symmetric ciphers.
- Engineers MUST NEVER use static zero-buffers or predictable global literals as the PRF input salt; salts MUST be cryptographically bound to the user's credential ID or derived from an account-specific constant 32-byte authenticated salt stored on the client.
- Code SHOULD verify `credential.getClientExtensionResults().prf.enabled` during registration before asserting PRF capability, and implement a graceful fallback or explicit rejection when the authenticator lacks HMAC-secret support.
- Engineers MUST explicitly zero-out (scrub) sensitive TypedArrays (`rawPrfBytes.fill(0)`) immediately after importing them into non-extractable `CryptoKey` handles using `SubtleCrypto.importKey`.

## Bad vs Good Implementations
### Client-Side PRF Evaluation and HKDF Subkey Derivation vs. Remote Leakage

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Directly exfiltrates the raw authenticator PRF output to the backend server, entirely compromising zero-knowledge architecture. Furthermore, it uses a non-32-byte string as an unhashed salt and bypasses client-side HKDF key expansion.
```typescript
export async function unlockUserVault(credentialId: string): Promise<void> {
  // Anti-Pattern: Missing PRF validation, reusing raw PRF output directly,
  // and sending the raw PRF secret to the backend API for decryption.
  const assertion = await navigator.credentials.get({
    publicKey: {
      challenge: new Uint8Array([1, 2, 3]),
      allowCredentials: [{ id: Uint8Array.from(atob(credentialId), c => c.charCodeAt(0)), type: 'public-key' }],
      extensions: {
        prf: {
          eval: {
            first: new TextEncoder().encode('global-salt-1234')
          }
        }
      }
    }
  }) as PublicKeyCredential;

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

  // VULNERABILITY: Raw cryptographic key material exfiltrated over network
  await fetch('/api/vault/decrypt', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      credentialId,
      rawPrfSecret: Array.from(new Uint8Array(rawSecret!))
    })
  });
}
```

#### Production Standard (Correct)
> **Standard**: Enforces 32-byte salt invariants, verifies PRF extension output existence, uses client-side HKDF derivation with strict domain separation, creates a non-extractable CryptoKey, and wipes the intermediate raw PRF memory buffer.
```typescript
export async function unlockUserVault(
  credentialIdBytes: Uint8Array,
  domainSalt: Uint8Array
): Promise<CryptoKey> {
  if (domainSalt.byteLength !== 32) {
    throw new Error('Security Error: PRF evaluation salt must be strictly 32 bytes.');
  }

  const assertion = (await navigator.credentials.get({
    publicKey: {
      challenge: crypto.getRandomValues(new Uint8Array(32)),
      allowCredentials: [{
        id: credentialIdBytes,
        type: 'public-key',
        transports: ['internal', 'hybrid', 'usb']
      }],
      userVerification: 'required',
      extensions: {
        prf: {
          eval: {
            first: domainSalt
          }
        }
      }
    }
  })) as PublicKeyCredential | null;

  if (!assertion) {
    throw new Error('Credential assertion failed or was aborted by user.');
  }

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

  if (!prfResult) {
    throw new Error('Authenticator did not return a valid PRF extension evaluation.');
  }

  const prfBuffer = new Uint8Array(prfResult);
  try {
    // Import PRF output as raw IKM (Input Keying Material)
    const rawPrfKey = await crypto.subtle.importKey(
      'raw',
      prfBuffer,
      'HKDF',
      false,
      ['deriveKey']
    );

    // Derive a non-extractable 256-bit AES-GCM symmetric vault encryption key
    const vaultKey = await crypto.subtle.deriveKey(
      {
        name: 'HKDF',
        hash: 'SHA-256',
        salt: domainSalt,
        info: new TextEncoder().encode('production:zero-knowledge:vault-aes-gcm-256')
      },
      rawPrfKey,
      { name: 'AES-GCM', length: 256 },
      false,
      ['encrypt', 'decrypt']
    );

    return vaultKey;
  } finally {
    // Zeroize intermediate memory buffer
    prfBuffer.fill(0);
  }
}
```

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 PRF Client-Side Zero-Knowledge Cryptographic Key Derivation Guardrail

WebAuthn PRF Client-Side Zero-Knowledge Cryptographic Key Derivation Guardrail defines an industrial-grade behavioral standard for security engineering. Enforces strict client-side zero-knowledge architectural standards for deriving symmetric cryptographic keys via the WebAuthn Pseudo-Random Function (PRF) extension (HMAC-secret). Prevents leakage of raw PRF outputs, mandates constant salt isolation, enforces subkey derivation using HKDF with quantum-resistant key lengths (AES-256-GCM / XChaCha20-Poly1305), and ensures hardware secrets never transit to relying party backend servers. 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: Transmitting Raw PRF Outputs to Relying Parties or Directly Utilizing Unhashed Hardware Evaluation Results as Symmetric Vault 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 DriftTransmitting Raw PRF Outputs to Relying Parties or Directly Utilizing Unhashed Hardware Evaluation Results as Symmetric Vault 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 execute WebAuthn PRF key derivation strictly within client-side sandboxes (e.g., Web Workers or browser window runtime) and MUST NEVER serialize, log, or transmit raw PRF output buffers (`results.prf.first` / `results.prf.second`) across the network.

Engineers MUST ALWAYS execute WebAuthn PRF key derivation strictly within client-side sandboxes (e.g., Web Workers or browser window runtime) and MUST NEVER serialize, log, or transmit raw PRF output buffers (`results.prf.first` / `results.prf.second`) across the network.

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 pass the raw 32-byte PRF hardware evaluation output through HKDF (RFC 5869) using SHA-256 or SHA-512, with distinct domain-separated `info` labels (e.g., 'vault-encryption-key-v1', 'vault-mac-key-v1') before instantiating symmetric ciphers.

Engineers MUST ALWAYS pass the raw 32-byte PRF hardware evaluation output through HKDF (RFC 5869) using SHA-256 or SHA-512, with distinct domain-separated `info` labels (e.g., 'vault-encryption-key-v1', 'vault-mac-key-v1') before instantiating symmetric ciphers.

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 static zero-buffers or predictable global literals as the PRF input salt

Engineers MUST NEVER use static zero-buffers or predictable global literals as the PRF input salt; salts MUST be cryptographically bound to the user's credential ID or derived from an account-specific constant 32-byte authenticated salt stored on the client.

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 SHOULD verify `credential.getClientExtensionResults().prf.enabled` during registration before asserting PRF capability, and implement a graceful fallback or explicit rejection when the authenticator lacks HMAC-secret support.

Code SHOULD verify `credential.getClientExtensionResults().prf.enabled` during registration before asserting PRF capability, and implement a graceful fallback or explicit rejection when the authenticator lacks HMAC-secret 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

Engineers MUST explicitly zero-out (scrub) sensitive TypedArrays (`rawPrfBytes.fill(0)`) immediately after importing them into non-extractable `CryptoKey` handles using `SubtleCrypto.importKey`.

Engineers MUST explicitly zero-out (scrub) sensitive TypedArrays (`rawPrfBytes.fill(0)`) immediately after importing them into non-extractable `CryptoKey` handles using `SubtleCrypto.importKey`.

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 Client-Side Zero-Knowledge Cryptographic Key Derivation Guardrail critical for AI coding assistants?

Enforces strict client-side zero-knowledge architectural standards for deriving symmetric cryptographic keys via the WebAuthn Pseudo-Random Function (PRF) extension (HMAC-secret). Prevents leakage of raw PRF outputs, mandates constant salt isolation, enforces subkey derivation using HKDF with quantum-resistant key lengths (AES-256-GCM / XChaCha20-Poly1305), and ensures hardware secrets never transit to relying party backend servers. 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 (Transmitting Raw PRF Outputs to Relying Parties or Directly Utilizing Unhashed Hardware Evaluation Results as Symmetric Vault 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