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-webauthn-prf-ext-140

Hardware-Backed WebAuthn PRF Deterministic Key Derivation & Zero-Knowledge Enclaves

Enforces strict cryptographic patterns for WebAuthn Pseudo-Random Function (PRF) extension key derivation in client-side zero-knowledge enclaves. Mandates ephemeral HKDF expansion from authenticator outputs, strict separation of credential IDs, and prohibits storing, transmitting, or caching unmasked derived symmetric master keys.

Prohibited Anti-Pattern: Deriving Symmetric Keys from Raw Passkey Assertion Signatures or Storing PRF Secrets Unencrypted in State

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Hardware-Backed WebAuthn PRF Deterministic Key Derivation & Zero-Knowledge Enclaves - Enforces strict cryptographic patterns for WebAuthn Pseudo-Random Function (PRF) extension key derivation in client-side zero-knowledge enclaves. Mandates ephemeral HKDF expansion from authenticator outputs, strict separation of credential IDs, and prohibits storing, transmitting, or caching unmasked derived symmetric master keys.
globs: src/lib/crypto/**/*.{ts,tsx}, src/features/auth/**/*.{ts,tsx}, src/services/vault/**/*.{ts,tsx}, src/utils/webauthn/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-prf-deterministic-key-derivation-webauthn-prf-ext-140"
---

# Hardware-Backed WebAuthn PRF Deterministic Key Derivation & Zero-Knowledge Enclaves

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Deriving Symmetric Keys from Raw Passkey Assertion Signatures or Storing PRF Secrets Unencrypted in State

## System Constraints
You are a Principal Cryptographic Systems Architect enforcing strict security invariants for WebAuthn PRF (Pseudo-Random Function) extension usage. All client-side end-to-end encryption keys derived from authenticators must follow strict HMAC/HKDF domain separation, never transmit raw PRF seeds across network boundaries, zero out cryptographic material from memory after key derivation, and verify PRF extension availability prior to enclave initialization.

## Strict Guidelines
- Engineers MUST ALWAYS verify navigator.credentials with the 'prf' extension enabled within `clientExtensionResults` before assuming hardware key isolation.
- Engineers MUST ALWAYS pipe the 32-byte authenticator PRF output (`results.prf.results.first`) into HKDF-SHA256 with an explicit, distinct application-specific info string and a deterministic salt.
- Engineers MUST NOT use signature payloads (`authenticatorData`, `clientDataJSON`, or ECDSA signatures) as key seeds instead of the dedicated PRF extension output.
- Engineers MUST NEVER persist raw PRF seeds, intermediate HKDF outputs, or derived AES-GCM CryptoKey handles to localStorage, sessionStorage, or IndexedDB.
- Code MUST zeroize Uint8Array buffers containing intermediate raw key material immediately after `crypto.subtle.importKey` creates non-extractable CryptoKey handles.
- Services MUST ensure that WebAuthn challenge generation enforces User Verification (`userVerification: 'required'`) when PRF inputs are evaluated.

## Bad vs Good Implementations
### WebAuthn PRF Assertion and HKDF Key Derivation Invariant

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Derives a symmetric key from signature bytes instead of the PRF extension, permits non-user-verified operations ('preferred'), and marks the key as extractable while risking cross-context leakage.
```typescript
export async function deriveVaultKeyBad(credentialId: string, challenge: Uint8Array): Promise<CryptoKey> {
  // Anti-pattern: Using raw assertion signature as key seed
  const assertion = await navigator.credentials.get({
    publicKey: {
      challenge,
      allowCredentials: [{ id: new TextEncoder().encode(credentialId), type: 'public-key' }],
      userVerification: 'preferred'
    }
  }) as PublicKeyCredential;

  const response = assertion.response as AuthenticatorAssertionResponse;
  // Flaw: Signature contains nonces and malleability, leaks signature as secret, not deterministic or zero-knowledge
  const rawSig = response.signature;
  
  return crypto.subtle.importKey(
    'raw',
    rawSig.slice(0, 32),
    { name: 'AES-GCM', length: 256 },
    true, // Flaw: Extractable master key
    ['encrypt', 'decrypt']
  );
}
```

