This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: webauthn-prf-client-side-envelope-encryption-guardrail

WebAuthn Level 3 PRF Salted Client-Side Envelope Encryption Invariant

Enforces strict zero-knowledge envelope encryption invariants utilizing WebAuthn Level 3 Pseudo-Random Function (PRF) extension outputs combined with cryptographically secure application-specific salts. Guarantees deterministic, hardware-backed Root Key derivation exclusively within client memory, forbidding raw key transport, unauthenticated HKDF derivations, and server-side key custody.

Prohibited Anti-Pattern: Leaking Raw Authenticator PRF Outputs to Backend or Relying on Server-Side Key Escrow

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn Level 3 PRF Salted Client-Side Envelope Encryption Invariant - Enforces strict zero-knowledge envelope encryption invariants utilizing WebAuthn Level 3 Pseudo-Random Function (PRF) extension outputs combined with cryptographically secure application-specific salts. Guarantees deterministic, hardware-backed Root Key derivation exclusively within client memory, forbidding raw key transport, unauthenticated HKDF derivations, and server-side key custody.
globs: src/**/*.{ts,tsx}, lib/**/*.{ts,tsx}, services/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-prf-client-side-envelope-encryption-guardrail"
---

# WebAuthn Level 3 PRF Salted Client-Side Envelope Encryption Invariant

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Leaking Raw Authenticator PRF Outputs to Backend or Relying on Server-Side Key Escrow

## System Constraints
You are a Principal Security Architect enforcing the WebAuthn Level 3 PRF Salted Client-Side Envelope Encryption Invariant. Mandate that PRF outputs (hmac-secret/prf) never exit the client runtime unhashed, are never transmitted to server endpoints, and are always processed through HKDF-SHA-256 with cryptographically isolated application salts to derive a Key Encryption Key (KEK) for local Data Encryption Key (DEK) unwrapping. Reject all code violating client-side zero-trust boundaries.

## Strict Guidelines
- Engineers MUST ALWAYS verify navigator.credentials.get/create includes the 'prf' extension input using an isolated, cryptographically random, per-user or per-document 32-byte salt.
- Engineers MUST ALWAYS derive the Key Encryption Key (KEK) using HKDF-SHA-256 with a domain-specific 'info' context string before unsealing or generating Data Encryption Keys (DEKs).
- Engineers MUST NOT transmit the raw PRF output array buffer (`prf.results.first`) or derived KEKs to any remote server or persistent local storage (localStorage, IndexedDB).
- Services MUST enforce envelope encryption: document payloads MUST be encrypted with ephemeral AES-256-GCM DEKs, and only the ciphertext, DEK ciphertext (wrapped by KEK), initialization vector, and public salt are stored remotely.
- Components NEVER hold unencrypted DEKs or raw PRF outputs in persistent component state longer than the active cryptographic operation lifecycle; explicit byte clearing MUST be enforced.

## Bad vs Good Implementations
### Deterministic Client-Side KEK Derivation from WebAuthn PRF Output

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Directly exfiltrates the raw PRF secret to a remote server, completely destroying zero-custody hardware guarantees. Furthermore, using the raw authenticator PRF output directly as an AES key without HKDF salt-expansion and info domain-separation exposes the application to cross-domain key reuse attacks.
```typescript
async function decryptUserData(assertion: AuthenticationCredential, encryptedData: ArrayBuffer) {
  // VULNERABLE: Direct transmission of PRF results or using raw PRF output directly as AES key
  const rawPrf = (assertion.getClientExtensionResults() as any).prf?.results?.first;
  if (!rawPrf) throw new Error('PRF not supported');

  // Flaw 1: Sending raw PRF to server violates zero-knowledge invariants
  await fetch('/api/user/keys/register', {
    method: 'POST',
    body: JSON.stringify({ prfSecret: Array.from(new Uint8Array(rawPrf)) }),
  });

  // Flaw 2: Using un-salt-stretched key directly as DEK without HKDF domain separation
  const directKey = await crypto.subtle.importKey(
    'raw',
    rawPrf,
    { name: 'AES-GCM' },
    false,
    ['decrypt']
  );
  return directKey;
}
```

