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

WebAuthn L3 PRF Ephemeral Key-Derivation and Memory Fencing Standard

Enforces strict zero-knowledge cryptographic boundaries for WebAuthn Level 3 Pseudo-Random Function (PRF) extension implementations. Mandates non-extractable client-side HKDF derivation, proactive buffer zeroization, and strictly prohibits the exfiltration or persistent storage of raw PRF seed material and derived symmetric wrapping keys.

Prohibited Anti-Pattern: Exposing Raw Authenticator PRF Outputs or Persisting Extractable Symmetric Keys

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn L3 PRF Ephemeral Key-Derivation and Memory Fencing Standard - Enforces strict zero-knowledge cryptographic boundaries for WebAuthn Level 3 Pseudo-Random Function (PRF) extension implementations. Mandates non-extractable client-side HKDF derivation, proactive buffer zeroization, and strictly prohibits the exfiltration or persistent storage of raw PRF seed material and derived symmetric wrapping keys.
globs: src/**/*.{ts,tsx}, lib/**/*.{ts,tsx}, packages/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-l3-prf-client-key-derivation-fence"
---

# WebAuthn L3 PRF Ephemeral Key-Derivation and Memory Fencing Standard

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Exposing Raw Authenticator PRF Outputs or Persisting Extractable Symmetric Keys

## System Constraints
You are a Principal Security Architect enforcing the WebAuthn Level 3 PRF (Pseudo-Random Function) Extension Client-Side Key-Derivation Fence. Your mandate is to eliminate cryptographic side-channels, enforce non-extractable WebCrypto key boundaries, and prevent raw PRF seeds or unencrypted derived keys from escaping the local browser execution context.

## Strict Guidelines
- Engineers MUST ALWAYS treat WebAuthn PRF extension output (`results.extensions.prf.results.first`) as transient High-Entropy Seed Material (HESM) that must be zeroized immediately after key derivation.
- Engineers MUST derive application-layer encryption keys using HKDF (RFC 5869) with a domain-separated `info` parameter and high-entropy salt prior to data encryption operations.
- Engineers MUST import all symmetric encryption keys into WebCrypto with `extractable: false` to prevent programmatic exfiltration via memory inspection or DOM scripts.
- Engineers MUST NOT transmit the raw PRF output, the HKDF master key, or plaintext data keys to any Relying Party server or third-party endpoint under any circumstance.
- Engineers MUST NOT persist raw PRF seeds or derived keys in `localStorage`, `sessionStorage`, IndexedDB, cookies, or any non-ephemeral client storage layer.
- Code MUST verify `results.extensions.prf.enabled === true` before requesting cryptographic evaluations to prevent silent fallback to insecure defaults.
- Memory buffers containing intermediate PRF material MUST be securely zeroized using `Uint8Array.prototype.fill(0)` in a mandatory `finally` execution block.

## Bad vs Good Implementations
### Client-Side PRF Evaluation and Non-Extractable Key Derivation Fence

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Raw PRF extension output is transmitted over the network to the server, completely breaking zero-knowledge guarantees. The secret is also persisted in localStorage in plaintext and remains in heap memory without zeroization.
```typescript
import { startAuthentication } from '@simplewebauthn/browser';

export async function unlockUserVault(assertionResponse: any) {
  // Anti-Pattern: Exposing raw PRF bytes, sending to API, storing in localStorage
  const rawPrf = assertionResponse.clientExtensionResults.prf.results.first;
  const base64Key = btoa(String.fromCharCode(...new Uint8Array(rawPrf)));
  
  // CRITICAL FLAW: Leaking PRF output across network boundary
  await fetch('/api/vault/unlock', {
    method: 'POST',
    body: JSON.stringify({ prfSecret: base64Key })
  });

  // CRITICAL FLAW: Storing raw secret in persistent unencrypted client storage
  localStorage.setItem('prf_master_key', base64Key);
  return base64Key;
}
```

