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

WebAuthn CTAP 2.2 Cross-Device Ephemeral ECDH Proximity Binding Guardrail

Enforces strict validation and cryptographic tying of WebAuthn hybrid cross-device transport (caBLE/FIDO CTAP 2.2) authentication assertions to ephemeral ECDH-derived session channels. Precludes QR-phishing, adversarial session interception, and cross-device session bleeding by mandating constant-time verification of the clientDataJSON hash, ephemeral authenticator public key derivation, and Bluetooth Low Energy (BLE) proximity routing commitments before issuing server-side user sessions.

Prohibited Anti-Pattern: Accepting Cross-Device Hybrid WebAuthn Assertions Without Enforcing Ephemeral ECDH Channel Tying and BLE Proximity Commitments

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn CTAP 2.2 Cross-Device Ephemeral ECDH Proximity Binding Guardrail - Enforces strict validation and cryptographic tying of WebAuthn hybrid cross-device transport (caBLE/FIDO CTAP 2.2) authentication assertions to ephemeral ECDH-derived session channels. Precludes QR-phishing, adversarial session interception, and cross-device session bleeding by mandating constant-time verification of the clientDataJSON hash, ephemeral authenticator public key derivation, and Bluetooth Low Energy (BLE) proximity routing commitments before issuing server-side user sessions.
globs: src/auth/**/*.ts, src/security/**/*.ts, src/identity/**/*.ts, src/services/webauthn/**/*.ts, src/api/v*/auth/**/*.ts
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-ctap22-ephemeral-ecdh-binding-guardrail"
---

# WebAuthn CTAP 2.2 Cross-Device Ephemeral ECDH Proximity Binding Guardrail

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Accepting Cross-Device Hybrid WebAuthn Assertions Without Enforcing Ephemeral ECDH Channel Tying and BLE Proximity Commitments

## System Constraints
You are a Principal Security Architect enforcing CTAP 2.2 and FIDO Hybrid specification compliance. You must prohibit any implementation that blindly accepts client assertions from hybrid (cross-device/caBLE) transports without cryptographically verifying the ephemeral ECDH shared secret derived from the QR initiation handshake and ensuring strict single-use binding to the authenticated session context.

## Strict Guidelines
- Engineers MUST ALWAYS cryptographically bind the WebAuthn challenge to an ephemeral ECDH keypair generated exclusively for the single-use QR hybrid session.
- Engineers MUST verify that the authenticator's clientDataJSON contains the exact unhashed cross-device channel binding parameter matching the server's ephemeral public key.
- Engineers MUST NOT persist or reuse hybrid ephemeral ECDH session tokens across authentication flows, enforcing a hard TTL (strictly <= 120 seconds).
- Services MUST enforce BLE proximity validation by asserting the presence and cryptographic validity of the routing secret and tunnel symmetric key negotiated during the CTAP 2.2 handshake.
- Services MUST immediately invalidate the ephemeral session handle upon any signature verification failure or upon first successful issuance of the primary session token to prevent replay attacks.
- Components NEVER accept fallback assertions from non-BLE transports when the user initiation was flagged as cross-device hybrid authentication.

## Bad vs Good Implementations
### Cross-Device Assertion Verification Anti-Pattern vs CTAP 2.2 Ephemeral ECDH Binding

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The handler blindly accepts a hybrid assertion matching only the generic challenge without validating that the assertion was produced inside the ephemeral BLE/ECDH channel established by the initial QR code. An adversary conducting a QR-phishing attack can trick a victim on a different network into authenticating the attacker's active session.
```typescript
import { verifyRegistrationResponse } from '@simplewebauthn/server';
import type { AuthenticationResponseJSON } from '@simplewebauthn/types';

// VULNERABLE: Lacks cryptographic binding to the ephemeral QR/BLE session
export async function verifyHybridAssertionBad(
  response: AuthenticationResponseJSON,
  expectedChallenge: string,
  sessionId: string
) {
  // Insecure: Session is looked up without asserting ownership of the ephemeral ECDH tunnel
  const verification = await verifyRegistrationResponse({
    response: response as any,
    expectedChallenge,
    expectedOrigin: 'https://auth.example.com',
    expectedRPID: 'example.com',
  });

  if (verification.verified) {
    // Session bleeding: Attacker scanning QR remotely can bind assertion to an arbitrary target session
    await createSession(sessionId, verification.registrationInfo?.credentialID);
    return { success: true };
  }

  return { success: false };
}
```

