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

Deterministic Zero-Knowledge Key Derivation via WebAuthn PRF and Conditional Mediation

Enforces strict cryptographic boundaries when using the WebAuthn PRF (Pseudo-Random Function) extension with conditional mediation for end-to-end encryption. Guarantees that authenticator-derived seeds are never transmitted to relying party servers, are isolated per security domain, and are processed strictly through HKDF before cipher instantiation.

Prohibited Anti-Pattern: Exposing Raw Authenticator PRF Outputs to Relying Party Servers or Reusing Unsalted PRF Roots Directly as Symmetric Cipher Keys

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Deterministic Zero-Knowledge Key Derivation via WebAuthn PRF and Conditional Mediation - Enforces strict cryptographic boundaries when using the WebAuthn PRF (Pseudo-Random Function) extension with conditional mediation for end-to-end encryption. Guarantees that authenticator-derived seeds are never transmitted to relying party servers, are isolated per security domain, and are processed strictly through HKDF before cipher instantiation.
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-conditional-mediation-key-derivation"
---

# Deterministic Zero-Knowledge Key Derivation via WebAuthn PRF and Conditional Mediation

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Exposing Raw Authenticator PRF Outputs to Relying Party Servers or Reusing Unsalted PRF Roots Directly as Symmetric Cipher Keys

## System Constraints
You are a Principal Security Architect specializing in WebAuthn Level 3 specifications, W3C PRF extensions, and Zero-Knowledge client architectures. Mandate strict cryptographic hygiene when deriving encryption keys from Passkeys.

## Strict Guidelines
- Engineers MUST ALWAYS pipe raw WebAuthn PRF evaluation outputs through HKDF (RFC 5869) with application-specific context info before initializing symmetric ciphers.
- Engineers MUST NOT transmit raw PRF output bytes, evaluator seeds, or unwrapped derived keys to backend relying party (RP) servers under any circumstances.
- Code MUST verify authenticator PRF capability during registration by inspecting 'clientExtensionResults.prf.enabled' before committing users to PRF-dependent client storage.
- Services MUST supply cryptographically secure, tenant-isolated or record-specific salts (minimum 32 bytes) for PRF evaluations to prevent cross-context key equivalence.
- Components NEVER persist derived key material in unencrypted browser storage primitives (localStorage, sessionStorage, or plaintext IndexedDB). Derived CryptoKey handles MUST remain non-extractable in memory.
- Engineers MUST gracefully handle conditional mediation fallbacks when authenticators lack PRF support or when user mediation declines authentication.

## Bad vs Good Implementations
### WebAuthn Conditional Mediation with Secure PRF HKDF Derivation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Raw PRF output is directly leaked to the server API, defeating zero-knowledge guarantees. Furthermore, raw PRF outputs are imported directly as AES keys with extractable permissions, omitting necessary HKDF domain separation.
```typescript
export async function authenticateAndUnlock(challenge: string, prfSalt: Uint8Array) {
  // Flaw 1: Sending PRF outputs to the server
  // Flaw 2: Using raw PRF output directly as an AES-GCM key without HKDF
  const credential = (await navigator.credentials.get({
    mediation: 'conditional',
    publicKey: {
      challenge: Uint8Array.from(atob(challenge), c => c.charCodeAt(0)),
      extensions: {
        prf: {
          eval: { first: prfSalt }
        }
      }
    }
  })) as PublicKeyCredential;

  const extResults = credential.getClientExtensionResults() as any;
  const rawPrfOutput = new Uint8Array(extResults.prf.results.first);

  // CRITICAL: Leaking PRF secret to the backend server
  await fetch('/api/keys/sync', {
    method: 'POST',
    body: JSON.stringify({ credentialId: credential.id, rawPrf: Array.from(rawPrfOutput) })
  });

  return crypto.subtle.importKey('raw', rawPrfOutput, { name: 'AES-GCM' }, true, ['encrypt', 'decrypt']);
}
```

