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

Mandatory Client-Side WebAuthn PRF Symmetric Key Derivation & Zero-Knowledge Transport

Enforces strict client-side symmetric key derivation using the WebAuthn PRF (Pseudo-Random Function) extension for end-to-end encrypted vaults. Authenticator PRF outputs and intermediate key materials must never be transmitted to Relying Party servers, and must always be expanded via client-side HKDF with distinct domain separation parameters before encrypting application state.

Prohibited Anti-Pattern: Transmitting WebAuthn PRF Extension Outputs to Relying Party Backends or Deriving Vault Keys Server-Side

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Mandatory Client-Side WebAuthn PRF Symmetric Key Derivation & Zero-Knowledge Transport - Enforces strict client-side symmetric key derivation using the WebAuthn PRF (Pseudo-Random Function) extension for end-to-end encrypted vaults. Authenticator PRF outputs and intermediate key materials must never be transmitted to Relying Party servers, and must always be expanded via client-side HKDF with distinct domain separation parameters before encrypting application state.
globs: src/crypto/**/*.{ts,tsx}, src/auth/**/*.{ts,tsx}, src/vault/**/*.{ts,tsx}, src/services/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-prf-client-vault-key-derivation"
---

# Mandatory Client-Side WebAuthn PRF Symmetric Key Derivation & Zero-Knowledge Transport

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Transmitting WebAuthn PRF Extension Outputs to Relying Party Backends or Deriving Vault Keys Server-Side

## System Constraints
You are a Principal Security Architect enforcing deterministic client-side symmetric key derivation using the WebAuthn PRF extension. You must guarantee that authenticator-derived secrets never leak to the backend, that PRF outputs are always fortified via client-side HKDF with domain-specific salts, and that assertion payloads sent over the wire are completely stripped of clientExtensionResults containing PRF bytes.

## Strict Guidelines
- Engineers MUST ALWAYS isolate navigator.credentials.get() and navigator.credentials.create() PRF outputs strictly in client-side memory using Web Crypto API (SubtleCrypto).
- Engineers MUST NOT transmit clientExtensionResults.prf or raw PRF evaluation bytes (first/second) to Relying Party (RP) backends or remote logging services.
- Engineers MUST ALWAYS pass the raw 32-byte PRF output into HKDF (HMAC-based Extract-and-Expand Key Derivation Function) with SHA-256, an application-specific salt, and an explicit domain separation info parameter (e.g., 'e2ee-vault-v1:encryption') before instantiating symmetric encryption primitives.
- Engineers MUST NEVER use the raw PRF output directly as an AES-GCM or ChaCha20-Poly1305 key without prior key expansion and explicit info tagging.
- Code MUST sanitize the PublicKeyCredential assertion object before serialization to remote endpoints, stripping any extension results that expose credential-derived cryptographic entropy.
- Services MUST verify WebAuthn authentication assertions independently of vault decryption, ensuring the backend operates under a zero-knowledge trust model regarding vault contents.
- Components NEVER store derived master vault keys in localStorage, sessionStorage, or unencrypted IndexedDB; derived CryptoKey handles must be transiently held in memory or wrapped with Web Crypto non-extractable flags.

## Bad vs Good Implementations
### Client-Side PRF Key Derivation and Wire Payload Sanitization

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The anti-pattern transmits the raw PRF entropy to the backend server via HTTP, completely destroying the zero-knowledge model and allowing the Relying Party to decrypt the user's private vault. Furthermore, it uses a hardcoded, non-unique salt and fails to expand the PRF output through HKDF.
```typescript
import axios from 'axios';

export async function unlockVaultAndAuthenticate(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(1) // Insecure static evaluation salt
          }
        }
      }
    }
  }) as PublicKeyCredential;

  // CRITICAL SECURITY FLAW: Sending raw credential including PRF extension results to backend
  const extensionResults = credential.getClientExtensionResults();
  await axios.post('/api/vault/login', {
    credential,
    prfRaw: extensionResults.prf?.results?.first // LEAKING PRF MASTER ENTROPY TO SERVER
  });

  // DIRECT USE OF RAW PRF OUTPUT WITHOUT HKDF
  return extensionResults.prf?.results?.first;
}
```

