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

WebAuthn Level 3 Passkey Origin & Relying Party Cryptographic Binding Standard

Enforces strict, cryptographically verified origin and Relying Party (RP) ID validation on WebAuthn Level 3 authentication assertions to defeat Adversary-in-the-Middle (AitM) reverse-proxy session hijacking. Mandates canonical origin whitelisting over dynamic header reflection, explicit verification of the clientDataJSON crossOrigin member, and strict validation of authenticatorData rpIdHash and flags.

Prohibited Anti-Pattern: Dynamic RP Origin Reflection and Missing crossOrigin Checks Permitting Reverse-Proxy Phishing Hijacks

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn Level 3 Passkey Origin & Relying Party Cryptographic Binding Standard - Enforces strict, cryptographically verified origin and Relying Party (RP) ID validation on WebAuthn Level 3 authentication assertions to defeat Adversary-in-the-Middle (AitM) reverse-proxy session hijacking. Mandates canonical origin whitelisting over dynamic header reflection, explicit verification of the clientDataJSON crossOrigin member, and strict validation of authenticatorData rpIdHash and flags.
globs: src/**/auth/**/*.{ts,tsx,js}, src/**/webauthn/**/*.{ts,tsx,js}, src/server/api/routers/auth/**/*.{ts,tsx,js}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-l3-cross-origin-binding-guardrail"
---

# WebAuthn Level 3 Passkey Origin & Relying Party Cryptographic Binding Standard

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Dynamic RP Origin Reflection and Missing crossOrigin Checks Permitting Reverse-Proxy Phishing Hijacks

## System Constraints
You are a Principal Software Architect enforcing WebAuthn Level 3 and FIDO2 standards. Passkeys cryptographically bind authentication ceremonies to the origin and relying party ID to defeat AitM proxies (e.g., Evilginx). Dynamic reflection of request headers (`Host`, `X-Forwarded-Host`, `Origin`) into WebAuthn verification methods completely undermines this security model. You must reject any verification logic that computes expected RP ID or expected Origin from untrusted HTTP request headers, and you must strictly enforce clientDataJSON verification, crossOrigin flags, user verification, and replay resistance.

## Strict Guidelines
- Engineers MUST ALWAYS validate WebAuthn assertions against static, canonical Relying Party IDs (RP ID) and pre-configured origin whitelists.
- Engineers MUST NOT dynamically construct `expectedOrigin` or `expectedRPID` from HTTP request headers (`Host`, `X-Forwarded-Host`, `Origin`, or `Referer`).
- Services MUST verify the WebAuthn Level 3 `crossOrigin` property in `clientDataJSON`; if `crossOrigin: true` is present and cross-origin iframe authentication is not explicitly provisioned, the assertion MUST be rejected immediately.
- Code SHOULD enforce User Verification (`UV=1`) in `authenticatorData` flags (`requireUserVerification: true`) to guarantee biometric or PIN presence rather than basic User Presence alone.
- Components NEVER store or reuse cryptographic challenges across sessions; challenges MUST be cryptographically random (minimum 32 bytes), single-use, bounded by a strict TTL (maximum 120 seconds), and securely destroyed upon initial evaluation.

## Bad vs Good Implementations
### AitM Vulnerability: Dynamic Origin Reflection vs. Hardened Canonical WebAuthn L3 Validation

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Reflecting request headers into `expectedOrigin` and `expectedRPID` dismantles WebAuthn's primary defense against reverse-proxy AitM attacks. If an adversary proxies credentials via `evil-phish.com`, the dynamic extraction matches the attacker's origin instead of flagging an origin mismatch, granting the attacker a validated session.
```typescript
import { verifyAuthenticationResponse } from '@simplewebauthn/server';
import type { AuthenticationResponseJSON } from '@simplewebauthn/types';
import type { Request } from 'express';

export async function verifyPasskey(req: Request, assertion: AuthenticationResponseJSON) {
  // VULNERABILITY: Dynamic origin and RP ID extraction from request headers.
  // An AitM reverse proxy (e.g., evil-login.com) forwarding to this server passes its own Host,
  // tricking the server into accepting clientData created for evil-login.com.
  const host = req.headers['host'] || 'localhost';
  const dynamicOrigin = `${req.protocol}://${host}`;
  const dynamicRpId = host.split(':')[0];

  return await verifyAuthenticationResponse({
    response: assertion,
    expectedChallenge: req.session.challenge!,
    expectedOrigin: dynamicOrigin,
    expectedRPID: dynamicRpId,
    requireUserVerification: false, // Fails to enforce biometric/PIN validation
  });
}
```

#### Production Standard (Correct)
> **Standard**: Validates assertions exclusively against immutable canonical origins and RP IDs defined at runtime config, bypassing request header spoofing. Checks the WebAuthn Level 3 `crossOrigin` property to eliminate cross-origin injection, enforces challenge expiration, and requires user verification flags.
```typescript
import { verifyAuthenticationResponse } from '@simplewebauthn/server';
import type { AuthenticationResponseJSON } from '@simplewebauthn/types';

