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

WebAuthn Level 3 PRF Extension Hardware Key-Wrapping Standard

Enforces hardware-bound end-to-end client-side encryption key derivation via the WebAuthn Level 3 Pseudo-Random Function (PRF) extension. Mandates that raw PRF outputs and intermediate master keys remain strictly ephemeral within client hardware and memory, prohibiting transmission of cryptographic seeds to Relying Parties or identity providers.

Prohibited Anti-Pattern: Transmitting raw WebAuthn PRF outputs to backend servers or relying on software-only password derivation for client-side encryption.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn Level 3 PRF Extension Hardware Key-Wrapping Standard - Enforces hardware-bound end-to-end client-side encryption key derivation via the WebAuthn Level 3 Pseudo-Random Function (PRF) extension. Mandates that raw PRF outputs and intermediate master keys remain strictly ephemeral within client hardware and memory, prohibiting transmission of cryptographic seeds to Relying Parties or identity providers.
globs: src/**/*.{ts,tsx,js,mjs}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-l3-prf-hardware-key-wrapping-standard"
---

# WebAuthn Level 3 PRF Extension Hardware Key-Wrapping Standard

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Transmitting raw WebAuthn PRF outputs to backend servers or relying on software-only password derivation for client-side encryption.

## System Constraints
You are a Principal Security Architect enforcing zero-knowledge client-side encryption standards using WebAuthn Level 3 PRF (Pseudo-Random Function) extensions. Your objective is to ensure that symmetric root keys derived from hardware authenticators (CTAP 2.1 / WebAuthn L3) remain strictly client-side, using WebCrypto HKDF for domain separation, while preventing credential leakage, persistent unencrypted key exposure, and Relying Party telemetry inspection.

## Strict Guidelines
- Engineers MUST ALWAYS inspect `authenticatorAttachment` and verify `extensions.prf.supported` or handle fallback when registering credentials requiring PRF encryption.
- Engineers MUST ALWAYS isolate raw PRF outputs (`results.first` / `results.second`) to client-side memory and immediately derive cryptographic subkeys using `crypto.subtle.deriveKey` or `deriveBits` with HKDF-SHA256 and explicit domain separation context info.
- Engineers MUST NOT transmit raw PRF extension outputs, evaluation seeds, or derived master encryption keys in registration responses, authentication assertions, analytics, or API request bodies to the Relying Party (RP) or any IdP.
- Components NEVER persist derived PRF keys or raw outputs to `localStorage`, `sessionStorage`, or unencrypted `IndexedDB`; keys must remain in non-extractable `CryptoKey` handles within memory scoped to the active session lifecycle.
- Services MUST generate cryptographically secure, per-user or per-document 32-byte salts using `crypto.getRandomValues()` to supply to `extensions.prf.eval.first` during authentication assertions.

## Bad vs Good Implementations
### WebAuthn PRF Assertion and Hardware Key Derivation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The implementation sends the raw authenticator assertion—including the client extension results containing the PRF output buffer—directly to the server endpoint. This destroys the zero-knowledge guarantee, enabling the Relying Party (IdP) to reconstruct the client-side encryption key.
```typescript
import { startAuthentication } from '@simplewebauthn/browser';

export async function unlockVault(authOptions: any, userSalt: Uint8Array) {
  // Flaw 1: Passing unhashed server seeds directly into assertion
  // Flaw 2: Leaking the raw PRF output back to the server inside the assertion payload
  const assertion = await startAuthentication({
    ...authOptions,
    extensions: {
      prf: {
        eval: {
          first: userSalt,
        },
      },
    },
  });

  // CRITICAL SECURITY FLAW: Sending full assertion including PRF output to the RP
  const response = await fetch('/api/vault/verify-and-unlock', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(assertion),
  });

  return response.json();
}
```

