This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: webauthn-l3-conditional-mediation-cross-origin-boundary-standard

WebAuthn Level 3 Conditional Mediation Cross-Origin Boundary Standard

Enforces strict cryptographic origin binding and Permission-Policy verification for WebAuthn Level 3 conditional UI mediation embedded in cross-origin frames. Mandates server-side validation of clientDataJSON crossOrigin and topOrigin attributes alongside deterministic AbortController lifecycle management to eliminate credential harvesting and autofill mediation races.

Prohibited Anti-Pattern: Unvalidated Cross-Origin Conditional Mediation and Unbounded Autofill Race Conditions

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn Level 3 Conditional Mediation Cross-Origin Boundary Standard - Enforces strict cryptographic origin binding and Permission-Policy verification for WebAuthn Level 3 conditional UI mediation embedded in cross-origin frames. Mandates server-side validation of clientDataJSON crossOrigin and topOrigin attributes alongside deterministic AbortController lifecycle management to eliminate credential harvesting and autofill mediation races.
globs: src/**/*.{ts,tsx}, server/**/*.{ts,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-l3-conditional-mediation-cross-origin-boundary-standard"
---

# WebAuthn Level 3 Conditional Mediation Cross-Origin Boundary Standard

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Unvalidated Cross-Origin Conditional Mediation and Unbounded Autofill Race Conditions

## System Constraints
You are a Principal Engineer enforcing WebAuthn Level 3 Conditional Mediation Cross-Origin Boundary Standards. You must mandate strict adherence to WebAuthn L3 specifications for embedded conditional mediation (Passkey autofill). Ensure all cross-origin credential verification validates clientDataJSON flags ('crossOrigin', 'topOrigin') against authorized Related Origin manifests. Enforce explicit AbortController lifecycle management on all conditional mediation calls to prevent race conditions with modal authentication ceremonies.

## Strict Guidelines
- Engineers MUST ALWAYS validate `crossOrigin` and `topOrigin` in `clientDataJSON` during server-side authentication response verification whenever requests originate from nested or federated contexts.
- Engineers MUST verify that any cross-origin frame requesting passkey operations is explicitly permitted via HTTP header `Permissions-Policy: publickey-credentials-get=(self "https://trusted-origin.com")`.
- Services MUST validate that top-level origins claiming credentials across boundaries are authorized via the target RP's `/.well-known/webauthn` Related Origin Requests (ROR) manifest.
- Engineers MUST NOT invoke `navigator.credentials.get({ mediation: 'conditional', ... })` without an active `AbortSignal` tied to the lifecycle of the host input element.
- Components NEVER allow concurrent conditional mediation and modal (`mediation: 'required'`) requests; pending conditional ceremonies MUST be explicitly aborted prior to dispatching modal ceremonies.

## Bad vs Good Implementations
### WebAuthn L3 Server-Side clientDataJSON Boundary Verification & Client Mediation Lifecycle

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The verification function ignores WebAuthn Level 3 `crossOrigin` and `topOrigin` properties. If conditional mediation is requested within a nested browsing context or cross-origin iframe, an attacker can exploit federated contexts or cross-site embeddings without proving parent frame authorization.
```typescript
import { Request, Response } from 'express';

interface ClientDataJSON {
  type: string;
  challenge: string;
  origin: string;
}

export async function verifyPasskeyAuthentication(req: Request, res: Response) {
  const { clientDataJSONBase64, expectedChallenge, expectedRpId } = req.body;
  
  const rawJson = Buffer.from(clientDataJSONBase64, 'base64').toString('utf8');
  const clientData: ClientDataJSON = JSON.parse(rawJson);

  // VULNERABILITY: Blindly checks only origin, ignoring crossOrigin and topOrigin flags.
  // Malicious embedded iframes can harvest credentials or trigger autofill races.
  if (clientData.type !== 'webauthn.get') {
    return res.status(400).json({ error: 'Invalid operation type' });
  }
  if (clientData.challenge !== expectedChallenge) {
    return res.status(400).json({ error: 'Challenge mismatch' });
  }
  if (clientData.origin !== `https://${expectedRpId}`) {
    return res.status(400).json({ error: 'Origin mismatch' });
  }

  return res.status(200).json({ verified: true });
}
```

#### Production Standard (Correct)
> **Standard**: Production invariant compliant implementation ensuring memory safety, deterministic execution, and zero runtime hallucination.
```typescript
import { Request, Response } from 'express';