// Canonical invariant constants configured at deployment time
const CANONICAL_RP_ID = 'auth.example.com';
const ALLOWED_ORIGINS: ReadonlySet<string> = new Set([
  'https://auth.example.com',
  'https://app.example.com'
]);

interface SessionContext {
  challenge: string;
  userId: string;
  issuedAt: number;
}

export async function verifyPasskey(
  session: SessionContext,
  assertion: AuthenticationResponseJSON,
  expectedCredentialPublicKey: Uint8Array
) {
  // 1. Enforce challenge TTL (replay protection)
  const CHALLENGE_TTL_MS = 120_000;
  if (Date.now() - session.issuedAt > CHALLENGE_TTL_MS) {
    throw new Error('WebAuthn ceremony expired; challenge stale');
  }

  // 2. Decode clientDataJSON to enforce WebAuthn Level 3 crossOrigin invariants
  const rawClientData = Buffer.from(assertion.response.clientDataJSON, 'base64url').toString('utf-8');
  const clientData = JSON.parse(rawClientData) as {
    type: string;
    challenge: string;
    origin: string;
    crossOrigin?: boolean;
  };

  if (clientData.crossOrigin === true) {
    throw new Error('Unauthorized cross-origin passkey assertion detected');
  }

  if (!ALLOWED_ORIGINS.has(clientData.origin)) {
    throw new Error(`Untrusted WebAuthn origin detected: ${clientData.origin}`);
  }

  // 3. Perform cryptographic verification with hardened canonical constraints
  const verification = await verifyAuthenticationResponse({
    response: assertion,
    expectedChallenge: session.challenge,
    expectedOrigin: Array.from(ALLOWED_ORIGINS),
    expectedRPID: CANONICAL_RP_ID,
    authenticator: {
      credentialPublicKey: expectedCredentialPublicKey,
      credentialID: assertion.id,
      counter: 0,
    },
    requireUserVerification: true, // Guarantees biometric or PIN gate
  });

  if (!verification.verified) {
    throw new Error('Cryptographic signature verification failed');
  }

  return verification;
}
```

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 Passkey Origin & Relying Party Cryptographic Binding Standard

WebAuthn Level 3 Passkey Origin & Relying Party Cryptographic Binding Standard defines an industrial-grade behavioral standard for security engineering. Enforces strict, cryptographically verified origin and Relying Party (RP) ID validation on WebAuthn Level 3 authentication assertions to defeat Adversary-in-the-Middle (AitM) reverse-proxy session hijacking. Mandates canonical origin whitelisting over dynamic header reflection, explicit verification of the clientDataJSON crossOrigin member, and strict validation of authenticatorData rpIdHash and flags. 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: Dynamic RP Origin Reflection and Missing crossOrigin Checks Permitting Reverse-Proxy Phishing Hijacks 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 DriftDynamic RP Origin Reflection and Missing crossOrigin Checks Permitting Reverse-Proxy Phishing HijacksCritical
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 WebAuthn assertions against static, canonical Relying Party IDs (RP ID) and pre-configured origin whitelists.

Engineers MUST ALWAYS validate WebAuthn assertions against static, canonical Relying Party IDs (RP ID) and pre-configured origin whitelists.

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 dynamically construct `expectedOrigin` or `expectedRPID` from HTTP request headers (`Host`, `X-Forwarded-Host`, `Origin`, or `Referer`).

Engineers MUST NOT dynamically construct `expectedOrigin` or `expectedRPID` from HTTP request headers (`Host`, `X-Forwarded-Host`, `Origin`, or `Referer`).

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 verify the WebAuthn Level 3 `crossOrigin` property in `clientDataJSON`

Services MUST verify the WebAuthn Level 3 `crossOrigin` property in `clientDataJSON`; if `crossOrigin: true` is present and cross-origin iframe authentication is not explicitly provisioned, the assertion MUST be rejected immediately.

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

Code SHOULD enforce User Verification (`UV=1`) in `authenticatorData` flags (`requireUserVerification

Code SHOULD enforce User Verification (`UV=1`) in `authenticatorData` flags (`requireUserVerification: true`) to guarantee biometric or PIN presence rather than basic User Presence alone.

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 store or reuse cryptographic challenges across sessions

Components NEVER store or reuse cryptographic challenges across sessions; challenges MUST be cryptographically random (minimum 32 bytes), single-use, bounded by a strict TTL (maximum 120 seconds), and securely destroyed upon initial evaluation.

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 Passkey Origin & Relying Party Cryptographic Binding Standard critical for AI coding assistants?

Enforces strict, cryptographically verified origin and Relying Party (RP) ID validation on WebAuthn Level 3 authentication assertions to defeat Adversary-in-the-Middle (AitM) reverse-proxy session hijacking. Mandates canonical origin whitelisting over dynamic header reflection, explicit verification of the clientDataJSON crossOrigin member, and strict validation of authenticatorData rpIdHash and flags. 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 (Dynamic RP Origin Reflection and Missing crossOrigin Checks Permitting Reverse-Proxy Phishing Hijacks) 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