#### Production Standard (Correct)
> **Standard**: Enforces full client-side zero-knowledge boundaries. Raw PRF outputs are consumed strictly as HKDF key material alongside domain-isolated application salts, deriving a transient Key Encryption Key (KEK) that safely unwraps the ephemeral Data Encryption Key (DEK). No raw secret or cryptographic key leaves the browser client.
```typescript
interface EncryptedEnvelope {
  ciphertext: Uint8Array;
  wrappedDek: Uint8Array;
  ivDek: Uint8Array;
  ivPayload: Uint8Array;
  envelopeSalt: Uint8Array;
}

async function decryptEnvelopeWithPrf(
  prfResultBuffer: ArrayBuffer,
  envelope: EncryptedEnvelope
): Promise<ArrayBuffer> {
  // Invariant 1: PRF output is strictly retained in client memory
  const prfKeyMaterial = await crypto.subtle.importKey(
    'raw',
    prfResultBuffer,
    'HKDF',
    false,
    ['deriveKey']
  );

  // Invariant 2: Contextual domain separation via HKDF-SHA-256 and unique envelope salt
  const kek = await crypto.subtle.deriveKey(
    {
      name: 'HKDF',
      hash: 'SHA-256',
      salt: envelope.envelopeSalt,
      info: new TextEncoder().encode('webauthn-l3-prf-client-envelope-kek-v1')
    },
    prfKeyMaterial,
    { name: 'AES-GCM', length: 256 },
    false,
    ['unwrapKey', 'decrypt']
  );

  // Invariant 3: Unwrap ephemeral Data Encryption Key (DEK)
  const rawDekBuffer = await crypto.subtle.decrypt(
    { name: 'AES-GCM', iv: envelope.ivDek },
    kek,
    envelope.wrappedDek
  );

  const dek = await crypto.subtle.importKey(
    'raw',
    rawDekBuffer,
    { name: 'AES-GCM' },
    false,
    ['decrypt']
  );

  // Invariant 4: Decrypt payload locally using ephemeral unwrapped DEK
  return crypto.subtle.decrypt(
    { name: 'AES-GCM', iv: envelope.ivPayload },
    dek,
    envelope.ciphertext
  );
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: WebAuthn Level 3 PRF Salted Client-Side Envelope Encryption Invariant

WebAuthn Level 3 PRF Salted Client-Side Envelope Encryption Invariant defines an industrial-grade behavioral standard for security engineering. Enforces strict zero-knowledge envelope encryption invariants utilizing WebAuthn Level 3 Pseudo-Random Function (PRF) extension outputs combined with cryptographically secure application-specific salts. Guarantees deterministic, hardware-backed Root Key derivation exclusively within client memory, forbidding raw key transport, unauthenticated HKDF derivations, and server-side key custody. 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: Leaking Raw Authenticator PRF Outputs to Backend or Relying on Server-Side Key Escrow 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 DriftLeaking Raw Authenticator PRF Outputs to Backend or Relying on Server-Side Key EscrowCritical
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.get/create includes the 'prf' extension input using an isolated, cryptographically random, per-user or per-document 32-byte salt.

Engineers MUST ALWAYS verify navigator.credentials.get/create includes the 'prf' extension input using an isolated, cryptographically random, per-user or per-document 32-byte 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.
2

Engineers MUST ALWAYS derive the Key Encryption Key (KEK) using HKDF-SHA-256 with a domain-specific 'info' context string before unsealing or generating Data Encryption Keys (DEKs).

Engineers MUST ALWAYS derive the Key Encryption Key (KEK) using HKDF-SHA-256 with a domain-specific 'info' context string before unsealing or generating Data Encryption Keys (DEKs).

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 the raw PRF output array buffer (`prf.results.first`) or derived KEKs to any remote server or persistent local storage (localStorage, IndexedDB).

Engineers MUST NOT transmit the raw PRF output array buffer (`prf.results.first`) or derived KEKs to any remote server or persistent local storage (localStorage, 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.
4

Services MUST enforce envelope encryption

Services MUST enforce envelope encryption: document payloads MUST be encrypted with ephemeral AES-256-GCM DEKs, and only the ciphertext, DEK ciphertext (wrapped by KEK), initialization vector, and public salt are stored remotely.

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 hold unencrypted DEKs or raw PRF outputs in persistent component state longer than the active cryptographic operation lifecycle

Components NEVER hold unencrypted DEKs or raw PRF outputs in persistent component state longer than the active cryptographic operation lifecycle; explicit byte clearing MUST be enforced.

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 Salted Client-Side Envelope Encryption Invariant critical for AI coding assistants?

Enforces strict zero-knowledge envelope encryption invariants utilizing WebAuthn Level 3 Pseudo-Random Function (PRF) extension outputs combined with cryptographically secure application-specific salts. Guarantees deterministic, hardware-backed Root Key derivation exclusively within client memory, forbidding raw key transport, unauthenticated HKDF derivations, and server-side key custody. 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 (Leaking Raw Authenticator PRF Outputs to Backend or Relying on Server-Side Key Escrow) 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