#### Production Standard (Correct)
> **Standard**: Extracts the hardware PRF output solely within the client environment, imports it into WebCrypto as a non-extractable HKDF master secret, derives a scoped AES-GCM-256 key with domain separation context, and purges the PRF output from the assertion response payload before communicating with the Relying Party.
```typescript
import { startAuthentication } from '@simplewebauthn/browser';

const HKDF_INFO_VAULT_ENCRYPTION = new TextEncoder().encode('application/vnd.company.vault.enc.v1');

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

  // Extract PRF output directly on client
  const prfResults = assertion.clientExtensionResults?.prf?.results;
  if (!prfResults?.first) {
    throw new Error('Authenticator did not return a valid PRF output.');
  }

  const rawPrfOutput = new Uint8Array(prfResults.first);

  // Import raw PRF output as non-extractable key material for HKDF derivation
  const rawHkdfKey = await crypto.subtle.importKey(
    'raw',
    rawPrfOutput,
    'HKDF',
    false,
    ['deriveKey']
  );

  // Derive AES-GCM-256 vault encryption key with strict domain separation
  const vaultKey = await crypto.subtle.deriveKey(
    {
      name: 'HKDF',
      hash: 'SHA-256',
      salt: userSalt,
      info: HKDF_INFO_VAULT_ENCRYPTION,
    },
    rawHkdfKey,
    { name: 'AES-GCM', length: 256 },
    false,
    ['encrypt', 'decrypt']
  );

  // Sanitize assertion payload before transmitting to RP: strip sensitive PRF output
  const sanitizedAssertion = structuredClone(assertion);
  if (sanitizedAssertion.clientExtensionResults?.prf?.results) {
    delete sanitizedAssertion.clientExtensionResults.prf.results;
  }

  const verification = await fetch('/api/vault/verify-assertion', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(sanitizedAssertion),
  });

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

  return vaultKey;
}
```

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 Level 3 PRF Extension Hardware Key-Wrapping Standard

WebAuthn Level 3 PRF Extension Hardware Key-Wrapping Standard defines an industrial-grade behavioral standard for security engineering. Enforces hardware-bound end-to-end client-side encryption key derivation via the WebAuthn Level 3 Pseudo-Random Function (PRF) extension. Mandates that raw PRF outputs and intermediate master keys remain strictly ephemeral within client hardware and memory, prohibiting transmission of cryptographic seeds to Relying Parties or identity providers. 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 WebAuthn PRF outputs to backend servers or relying on software-only password derivation for client-side encryption. 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 WebAuthn PRF outputs to backend servers or relying on software-only password derivation for client-side encryption.Critical
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 inspect `authenticatorAttachment` and verify `extensions.prf.supported` or handle fallback when registering credentials requiring PRF encryption.

Engineers MUST ALWAYS inspect `authenticatorAttachment` and verify `extensions.prf.supported` or handle fallback when registering credentials requiring PRF encryption.

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 isolate raw PRF outputs (`results.first` / `results.second`) to client-side memory and immediately derive cryptographic subkeys using `crypto.subtle.deriveKey` or `deriveBits` with HKDF-SHA256 and explicit domain separation context info.

Engineers MUST ALWAYS isolate raw PRF outputs (`results.first` / `results.second`) to client-side memory and immediately derive cryptographic subkeys using `crypto.subtle.deriveKey` or `deriveBits` with HKDF-SHA256 and explicit domain separation context info.

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 transmit raw PRF extension outputs, evaluation seeds, or derived master encryption keys in registration responses, authentication assertions, analytics, or API request bodies to the Relying Party (RP) or any IdP.

Engineers MUST NOT transmit raw PRF extension outputs, evaluation seeds, or derived master encryption keys in registration responses, authentication assertions, analytics, or API request bodies to the Relying Party (RP) or any IdP.

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

Components NEVER persist derived PRF keys or raw outputs to `localStorage`, `sessionStorage`, or unencrypted `IndexedDB`

Components NEVER persist derived PRF keys or raw outputs to `localStorage`, `sessionStorage`, or unencrypted `IndexedDB`; keys must remain in non-extractable `CryptoKey` handles within memory scoped to the active session lifecycle.

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 generate cryptographically secure, per-user or per-document 32-byte salts using `crypto.getRandomValues()` to supply to `extensions.prf.eval.first` during authentication assertions.

Services MUST generate cryptographically secure, per-user or per-document 32-byte salts using `crypto.getRandomValues()` to supply to `extensions.prf.eval.first` during authentication assertions.

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 Level 3 PRF Extension Hardware Key-Wrapping Standard critical for AI coding assistants?

Enforces hardware-bound end-to-end client-side encryption key derivation via the WebAuthn Level 3 Pseudo-Random Function (PRF) extension. Mandates that raw PRF outputs and intermediate master keys remain strictly ephemeral within client hardware and memory, prohibiting transmission of cryptographic seeds to Relying Parties or identity providers. 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 WebAuthn PRF outputs to backend servers or relying on software-only password derivation for client-side encryption.) 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