#### Production Standard (Correct)
> **Standard**: The production implementation evaluates the PRF extension locally, derives a non-extractable AES-GCM-256 key via Web Crypto HKDF using strict domain separation info, and sanitizes the PublicKeyCredential payload before wire transport so that raw PRF outputs never leave the browser runtime.
```typescript
export interface VaultKeyDerivationOptions {
  credentialId: Uint8Array;
  challenge: Uint8Array;
  vaultSalt: Uint8Array;
  domainInfo: string;
}

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

  if (!credential) {
    throw new Error('Authentication rejected by user');
  }

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

  // Import raw PRF output as HKDF key material strictly in client memory
  const prfKeyMaterial = await crypto.subtle.importKey(
    'raw',
    prfOutput,
    'HKDF',
    false,
    ['deriveKey']
  );

  // Derive non-extractable AES-GCM-256 key with domain separation
  const encoder = new TextEncoder();
  const vaultKey = await crypto.subtle.deriveKey(
    {
      name: 'HKDF',
      hash: 'SHA-256',
      salt: options.vaultSalt,
      info: encoder.encode(options.domainInfo)
    },
    prfKeyMaterial,
    { name: 'AES-GCM', length: 256 },
    false, // Non-extractable to prevent heap export
    ['encrypt', 'decrypt']
  );

  // Sanitize assertion for Relying Party: EXCLUDE PRF outputs from wire transmission
  const rawResponse = credential.response as AuthenticatorAssertionResponse;
  const assertionForServer = {
    id: credential.id,
    rawId: Array.from(new Uint8Array(credential.rawId)),
    type: credential.type,
    response: {
      authenticatorData: Array.from(new Uint8Array(rawResponse.authenticatorData)),
      clientDataJSON: Array.from(new Uint8Array(rawResponse.clientDataJSON)),
      signature: Array.from(new Uint8Array(rawResponse.signature)),
      userHandle: rawResponse.userHandle ? Array.from(new Uint8Array(rawResponse.userHandle)) : null
    }
  };

  return { vaultKey, assertionForServer };
}
```

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: Mandatory Client-Side WebAuthn PRF Symmetric Key Derivation & Zero-Knowledge Transport

Mandatory Client-Side WebAuthn PRF Symmetric Key Derivation & Zero-Knowledge Transport defines an industrial-grade behavioral standard for security engineering. Enforces strict client-side symmetric key derivation using the WebAuthn PRF (Pseudo-Random Function) extension for end-to-end encrypted vaults. Authenticator PRF outputs and intermediate key materials must never be transmitted to Relying Party servers, and must always be expanded via client-side HKDF with distinct domain separation parameters before encrypting application state. 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 WebAuthn PRF Extension Outputs to Relying Party Backends or Deriving Vault Keys Server-Side 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 WebAuthn PRF Extension Outputs to Relying Party Backends or Deriving Vault Keys Server-SideCritical
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 navigator.credentials.get() and navigator.credentials.create() PRF outputs strictly in client-side memory using Web Crypto API (SubtleCrypto).

Engineers MUST ALWAYS isolate navigator.credentials.get() and navigator.credentials.create() PRF outputs strictly in client-side memory using Web Crypto API (SubtleCrypto).

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 clientExtensionResults.prf or raw PRF evaluation bytes (first/second) to Relying Party (RP) backends or remote logging services.

Engineers MUST NOT transmit clientExtensionResults.prf or raw PRF evaluation bytes (first/second) to Relying Party (RP) backends or remote logging services.

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 ALWAYS pass the raw 32-byte PRF output into HKDF (HMAC-based Extract-and-Expand Key Derivation Function) with SHA-256, an application-specific salt, and an explicit domain separation info parameter (e.g., 'e2ee-vault-v1

Engineers MUST ALWAYS pass the raw 32-byte PRF output into HKDF (HMAC-based Extract-and-Expand Key Derivation Function) with SHA-256, an application-specific salt, and an explicit domain separation info parameter (e.g., 'e2ee-vault-v1:encryption') before instantiating symmetric encryption primitives.

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 NEVER use the raw PRF output directly as an AES-GCM or ChaCha20-Poly1305 key without prior key expansion and explicit info tagging.

Engineers MUST NEVER use the raw PRF output directly as an AES-GCM or ChaCha20-Poly1305 key without prior key expansion and explicit info tagging.

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

Code MUST sanitize the PublicKeyCredential assertion object before serialization to remote endpoints, stripping any extension results that expose credential-derived cryptographic entropy.

Code MUST sanitize the PublicKeyCredential assertion object before serialization to remote endpoints, stripping any extension results that expose credential-derived cryptographic entropy.

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

Services MUST verify WebAuthn authentication assertions independently of vault decryption, ensuring the backend operates under a zero-knowledge trust model regarding vault contents.

Services MUST verify WebAuthn authentication assertions independently of vault decryption, ensuring the backend operates under a zero-knowledge trust model regarding vault contents.

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.
7

Components NEVER store derived master vault keys in localStorage, sessionStorage, or unencrypted IndexedDB

Components NEVER store derived master vault keys in localStorage, sessionStorage, or unencrypted IndexedDB; derived CryptoKey handles must be transiently held in memory or wrapped with Web Crypto non-extractable flags.

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 Mandatory Client-Side WebAuthn PRF Symmetric Key Derivation & Zero-Knowledge Transport critical for AI coding assistants?

Enforces strict client-side symmetric key derivation using the WebAuthn PRF (Pseudo-Random Function) extension for end-to-end encrypted vaults. Authenticator PRF outputs and intermediate key materials must never be transmitted to Relying Party servers, and must always be expanded via client-side HKDF with distinct domain separation parameters before encrypting application state. 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 WebAuthn PRF Extension Outputs to Relying Party Backends or Deriving Vault Keys Server-Side) 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

Mandatory