interface WebAuthnLevel3ClientDataJSON {
  type: string;
  challenge: string;
  origin: string;
  crossOrigin?: boolean;
  topOrigin?: string;
}

// Pre-approved related top origins based on RFC / W3C Related Origin Requests
const AUTHORIZED_TOP_ORIGINS = new Set<string>([
  'https://auth.example.com',
  'https://checkout.example.com',
]);

export async function verifyPasskeyAuthentication(req: Request, res: Response) {
  const { clientDataJSONBase64, expectedChallenge, expectedRpOrigin } = req.body;

  const rawJson = Buffer.from(clientDataJSONBase64, 'base64').toString('utf8');
  const clientData: WebAuthnLevel3ClientDataJSON = JSON.parse(rawJson);

  if (clientData.type !== 'webauthn.get') {
    return res.status(400).json({ error: 'Invalid token ceremony type' });
  }
  if (clientData.challenge !== expectedChallenge) {
    return res.status(400).json({ error: 'Cryptographic challenge mismatch' });
  }

  // Strict WebAuthn L3 Origin & Cross-Origin Boundary Assertion
  if (clientData.origin !== expectedRpOrigin) {
    return res.status(403).json({ error: 'Credential origin mismatch' });
  }

  if (clientData.crossOrigin === true) {
    if (!clientData.topOrigin || !AUTHORIZED_TOP_ORIGINS.has(clientData.topOrigin)) {
      return res.status(403).json({
        error: 'Untrusted cross-origin topOrigin boundary detected',
      });
    }
  } else if (clientData.crossOrigin === false && clientData.topOrigin !== undefined) {
    return res.status(400).json({ error: 'Malformed clientDataJSON boundary state' });
  }

  return res.status(200).json({ verified: true });
}
```

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: WebAuthn Level 3 Conditional Mediation Cross-Origin Boundary Standard

WebAuthn Level 3 Conditional Mediation Cross-Origin Boundary Standard defines an industrial-grade behavioral standard for security engineering. Enforces strict cryptographic origin binding and Permission-Policy verification for WebAuthn Level 3 conditional UI mediation embedded in cross-origin frames. Mandates server-side validation of clientDataJSON crossOrigin and topOrigin attributes alongside deterministic AbortController lifecycle management to eliminate credential harvesting and autofill mediation races. 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: Unvalidated Cross-Origin Conditional Mediation and Unbounded Autofill Race Conditions 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 DriftUnvalidated Cross-Origin Conditional Mediation and Unbounded Autofill Race ConditionsCritical
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 validate `crossOrigin` and `topOrigin` in `clientDataJSON` during server-side authentication response verification whenever requests originate from nested or federated contexts.

Engineers MUST ALWAYS validate `crossOrigin` and `topOrigin` in `clientDataJSON` during server-side authentication response verification whenever requests originate from nested or federated contexts.

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 verify that any cross-origin frame requesting passkey operations is explicitly permitted via HTTP header `Permissions-Policy

Engineers MUST verify that any cross-origin frame requesting passkey operations is explicitly permitted via HTTP header `Permissions-Policy: publickey-credentials-get=(self "https://trusted-origin.com")`.

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 validate that top-level origins claiming credentials across boundaries are authorized via the target RP's `/.well-known/webauthn` Related Origin Requests (ROR) manifest.

Services MUST validate that top-level origins claiming credentials across boundaries are authorized via the target RP's `/.well-known/webauthn` Related Origin Requests (ROR) manifest.

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 NOT invoke `navigator.credentials.get({ mediation

Engineers MUST NOT invoke `navigator.credentials.get({ mediation: 'conditional', ... })` without an active `AbortSignal` tied to the lifecycle of the host input element.

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 allow concurrent conditional mediation and modal (`mediation

Components NEVER allow concurrent conditional mediation and modal (`mediation: 'required'`) requests; pending conditional ceremonies MUST be explicitly aborted prior to dispatching modal ceremonies.

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 Conditional Mediation Cross-Origin Boundary Standard critical for AI coding assistants?

Enforces strict cryptographic origin binding and Permission-Policy verification for WebAuthn Level 3 conditional UI mediation embedded in cross-origin frames. Mandates server-side validation of clientDataJSON crossOrigin and topOrigin attributes alongside deterministic AbortController lifecycle management to eliminate credential harvesting and autofill mediation races. 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 (Unvalidated Cross-Origin Conditional Mediation and Unbounded Autofill Race Conditions) 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