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

WebAuthn PRF Deterministic Zero-Knowledge Symmetric Key Derivation Guardrails

Enforces strict client-side isolation and standard-compliant key derivation when using the WebAuthn PRF (Pseudo-Random Function) extension. Ensures zero-knowledge client-side encryption by guaranteeing raw authenticator PRF outputs are never transmitted to relying parties and are rigorously expanded via HKDF into non-extractable Web Crypto keys.

Prohibited Anti-Pattern: Transmitting Raw PRF Outputs to Relying Parties or Direct Symmetric Cipher Initialization Without HKDF

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn PRF Deterministic Zero-Knowledge Symmetric Key Derivation Guardrails - Enforces strict client-side isolation and standard-compliant key derivation when using the WebAuthn PRF (Pseudo-Random Function) extension. Ensures zero-knowledge client-side encryption by guaranteeing raw authenticator PRF outputs are never transmitted to relying parties and are rigorously expanded via HKDF into non-extractable Web Crypto keys.
globs: src/**/{auth,crypto,security,vault,keys}/**/*.{ts,tsx,js,jsx}, packages/**/{crypto,auth}/**/*.{ts,tsx,js,jsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-prf-client-key-derivation-standard-webauthn-prf-ext-301"
---

# WebAuthn PRF Deterministic Zero-Knowledge Symmetric Key Derivation Guardrails

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Transmitting Raw PRF Outputs to Relying Parties or Direct Symmetric Cipher Initialization Without HKDF

## System Constraints
You are a Principal Security Architect enforcing the WebAuthn PRF Extension Client-Side Symmetric Key Derivation Standard. You must mandate zero-knowledge guarantees: PRF outputs must never cross the network boundary to the Relying Party, raw PRF bytes must never be used directly as cipher keys, HKDF-SHA256 key derivation must always be applied with domain-specific info strings, and derived keys must remain non-extractable in Web Crypto SubtleCrypto memory.

## Strict Guidelines
- Engineers MUST ALWAYS sanitize authentication assertion responses prior to network transmission, explicitly stripping `getClientExtensionResults().prf` from payloads sent to the Relying Party.
- Engineers MUST ALWAYS ingest the raw PRF output (`prf.results.first`) as initial keying material (IKM) into HKDF-SHA-256 (`SubtleCrypto.deriveKey`) rather than using PRF output directly as a symmetric cipher key.
- Engineers MUST ALWAYS set `extractable: false` when deriving symmetric cipher keys (e.g., AES-GCM-256) via `SubtleCrypto.deriveKey` to prevent memory exfiltration via rogue scripts.
- Engineers MUST ALWAYS supply a cryptographically secure, persistent, non-zero salt (typically 32 bytes) configured specifically for the derivation domain to `extensions.prf.eval`.
- Engineers MUST NOT fallback to unencrypted local storage (localStorage, unencrypted IndexedDB) or hardcoded fallbacks if PRF evaluation fails or the authenticator lacks PRF support.
- Services MUST verify WebAuthn assertion signatures independently on the Relying Party server without ever requiring or expecting PRF symmetric key material or derived E2EE keys in the request body.

## Bad vs Good Implementations
### Client Assertion & PRF Derivation Flow

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The bad example sends the raw WebAuthn response directly to the backend server, exposing the PRF extension results over the network and destroying zero-knowledge guarantees. It also bypasses HKDF expansion and imports the raw PRF output directly as an extractable AES-GCM key, exposing it to memory extraction by third-party scripts.
```typescript
import { startAuthentication } from '@simplewebauthn/browser';

export async function authenticateAndUnlockVault(authOptions: any, salt: Uint8Array) {
  // Anti-pattern: Passing PRF results directly to server or using raw output as cipher key
  const assertion = await startAuthentication({
    ...authOptions,
    extensions: {
      prf: { eval: { first: salt } }
    }
  });

  // CRITICAL SECURITY FLAW 1: Exfiltrating PRF output to Relying Party server
  await fetch('/api/auth/verify', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(assertion) // Contains assertion.clientExtensionResults.prf!
  });

  // CRITICAL SECURITY FLAW 2: Direct raw PRF output used directly as an extractable AES key
  const rawPrf = (assertion as any).clientExtensionResults?.prf?.results?.first;
  const key = await window.crypto.subtle.importKey(
    'raw',
    rawPrf,
    { name: 'AES-GCM', length: 256 },
    true, // Extractable allows malicious DOM scripts to steal the root key
    ['encrypt', 'decrypt']
  );

  return key;
}
```

#### Production Standard (Correct)
> **Standard**: The good implementation explicitly purges PRF output before transmitting assertion data to the server, preserving zero-knowledge properties. It uses HKDF-SHA256 to expand the raw PRF output with domain separation and derives a non-extractable AES-GCM key inside SubtleCrypto, mitigating cross-site memory scraping.
```typescript
import { startAuthentication } from '@simplewebauthn/browser';

const HKDF_INFO_VAULT_ENCRYPTION = new TextEncoder().encode('org.standard.vault.encryption.v1');

export async function authenticateAndUnlockVault(
  authOptions: any,
  prfSalt: Uint8Array
): Promise<CryptoKey> {
  const assertion = await startAuthentication({
    ...authOptions,
    extensions: {
      prf: { eval: { first: prfSalt } }
    }
  });

  const prfExtension = assertion.clientExtensionResults?.prf;
  if (!prfExtension?.results?.first) {
    throw new Error('Authenticator does not support PRF or failed evaluation');
  }

  const rawPrfMaterial = new Uint8Array(prfExtension.results.first);

  // 1. Sanitize payload sent to server: strip extension outputs to preserve zero-knowledge
  const serverPayload = {
    ...assertion,
    clientExtensionResults: {
      ...assertion.clientExtensionResults,
      prf: undefined
    }
  };

  const verifyRes = await fetch('/api/auth/verify', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(serverPayload)
  });

  if (!verifyRes.ok) {
    throw new Error('Server authentication verification failed');
  }

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

  // 3. Derive deterministic, non-extractable AES-GCM root symmetric key
  return await window.crypto.subtle.deriveKey(
    {
      name: 'HKDF',
      hash: 'SHA-256',
      salt: prfSalt,
      info: HKDF_INFO_VAULT_ENCRYPTION
    },
    ikmKey,
    { name: 'AES-GCM', length: 256 },
    false, // Enforce non-extractable key memory resident inside WebCrypto
    ['encrypt', 'decrypt']
  );
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: WebAuthn PRF Deterministic Zero-Knowledge Symmetric Key Derivation Guardrails

WebAuthn PRF Deterministic Zero-Knowledge Symmetric Key Derivation Guardrails defines an industrial-grade behavioral standard for security engineering. Enforces strict client-side isolation and standard-compliant key derivation when using the WebAuthn PRF (Pseudo-Random Function) extension. Ensures zero-knowledge client-side encryption by guaranteeing raw authenticator PRF outputs are never transmitted to relying parties and are rigorously expanded via HKDF into non-extractable Web Crypto keys. 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 Direct Symmetric Cipher Initialization Without HKDF 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 Direct Symmetric Cipher Initialization Without HKDFCritical
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 sanitize authentication assertion responses prior to network transmission, explicitly stripping `getClientExtensionResults().prf` from payloads sent to the Relying Party.

Engineers MUST ALWAYS sanitize authentication assertion responses prior to network transmission, explicitly stripping `getClientExtensionResults().prf` from payloads sent to the Relying Party.

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 ingest the raw PRF output (`prf.results.first`) as initial keying material (IKM) into HKDF-SHA-256 (`SubtleCrypto.deriveKey`) rather than using PRF output directly as a symmetric cipher key.

Engineers MUST ALWAYS ingest the raw PRF output (`prf.results.first`) as initial keying material (IKM) into HKDF-SHA-256 (`SubtleCrypto.deriveKey`) rather than using PRF output directly as a symmetric cipher 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.
3

Engineers MUST ALWAYS set `extractable

Engineers MUST ALWAYS set `extractable: false` when deriving symmetric cipher keys (e.g., AES-GCM-256) via `SubtleCrypto.deriveKey` to prevent memory exfiltration via rogue scripts.

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 ALWAYS supply a cryptographically secure, persistent, non-zero salt (typically 32 bytes) configured specifically for the derivation domain to `extensions.prf.eval`.

Engineers MUST ALWAYS supply a cryptographically secure, persistent, non-zero salt (typically 32 bytes) configured specifically for the derivation domain to `extensions.prf.eval`.

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 NOT fallback to unencrypted local storage (localStorage, unencrypted IndexedDB) or hardcoded fallbacks if PRF evaluation fails or the authenticator lacks PRF support.

Engineers MUST NOT fallback to unencrypted local storage (localStorage, unencrypted IndexedDB) or hardcoded fallbacks if PRF evaluation fails or the authenticator lacks PRF 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.
6

Services MUST verify WebAuthn assertion signatures independently on the Relying Party server without ever requiring or expecting PRF symmetric key material or derived E2EE keys in the request body.

Services MUST verify WebAuthn assertion signatures independently on the Relying Party server without ever requiring or expecting PRF symmetric key material or derived E2EE keys in the request body.

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 Deterministic Zero-Knowledge Symmetric Key Derivation Guardrails critical for AI coding assistants?

Enforces strict client-side isolation and standard-compliant key derivation when using the WebAuthn PRF (Pseudo-Random Function) extension. Ensures zero-knowledge client-side encryption by guaranteeing raw authenticator PRF outputs are never transmitted to relying parties and are rigorously expanded via HKDF into non-extractable Web Crypto keys. 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 Direct Symmetric Cipher Initialization Without HKDF) 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