#### Production Standard (Correct)
> **Standard**: The derived symmetric key is computed client-side using HKDF with domain-separated info strings, marked non-extractable, and zero raw secrets are dispatched across the network boundary.
```typescript
export async function authenticateAndUnlock(
  challenge: Uint8Array,
  prfSalt: Uint8Array,
  keyContextInfo: string
): Promise<CryptoKey> {
  const credential = (await navigator.credentials.get({
    mediation: 'conditional',
    publicKey: {
      challenge,
      userVerification: 'required',
      extensions: {
        prf: {
          eval: { first: prfSalt }
        }
      }
    }
  })) as PublicKeyCredential | null;

  if (!credential) {
    throw new Error('Passkey conditional authentication was aborted or unavailable.');
  }

  const extResults = credential.getClientExtensionResults();
  const prfResult = extResults.prf?.results?.first;
  if (!prfResult) {
    throw new Error('Authenticator did not evaluate PRF extension. Fallback recovery required.');
  }

  // Derive non-extractable symmetric key via HKDF with strict domain separation
  const prfKeyMaterial = await crypto.subtle.importKey(
    'raw',
    prfResult,
    { name: 'HKDF' },
    false,
    ['deriveKey']
  );

  const derivedKey = await crypto.subtle.deriveKey(
    {
      name: 'HKDF',
      salt: prfSalt,
      info: new TextEncoder().encode(keyContextInfo),
      hash: 'SHA-256'
    },
    prfKeyMaterial,
    { name: 'AES-GCM', length: 256 },
    false, // Must not be extractable
    ['encrypt', 'decrypt']
  );

  return derivedKey;
}
```

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: Deterministic Zero-Knowledge Key Derivation via WebAuthn PRF and Conditional Mediation

Deterministic Zero-Knowledge Key Derivation via WebAuthn PRF and Conditional Mediation defines an industrial-grade behavioral standard for security engineering. Enforces strict cryptographic boundaries when using the WebAuthn PRF (Pseudo-Random Function) extension with conditional mediation for end-to-end encryption. Guarantees that authenticator-derived seeds are never transmitted to relying party servers, are isolated per security domain, and are processed strictly through HKDF before cipher instantiation. 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 to Relying Party Servers or Reusing Unsalted PRF Roots Directly as Symmetric Cipher 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 to Relying Party Servers or Reusing Unsalted PRF Roots Directly as Symmetric Cipher 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 pipe raw WebAuthn PRF evaluation outputs through HKDF (RFC 5869) with application-specific context info before initializing symmetric ciphers.

Engineers MUST ALWAYS pipe raw WebAuthn PRF evaluation outputs through HKDF (RFC 5869) with application-specific context info before initializing symmetric ciphers.

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 output bytes, evaluator seeds, or unwrapped derived keys to backend relying party (RP) servers under any circumstances.

Engineers MUST NOT transmit raw PRF output bytes, evaluator seeds, or unwrapped derived keys to backend relying party (RP) servers under any circumstances.

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 verify authenticator PRF capability during registration by inspecting 'clientExtensionResults.prf.enabled' before committing users to PRF-dependent client storage.

Code MUST verify authenticator PRF capability during registration by inspecting 'clientExtensionResults.prf.enabled' before committing users to PRF-dependent client 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.
4

Services MUST supply cryptographically secure, tenant-isolated or record-specific salts (minimum 32 bytes) for PRF evaluations to prevent cross-context key equivalence.

Services MUST supply cryptographically secure, tenant-isolated or record-specific salts (minimum 32 bytes) for PRF evaluations to prevent cross-context key equivalence.

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 persist derived key material in unencrypted browser storage primitives (localStorage, sessionStorage, or plaintext IndexedDB). Derived CryptoKey handles MUST remain non-extractable in memory.

Components NEVER persist derived key material in unencrypted browser storage primitives (localStorage, sessionStorage, or plaintext IndexedDB). Derived CryptoKey handles MUST remain non-extractable in memory.

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

Engineers MUST gracefully handle conditional mediation fallbacks when authenticators lack PRF support or when user mediation declines authentication.

Engineers MUST gracefully handle conditional mediation fallbacks when authenticators lack PRF support or when user mediation declines authentication.

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 Deterministic Zero-Knowledge Key Derivation via WebAuthn PRF and Conditional Mediation critical for AI coding assistants?

Enforces strict cryptographic boundaries when using the WebAuthn PRF (Pseudo-Random Function) extension with conditional mediation for end-to-end encryption. Guarantees that authenticator-derived seeds are never transmitted to relying party servers, are isolated per security domain, and are processed strictly through HKDF before cipher instantiation. 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 to Relying Party Servers or Reusing Unsalted PRF Roots Directly as Symmetric Cipher 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

Deterministic