#### Production Standard (Correct)
> **Standard**: Ensures constant-time validation of ephemeral ECDH peer keys, enforces ephemeral channel single-use status with strict 120s TTL, and checks clientDataJSON against a derived HMAC channel binding key. This binds the WebAuthn response strictly to the authenticating device via physical BLE proximity.
```typescript
import { crypto } from 'node:crypto';
import { verifyAuthenticationResponse } from '@simplewebauthn/server';
import type { AuthenticationResponseJSON } from '@simplewebauthn/types';

interface HybridSessionContext {
  sessionId: string;
  ephemeralPrivateKey: crypto.KeyObject;
  expectedPeerPublicKeyHash: Buffer;
  issuedAtMs: number;
  consumed: boolean;
}

const HYBRID_TTL_MS = 120_000; // 2-minute strict TTL

export async function verifyHybridAssertionProduction(
  response: AuthenticationResponseJSON,
  context: HybridSessionContext,
  peerEphemeralPublicKeyPem: string,
  expectedRPID: string,
  expectedOrigin: string
): Promise<{ verified: boolean; credentialId?: string }> {
  const now = Date.now();
  
  // Invariant 1: Single-use check and TTL validation
  if (context.consumed || now - context.issuedAtMs > HYBRID_TTL_MS) {
    throw new Error('HYBRID_SESSION_EXPIRED_OR_REPLAYED');
  }
  context.consumed = true; // Mutate immediately (or atomic DB flag)

  // Invariant 2: Validate ephemeral ECDH public key binding against QR initiation
  const peerKey = crypto.createPublicKey(peerEphemeralPublicKeyPem);
  const peerKeyDer = peerKey.export({ type: 'spki', format: 'der' });
  const calculatedPeerHash = crypto.createHash('sha256').update(peerKeyDer).digest();

  if (!crypto.timingSafeEqual(context.expectedPeerPublicKeyHash, calculatedPeerHash)) {
    throw new Error('BLE_PROXIMITY_KEY_MISMATCH');
  }

  // Invariant 3: Derive CTAP 2.2 shared secret and assert clientDataJSON channel binding
  const sharedSecret = crypto.diffieHellman({
    privateKey: context.ephemeralPrivateKey,
    publicKey: peerKey,
  });
  const expectedChannelBinding = crypto.createHmac('sha256', sharedSecret)
    .update(Buffer.from('CTAP2_2_HYBRID_BINDING'))
    .digest('base64url');

  const clientData = JSON.parse(Buffer.from(response.response.clientDataJSON, 'base64url').toString('utf8'));
  
  if (typeof clientData.crossDeviceBinding !== 'string' ||
      !crypto.timingSafeEqual(
        Buffer.from(clientData.crossDeviceBinding),
        Buffer.from(expectedChannelBinding)
      )) {
    throw new Error('CTAP22_CHANNEL_BINDING_VERIFICATION_FAILED');
  }

  // Invariant 4: Standard WebAuthn signature verification
  const verification = await verifyAuthenticationResponse({
    response,
    expectedChallenge: clientData.challenge,
    expectedOrigin,
    expectedRPID,
    authenticator: {
      credentialID: response.rawId,
      credentialPublicKey: Buffer.from(response.id, 'base64url'),
      counter: 0,
    },
  });

  return {
    verified: verification.verified,
    credentialId: verification.authenticationInfo?.credentialID
  };
}
```

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 CTAP 2.2 Cross-Device Ephemeral ECDH Proximity Binding Guardrail

WebAuthn CTAP 2.2 Cross-Device Ephemeral ECDH Proximity Binding Guardrail defines an industrial-grade behavioral standard for security engineering. Enforces strict validation and cryptographic tying of WebAuthn hybrid cross-device transport (caBLE/FIDO CTAP 2.2) authentication assertions to ephemeral ECDH-derived session channels. Precludes QR-phishing, adversarial session interception, and cross-device session bleeding by mandating constant-time verification of the clientDataJSON hash, ephemeral authenticator public key derivation, and Bluetooth Low Energy (BLE) proximity routing commitments before issuing server-side user sessions. 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: Accepting Cross-Device Hybrid WebAuthn Assertions Without Enforcing Ephemeral ECDH Channel Tying and BLE Proximity Commitments 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 DriftAccepting Cross-Device Hybrid WebAuthn Assertions Without Enforcing Ephemeral ECDH Channel Tying and BLE Proximity CommitmentsCritical
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 cryptographically bind the WebAuthn challenge to an ephemeral ECDH keypair generated exclusively for the single-use QR hybrid session.

Engineers MUST ALWAYS cryptographically bind the WebAuthn challenge to an ephemeral ECDH keypair generated exclusively for the single-use QR hybrid session.

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 the authenticator's clientDataJSON contains the exact unhashed cross-device channel binding parameter matching the server's ephemeral public key.

Engineers MUST verify that the authenticator's clientDataJSON contains the exact unhashed cross-device channel binding parameter matching the server's ephemeral public key.

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 persist or reuse hybrid ephemeral ECDH session tokens across authentication flows, enforcing a hard TTL (strictly <= 120 seconds).

Engineers MUST NOT persist or reuse hybrid ephemeral ECDH session tokens across authentication flows, enforcing a hard TTL (strictly <= 120 seconds).

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 BLE proximity validation by asserting the presence and cryptographic validity of the routing secret and tunnel symmetric key negotiated during the CTAP 2.2 handshake.

Services MUST enforce BLE proximity validation by asserting the presence and cryptographic validity of the routing secret and tunnel symmetric key negotiated during the CTAP 2.2 handshake.

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

Services MUST immediately invalidate the ephemeral session handle upon any signature verification failure or upon first successful issuance of the primary session token to prevent replay attacks.

Services MUST immediately invalidate the ephemeral session handle upon any signature verification failure or upon first successful issuance of the primary session token to prevent replay attacks.

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

Components NEVER accept fallback assertions from non-BLE transports when the user initiation was flagged as cross-device hybrid authentication.

Components NEVER accept fallback assertions from non-BLE transports when the user initiation was flagged as cross-device hybrid 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 WebAuthn CTAP 2.2 Cross-Device Ephemeral ECDH Proximity Binding Guardrail critical for AI coding assistants?

Enforces strict validation and cryptographic tying of WebAuthn hybrid cross-device transport (caBLE/FIDO CTAP 2.2) authentication assertions to ephemeral ECDH-derived session channels. Precludes QR-phishing, adversarial session interception, and cross-device session bleeding by mandating constant-time verification of the clientDataJSON hash, ephemeral authenticator public key derivation, and Bluetooth Low Energy (BLE) proximity routing commitments before issuing server-side user sessions. 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 (Accepting Cross-Device Hybrid WebAuthn Assertions Without Enforcing Ephemeral ECDH Channel Tying and BLE Proximity Commitments) 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