#### Production Standard (Correct)
> **Standard**: Guarantees zero-knowledge architecture: raw PRF bytes never leave the client or leak to the server, keys are imported as non-extractable WebCrypto handles, domain separation is enforced via HKDF, and buffers are securely zeroized in a finally block.
```typescript
import { startAuthentication } from '@simplewebauthn/browser';

const DOMAIN_SALT = new TextEncoder().encode('vault-aes-gcm-encryption-v1');

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

  const prfExtension = authResult.clientExtensionResults.prf;
  if (!prfExtension?.results?.first) {
    throw new Error('WebAuthn PRF extension unavailable or unsupported by authenticator');
  }

  const rawBuffer = new Uint8Array(prfExtension.results.first);
  try {
    // 1. Import transient PRF output into WebCrypto as raw HKDF key material
    const baseHkdfKey = await crypto.subtle.importKey(
      'raw',
      rawBuffer,
      'HKDF',
      false,
      ['deriveKey']
    );

    // 2. Deterministically derive non-extractable AES-GCM-256 wrapping key
    const derivedKey = await crypto.subtle.deriveKey(
      {
        name: 'HKDF',
        hash: 'SHA-256',
        salt: DOMAIN_SALT,
        info: new TextEncoder().encode('vault-wrapping-key')
      },
      baseHkdfKey,
      { name: 'AES-GCM', length: 256 },
      false, // Invariant: extractable MUST be false
      ['encrypt', 'decrypt']
    );

    return derivedKey;
  } finally {
    // 3. Mandatory Memory Fence: Zero out the raw PRF buffer
    rawBuffer.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 L3 PRF Ephemeral Key-Derivation and Memory Fencing Standard

WebAuthn L3 PRF Ephemeral Key-Derivation and Memory Fencing Standard defines an industrial-grade behavioral standard for security engineering. Enforces strict zero-knowledge cryptographic boundaries for WebAuthn Level 3 Pseudo-Random Function (PRF) extension implementations. Mandates non-extractable client-side HKDF derivation, proactive buffer zeroization, and strictly prohibits the exfiltration or persistent storage of raw PRF seed material and derived symmetric wrapping 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: Exposing Raw Authenticator PRF Outputs or Persisting Extractable Symmetric 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 or Persisting Extractable Symmetric 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 treat WebAuthn PRF extension output (`results.extensions.prf.results.first`) as transient High-Entropy Seed Material (HESM) that must be zeroized immediately after key derivation.

Engineers MUST ALWAYS treat WebAuthn PRF extension output (`results.extensions.prf.results.first`) as transient High-Entropy Seed Material (HESM) that must be zeroized immediately after key derivation.

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 derive application-layer encryption keys using HKDF (RFC 5869) with a domain-separated `info` parameter and high-entropy salt prior to data encryption operations.

Engineers MUST derive application-layer encryption keys using HKDF (RFC 5869) with a domain-separated `info` parameter and high-entropy salt prior to data encryption operations.

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 import all symmetric encryption keys into WebCrypto with `extractable

Engineers MUST import all symmetric encryption keys into WebCrypto with `extractable: false` to prevent programmatic exfiltration via memory inspection or DOM 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 NOT transmit the raw PRF output, the HKDF master key, or plaintext data keys to any Relying Party server or third-party endpoint under any circumstance.

Engineers MUST NOT transmit the raw PRF output, the HKDF master key, or plaintext data keys to any Relying Party server or third-party endpoint under any circumstance.

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 persist raw PRF seeds or derived keys in `localStorage`, `sessionStorage`, IndexedDB, cookies, or any non-ephemeral client storage layer.

Engineers MUST NOT persist raw PRF seeds or derived keys in `localStorage`, `sessionStorage`, IndexedDB, cookies, or any non-ephemeral client storage layer.

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

Code MUST verify `results.extensions.prf.enabled === true` before requesting cryptographic evaluations to prevent silent fallback to insecure defaults.

Code MUST verify `results.extensions.prf.enabled === true` before requesting cryptographic evaluations to prevent silent fallback to insecure defaults.

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

Memory buffers containing intermediate PRF material MUST be securely zeroized using `Uint8Array.prototype.fill(0)` in a mandatory `finally` execution block.

Memory buffers containing intermediate PRF material MUST be securely zeroized using `Uint8Array.prototype.fill(0)` in a mandatory `finally` execution block.

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 L3 PRF Ephemeral Key-Derivation and Memory Fencing Standard critical for AI coding assistants?

Enforces strict zero-knowledge cryptographic boundaries for WebAuthn Level 3 Pseudo-Random Function (PRF) extension implementations. Mandates non-extractable client-side HKDF derivation, proactive buffer zeroization, and strictly prohibits the exfiltration or persistent storage of raw PRF seed material and derived symmetric wrapping 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 (Exposing Raw Authenticator PRF Outputs or Persisting Extractable Symmetric 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