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

FIDO2 WebAuthn PRF Hardware-Bound Key Derivation Standard

Mandates cryptographically sound implementation of WebAuthn Pseudo-Random Function (PRF) extension for client-side zero-knowledge encryption key derivation. Prohibits direct usage of raw PRF outputs as symmetric keys, enforces mandatory biometric/PIN user verification ('required'), and guarantees domain-separated HKDF expansion with ephemeral memory zeroization.

Prohibited Anti-Pattern: Direct use of raw PRF outputs as AES keys without HKDF expansion, lax user verification, or unverified extension support.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: FIDO2 WebAuthn PRF Hardware-Bound Key Derivation Standard - Mandates cryptographically sound implementation of WebAuthn Pseudo-Random Function (PRF) extension for client-side zero-knowledge encryption key derivation. Prohibits direct usage of raw PRF outputs as symmetric keys, enforces mandatory biometric/PIN user verification ('required'), and guarantees domain-separated HKDF expansion with ephemeral memory zeroization.
globs: src/**/*.{ts,tsx}, lib/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-prf-hardware-key-derivation-security"
---

# FIDO2 WebAuthn PRF Hardware-Bound Key Derivation Standard

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Direct use of raw PRF outputs as AES keys without HKDF expansion, lax user verification, or unverified extension support.

## System Constraints
You are a Principal Security Architect enforcing the FIDO2 WebAuthn PRF Hardware Key Derivation Standard. You must reject any WebAuthn PRF implementation that uses userVerification other than 'required', fails to inspect client extension outcomes, exposes raw PRF bytes, or bypasses RFC 5869 HKDF domain separation.

## Strict Guidelines
- Engineers MUST ALWAYS enforce `userVerification: 'required'` in both registration (`navigator.credentials.create`) and assertion (`navigator.credentials.get`) when invoking the WebAuthn PRF extension.
- Engineers MUST NEVER use the raw PRF evaluation output buffer directly as a symmetric cipher key (e.g., AES-GCM or ChaCha20-Poly1305).
- Services MUST route the raw PRF output through HKDF-SHA256 (RFC 5869) with an immutable, application-specific domain-separation string in the `info` parameter before key material derivation.
- Code MUST strictly validate that `clientExtensionResults.prf.supported` or `clientExtensionResults.prf.results.first` is populated and matches expected dimensions (32 bytes) before proceeding with cryptographic flows.
- Components NEVER retain or export raw PRF secret bytes; buffers MUST be imported non-extractable (`extractable: false`) and immediately zeroized (`buffer.fill(0)`) in a `finally` block.

## Bad vs Good Implementations
### Hardware Key Derivation via WebAuthn PRF Extension

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Sets userVerification to 'preferred' allowing bypass of biometric/PIN verification, assumes extension success without validating PRF results, exposes raw PRF output directly as an extractable AES key, and skips domain-separated HKDF expansion.
```typescript
export async function getEncryptionKeyBad(credentialId: Uint8Array, salt: Uint8Array): Promise<CryptoKey> {
  // Anti-pattern: 'preferred' UV weakens hardware isolation to user presence only
  const assertion = (await navigator.credentials.get({
    publicKey: {
      challenge: new Uint8Array(32),
      allowCredentials: [{ id: credentialId, type: 'public-key' }],
      userVerification: 'preferred',
      extensions: {
        prf: { eval: { first: salt } }
      }
    }
  })) as PublicKeyCredential;

  // Anti-pattern: Unchecked PRF output cast and direct use as AES-GCM key without HKDF
  const rawPrf = (assertion.getClientExtensionResults() as any).prf.results.first;
  return crypto.subtle.importKey(
    'raw',
    rawPrf,
    { name: 'AES-GCM', length: 256 },
    true, // Anti-pattern: extractable key leak
    ['encrypt', 'decrypt']
  );
}
```