#### Production Standard (Correct)
> **Standard**: Correctly invokes the WebAuthn PRF extension with 'userVerification: required', pipes the result through HKDF-SHA256 with domain-separated info parameters, enforces non-extractable CryptoKey policies, and zeroes the raw key buffer.
```typescript
const PRF_SALT = new TextEncoder().encode('e2ee-enclave-v1-domain-salt-deterministic');
const HKDF_INFO = new TextEncoder().encode('aes-gcm-master-vault-encryption-key');

export async function deriveVaultKey(credentialId: BufferSource, challenge: Uint8Array): Promise<CryptoKey> {
  const assertion = await navigator.credentials.get({
    publicKey: {
      challenge,
      allowCredentials: [{ id: credentialId, type: 'public-key' }],
      userVerification: 'required',
      extensions: {
        prf: {
          eval: {
            first: PRF_SALT
          }
        }
      }
    }
  }) as PublicKeyCredential;

  const extResults = assertion.getClientExtensionResults() as AuthenticationExtensionsClientOutputs & {
    prf?: { results?: { first: ArrayBuffer } };
  };

  if (!extResults.prf?.results?.first) {
    throw new Error('WebAuthn PRF extension not supported or failed by authenticator');
  }

  const prfRawOutput = new Uint8Array(extResults.prf.results.first);
  
  try {
    const initialKeyMaterial = await crypto.subtle.importKey(
      'raw',
      prfRawOutput,
      { name: 'HKDF' },
      false,
      ['deriveKey']
    );

    return await crypto.subtle.deriveKey(
      {
        name: 'HKDF',
        hash: 'SHA-256',
        salt: PRF_SALT,
        info: HKDF_INFO
      },
      initialKeyMaterial,
      { name: 'AES-GCM', length: 256 },
      false, // Invariant: Non-extractable key
      ['encrypt', 'decrypt']
    );
  } finally {
    // Invariant: Zeroize raw memory immediately
    prfRawOutput.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: Hardware-Backed WebAuthn PRF Deterministic Key Derivation & Zero-Knowledge Enclaves

Hardware-Backed WebAuthn PRF Deterministic Key Derivation & Zero-Knowledge Enclaves defines an industrial-grade behavioral standard for security engineering. Enforces strict cryptographic patterns for WebAuthn Pseudo-Random Function (PRF) extension key derivation in client-side zero-knowledge enclaves. Mandates ephemeral HKDF expansion from authenticator outputs, strict separation of credential IDs, and prohibits storing, transmitting, or caching unmasked derived symmetric master 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: Deriving Symmetric Keys from Raw Passkey Assertion Signatures or Storing PRF Secrets Unencrypted in State 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 DriftDeriving Symmetric Keys from Raw Passkey Assertion Signatures or Storing PRF Secrets Unencrypted in StateCritical
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 verify navigator.credentials with the 'prf' extension enabled within `clientExtensionResults` before assuming hardware key isolation.

Engineers MUST ALWAYS verify navigator.credentials with the 'prf' extension enabled within `clientExtensionResults` before assuming hardware key isolation.

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 pipe the 32-byte authenticator PRF output (`results.prf.results.first`) into HKDF-SHA256 with an explicit, distinct application-specific info string and a deterministic salt.

Engineers MUST ALWAYS pipe the 32-byte authenticator PRF output (`results.prf.results.first`) into HKDF-SHA256 with an explicit, distinct application-specific info string and a deterministic salt.

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 use signature payloads (`authenticatorData`, `clientDataJSON`, or ECDSA signatures) as key seeds instead of the dedicated PRF extension output.

Engineers MUST NOT use signature payloads (`authenticatorData`, `clientDataJSON`, or ECDSA signatures) as key seeds instead of the dedicated PRF extension output.

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 NEVER persist raw PRF seeds, intermediate HKDF outputs, or derived AES-GCM CryptoKey handles to localStorage, sessionStorage, or IndexedDB.

Engineers MUST NEVER persist raw PRF seeds, intermediate HKDF outputs, or derived AES-GCM CryptoKey handles to localStorage, sessionStorage, or IndexedDB.

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

Code MUST zeroize Uint8Array buffers containing intermediate raw key material immediately after `crypto.subtle.importKey` creates non-extractable CryptoKey handles.

Code MUST zeroize Uint8Array buffers containing intermediate raw key material immediately after `crypto.subtle.importKey` creates non-extractable CryptoKey handles.

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 ensure that WebAuthn challenge generation enforces User Verification (`userVerification

Services MUST ensure that WebAuthn challenge generation enforces User Verification (`userVerification: 'required'`) when PRF inputs are evaluated.

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-Backed WebAuthn PRF Deterministic Key Derivation & Zero-Knowledge Enclaves critical for AI coding assistants?

Enforces strict cryptographic patterns for WebAuthn Pseudo-Random Function (PRF) extension key derivation in client-side zero-knowledge enclaves. Mandates ephemeral HKDF expansion from authenticator outputs, strict separation of credential IDs, and prohibits storing, transmitting, or caching unmasked derived symmetric master 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 (Deriving Symmetric Keys from Raw Passkey Assertion Signatures or Storing PRF Secrets Unencrypted in State) 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-Backed