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

Hardware-Bound WebAuthn PRF Deterministic Key Derivation Invariants

Enforces client-side zero-knowledge key synthesis via the WebAuthn Level 3 PRF (Pseudo-Random Function) extension. Guarantees that derived symmetric keys never leak to backend infrastructure, authenticator assertions enforce explicit user verification, and raw PRF outputs are immediately expanded into non-extractable cryptographic keys using domain-separated HKDF.

Prohibited Anti-Pattern: Transmitting Raw PRF Secrets to Backends, Omitting Hardware User Verification, or Persisting Extractable Master Keys

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Hardware-Bound WebAuthn PRF Deterministic Key Derivation Invariants - Enforces client-side zero-knowledge key synthesis via the WebAuthn Level 3 PRF (Pseudo-Random Function) extension. Guarantees that derived symmetric keys never leak to backend infrastructure, authenticator assertions enforce explicit user verification, and raw PRF outputs are immediately expanded into non-extractable cryptographic keys using domain-separated HKDF.
globs: src/**/crypto/**/*.{ts,tsx}, src/**/auth/**/*.{ts,tsx}, src/**/*prf*.ts, src/**/*keystore*.ts
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-prf-deterministic-key-derivation-security"
---

# Hardware-Bound WebAuthn PRF Deterministic Key Derivation Invariants

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Transmitting Raw PRF Secrets to Backends, Omitting Hardware User Verification, or Persisting Extractable Master Keys

## System Constraints
You are a Principal Security Architect enforcing the WebAuthn PRF (Pseudo-Random Function) extension specification (WebAuthn Level 3 / CTAP 2.1). Mandate that authenticators perform hardware-bound deterministic key evaluation without disclosing credential-bound secrets. Require 'userVerification: required' on every PRF assertion to protect against unauthorized evaluations. Forbid transmitting raw PRF outputs, master salts, or derived encryption keys over the wire. Enforce immediate import of raw PRF output into non-extractable WebCrypto HKDF primitives with unique application domain separation contexts.

## Strict Guidelines
- Engineers MUST ALWAYS set `userVerification: 'required'` in `navigator.credentials.get({ publicKey: ... })` calls evaluating PRF extensions to ensure biometric/PIN validation is enforced in hardware.
- Engineers MUST NOT transmit raw PRF outputs (`results.first` or `results.second`) to cloud services, backend APIs, telemetry buffers, or unencrypted persistent storage.
- Code MUST consume raw PRF evaluation buffers immediately through `crypto.subtle.importKey('raw', prfOutput, 'HKDF', false, ['deriveKey'])` with `extractable: false`.
- Services MUST enforce cryptographic domain separation by supplying unique, context-specific `info` parameters (e.g., `application/subsystem/v1`) during subsequent `deriveKey` operations.
- Components NEVER fall back to unauthenticated or software-emulated master key persistence when the authenticator PRF extension is unavailable; failures must fail closed.

## Bad vs Good Implementations
### Deterministic PRF Evaluation and Non-Extractable Key Derivation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The bad example specifies 'preferred' user verification, transmits the raw PRF evaluation buffer to a cloud API, bypasses HKDF domain separation, and imports the key with extractable set to true, breaking zero-knowledge guarantees.
```typescript
export async function deriveEncryptionKey(credentialId: Uint8Array, salt: Uint8Array): Promise<CryptoKey> {
  // Flaw 1: userVerification defaults to 'preferred', allowing bypass
  // Flaw 2: extractable is true
  // Flaw 3: Sends raw PRF output to the backend API for escrow
  const assertion = await navigator.credentials.get({
    publicKey: {
      challenge: crypto.getRandomValues(new Uint8Array(32)),
      allowCredentials: [{ id: credentialId, type: 'public-key' }],
      userVerification: 'preferred',
      extensions: {
        prf: { eval: { first: salt } }
      }
    }
  }) as PublicKeyCredential;

  const results = assertion.getClientExtensionResults() as any;
  const rawSecret = results.prf?.results?.first as ArrayBuffer;

  // CRITICAL SECURITY VIOILATION: Exposing master key material to server
  await fetch('/api/v1/vault/sync', {
    method: 'POST',
    body: JSON.stringify({ prfSecret: Array.from(new Uint8Array(rawSecret)) })
  });

  return crypto.subtle.importKey(
    'raw',
    rawSecret,
    { name: 'AES-GCM' },
    true, // Extractable leaks raw secret in memory inspection
    ['encrypt', 'decrypt']
  );
}
```