#### Production Standard (Correct)
> **Standard**: Enforces userVerification 'required', strictly verifies PRF extension output availability and length, derives the symmetric key via HKDF-SHA256 with an immutable domain separator, sets extractable to false, and reliably zeroes memory in a finally block.
```typescript
export async function getHardwareBoundEncryptionKey(
  credentialId: Uint8Array,
  prfSalt: Uint8Array,
  contextInfo: string
): Promise<CryptoKey> {
  if (prfSalt.byteLength !== 32) {
    throw new RangeError('PRF salt must be cryptographically random and exactly 32 bytes.');
  }

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

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

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

  if (!rawFirst || rawFirst.byteLength !== 32) {
    throw new Error('Authenticator does not support the PRF extension or returned invalid key material.');
  }

  const ephemeralPrfSecret = new Uint8Array(rawFirst);
  try {
    const baseIkmKey = await crypto.subtle.importKey(
      'raw',
      ephemeralPrfSecret,
      'HKDF',
      false,
      ['deriveKey']
    );

    const domainSeparator = new TextEncoder().encode(`FIDO2-PRF-v1:${contextInfo}`);
    return await crypto.subtle.deriveKey(
      {
        name: 'HKDF',
        hash: 'SHA-256',
        salt: new Uint8Array(0),
        info: domainSeparator
      },
      baseIkmKey,
      { name: 'AES-GCM', length: 256 },
      false,
      ['encrypt', 'decrypt']
    );
  } finally {
    ephemeralPrfSecret.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: FIDO2 WebAuthn PRF Hardware-Bound Key Derivation Standard

FIDO2 WebAuthn PRF Hardware-Bound Key Derivation Standard defines an industrial-grade behavioral standard for security engineering. Mandates cryptographically sound implementation of WebAuthn Pseudo-Random Function (PRF) extension for client-side zero-knowledge encryption key derivation. Prohibits direct usage of raw PRF outputs as symmetric keys, enforces mandatory biometric/PIN user verification ('required'), and guarantees domain-separated HKDF expansion with ephemeral memory zeroization. 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: Direct use of raw PRF outputs as AES keys without HKDF expansion, lax user verification, or unverified extension support. 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 DriftDirect use of raw PRF outputs as AES keys without HKDF expansion, lax user verification, or unverified extension support.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 enforce `userVerification

Engineers MUST ALWAYS enforce `userVerification: 'required'` in both registration (`navigator.credentials.create`) and assertion (`navigator.credentials.get`) when invoking the WebAuthn PRF extension.

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 NEVER use the raw PRF evaluation output buffer directly as a symmetric cipher key (e.g., AES-GCM or ChaCha20-Poly1305).

Engineers MUST NEVER use the raw PRF evaluation output buffer directly as a symmetric cipher key (e.g., AES-GCM or ChaCha20-Poly1305).

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

Services MUST route the raw PRF output through HKDF-SHA256 (RFC 5869) with an immutable, application-specific domain-separation string in the `info` parameter before key material derivation.

Services MUST route the raw PRF output through HKDF-SHA256 (RFC 5869) with an immutable, application-specific domain-separation string in the `info` parameter before key material 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.
4

Code MUST strictly validate that `clientExtensionResults.prf.supported` or `clientExtensionResults.prf.results.first` is populated and matches expected dimensions (32 bytes) before proceeding with cryptographic flows.

Code MUST strictly validate that `clientExtensionResults.prf.supported` or `clientExtensionResults.prf.results.first` is populated and matches expected dimensions (32 bytes) before proceeding with cryptographic flows.

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

Components NEVER retain or export raw PRF secret bytes

Components NEVER retain or export raw PRF secret bytes; buffers MUST be imported non-extractable (`extractable: false`) and immediately zeroized (`buffer.fill(0)`) in a `finally` 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 FIDO2 WebAuthn PRF Hardware-Bound Key Derivation Standard critical for AI coding assistants?

Mandates cryptographically sound implementation of WebAuthn Pseudo-Random Function (PRF) extension for client-side zero-knowledge encryption key derivation. Prohibits direct usage of raw PRF outputs as symmetric keys, enforces mandatory biometric/PIN user verification ('required'), and guarantees domain-separated HKDF expansion with ephemeral memory zeroization. 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 (Direct use of raw PRF outputs as AES keys without HKDF expansion, lax user verification, or unverified extension support.) 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

FIDO2