#### Production Standard (Correct)
> **Standard**: The good implementation strictly enforces userVerification: 'required', validates PRF extension availability, protects intermediate key material as non-extractable, applies HKDF with context-bound domain separation, and never transmits derived secrets.
```typescript
export async function deriveEncryptionKey(
  credentialId: Uint8Array,
  salt: Uint8Array,
  domainContext: string
): Promise<CryptoKey> {
  // Invariant 1: Force hardware-level biometric or PIN authentication
  const assertion = await navigator.credentials.get({
    publicKey: {
      challenge: crypto.getRandomValues(new Uint8Array(32)),
      allowCredentials: [{ id: credentialId, type: 'public-key', transports: ['internal', 'hybrid', 'usb', 'nfc'] }],
      userVerification: 'required',
      extensions: {
        prf: { eval: { first: salt } }
      }
    }
  }) as PublicKeyCredential | null;

  if (!assertion) {
    throw new Error('Credential assertion failed or cancelled.');
  }

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

  if (!(rawPrfBuffer instanceof ArrayBuffer)) {
    throw new Error('Authenticator did not return PRF output. Hardware support missing.');
  }

  // Invariant 2: Import raw PRF output into non-extractable HKDF master
  const initialKeyMaterial = await crypto.subtle.importKey(
    'raw',
    rawPrfBuffer,
    'HKDF',
    false,
    ['deriveKey']
  );

  // Invariant 3: Domain separation with context string and non-extractable AES-GCM output
  const encoder = new TextEncoder();
  return crypto.subtle.deriveKey(
    {
      name: 'HKDF',
      hash: 'SHA-256',
      salt: salt,
      info: encoder.encode(`zk-vault/prf-domain/${domainContext}/v1`)
    },
    initialKeyMaterial,
    { name: 'AES-GCM', length: 256 },
    false,
    ['encrypt', 'decrypt']
  );
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Hardware-Bound WebAuthn PRF Deterministic Key Derivation Invariants

Hardware-Bound WebAuthn PRF Deterministic Key Derivation Invariants defines an industrial-grade behavioral standard for security engineering. Enforces client-side zero-knowledge key synthesis via the WebAuthn Level 3 PRF (Pseudo-Random Function) extension. Guarantees that derived symmetric keys never leak to backend infrastructure, authenticator assertions enforce explicit user verification, and raw PRF outputs are immediately expanded into non-extractable cryptographic keys using domain-separated HKDF. 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 Secrets to Backends, Omitting Hardware User Verification, or Persisting Extractable Master 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 DriftTransmitting Raw PRF Secrets to Backends, Omitting Hardware User Verification, or Persisting Extractable Master 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 set `userVerification

Engineers MUST ALWAYS set `userVerification: 'required'` in `navigator.credentials.get({ publicKey: ... })` calls evaluating PRF extensions to ensure biometric/PIN validation is enforced in hardware.

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 raw PRF outputs (`results.first` or `results.second`) to cloud services, backend APIs, telemetry buffers, or unencrypted persistent storage.

Engineers MUST NOT transmit raw PRF outputs (`results.first` or `results.second`) to cloud services, backend APIs, telemetry buffers, or unencrypted persistent storage.

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

Code MUST consume raw PRF evaluation buffers immediately through `crypto.subtle.importKey('raw', prfOutput, 'HKDF', false, ['deriveKey'])` with `extractable

Code MUST consume raw PRF evaluation buffers immediately through `crypto.subtle.importKey('raw', prfOutput, 'HKDF', false, ['deriveKey'])` with `extractable: false`.

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

Services MUST enforce cryptographic domain separation by supplying unique, context-specific `info` parameters (e.g., `application/subsystem/v1`) during subsequent `deriveKey` operations.

Services MUST enforce cryptographic domain separation by supplying unique, context-specific `info` parameters (e.g., `application/subsystem/v1`) during subsequent `deriveKey` 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.
5

Components NEVER fall back to unauthenticated or software-emulated master key persistence when the authenticator PRF extension is unavailable

Components NEVER fall back to unauthenticated or software-emulated master key persistence when the authenticator PRF extension is unavailable; failures must fail closed.

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 Hardware-Bound WebAuthn PRF Deterministic Key Derivation Invariants critical for AI coding assistants?

Enforces client-side zero-knowledge key synthesis via the WebAuthn Level 3 PRF (Pseudo-Random Function) extension. Guarantees that derived symmetric keys never leak to backend infrastructure, authenticator assertions enforce explicit user verification, and raw PRF outputs are immediately expanded into non-extractable cryptographic keys using domain-separated HKDF. 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 Secrets to Backends, Omitting Hardware User Verification, or Persisting Extractable Master 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

Hardware-Bound