This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
securitycritical PriorityID: webauthn-l3-backup-state-device-bound-enforcement

WebAuthn L3 Backup State Assertion & Device-Bound Token Enforcement

Enforces strict discrimination between multi-device synced passkeys and hardware-bound passkeys using WebAuthn Level 3 AuthenticatorData Backup Eligibility (BE) and Backup State (BS) flags. Prevents privilege escalation and session exportability on high-assurance operations (e.g., step-up authentication, cryptographic key authorization, admin actions) by cryptographically guaranteeing credentials cannot leave their initial physical Secure Element or FIPS-validated enclave.

Prohibited Anti-Pattern: Accepting generic WebAuthn credentials for high-assurance actions without validating BE/BS flags, allowing synced passkeys to bypass physical hardware requirements.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: WebAuthn L3 Backup State Assertion & Device-Bound Token Enforcement - Enforces strict discrimination between multi-device synced passkeys and hardware-bound passkeys using WebAuthn Level 3 AuthenticatorData Backup Eligibility (BE) and Backup State (BS) flags. Prevents privilege escalation and session exportability on high-assurance operations (e.g., step-up authentication, cryptographic key authorization, admin actions) by cryptographically guaranteeing credentials cannot leave their initial physical Secure Element or FIPS-validated enclave.
globs: src/auth/**/*.{ts,tsx}, src/security/**/*.{ts,tsx}, src/server/auth/**/*.{ts,tsx}, src/services/webauthn/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/webauthn-l3-backup-state-device-bound-enforcement"
---

# WebAuthn L3 Backup State Assertion & Device-Bound Token Enforcement

> **Severity**: CRITICAL | **Category**: security
> **Anti-Pattern Warning**: Accepting generic WebAuthn credentials for high-assurance actions without validating BE/BS flags, allowing synced passkeys to bypass physical hardware requirements.

## System Constraints
You are a Principal Security Architect specializing in FIDO2/WebAuthn Level 3 specifications. Enforce strict cryptographic validation of AuthenticatorData flags (Backup Eligibility `BE` and Backup State `BS`). Any high-assurance action (tier-1 admin, cryptographic signing, fund transfer, elevated permission assignment) MUST mandate hardware-bound (single-device) credentials by asserting `flags.BE === false` and `flags.BS === false`. Ensure multi-device credentials (synced passkeys) are never allowed into high-assurance execution paths.

## Strict Guidelines
- Engineers MUST ALWAYS inspect AuthenticatorData bit flags at byte offset 32: bit index 3 (mask 0x08) for Backup Eligibility (BE) and bit index 4 (mask 0x10) for Backup State (BS).
- Engineers MUST NOT permit operations flagged with High Assurance (FIPS 140-3, step-up auth, admin console access) to succeed if the WebAuthn credential has `flags.BE === true` or `flags.BS === true`.
- Services MUST record and persist `credentialDeviceType` ('singleDevice' vs 'multiDevice') at registration by checking `BE === 0` (single-device) or `BE === 1` (multi-device).
- Services MUST reject authentication if `flags.BS === true` while `flags.BE === false` as this violates the WebAuthn L3 specification invariant.
- Components NEVER assume `authenticatorAttachment: 'cross-platform'` guarantees a non-synced hardware token; attachment modality does not prevent multi-device ecosystem passkeys from responding over CTAP2/FIDO.

## Bad vs Good Implementations
### WebAuthn L3 AuthData Flag Verification for High-Assurance Endpoints

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: The code blindly verifies the cryptographic signature without checking the WebAuthn L3 BE (Backup Eligibility) or BS (Backup State) flags. A synced multi-device passkey exportable to consumer cloud backends is mistakenly accepted for an elevated action requiring physical tamper-resistant hardware.
```typescript
import { verifyAuthenticationResponse } from '@simplewebauthn/server';

export async function verifyElevatedAction(
  response: any,
  expectedChallenge: string,
  userCredential: { publicKey: Buffer; currentCounter: number }
) {
  // VULNERABLE: Only checks cryptographic signature and user presence
  // Synced passkeys (iCloud Keychain, Google Password Manager) pass this check,
  // violating device-bound security requirements for high-assurance endpoints.
  const verification = await verifyAuthenticationResponse({
    response,
    expectedChallenge,
    expectedOrigin: 'https://admin.enterprise.io',
    expectedRPID: 'enterprise.io',
    authenticator: {
      credentialPublicKey: userCredential.publicKey,
      credentialID: response.id,
      counter: userCredential.currentCounter,
    },
    requireUserVerification: true,
  });

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

  return { success: true };
}
```

#### Production Standard (Correct)
> **Standard**: The code extracts byte 32 of `authenticatorData` and validates the WebAuthn L3 `BE` and `BS` bitmasks. If either is set, the passkey is backed up or eligible for cloud syncing, and the request is rejected with a policy violation error before privileged operations execute.
```typescript
import { verifyAuthenticationResponse, VerifiedAuthenticationResponse } from '@simplewebauthn/server';

// WebAuthn L3 AuthenticatorData Flag Masks
const AUTH_DATA_FLAG_MASK = {
  UP: 0x01, // User Present
  UV: 0x04, // User Verified
  BE: 0x08, // Backup Eligibility (L3)
  BS: 0x10, // Backup State (L3)
} as const;

interface HighAssuranceVerificationResult {
  verified: boolean;
  isDeviceBoundHardware: boolean;
  newCounter: number;
}

export async function verifyHighAssuranceAction(
  response: any,
  expectedChallenge: string,
  userCredential: { publicKey: Buffer; currentCounter: number }
): Promise<HighAssuranceVerificationResult> {
  const verification: VerifiedAuthenticationResponse = await verifyAuthenticationResponse({
    response,
    expectedChallenge,
    expectedOrigin: 'https://admin.enterprise.io',
    expectedRPID: 'enterprise.io',
    authenticator: {
      credentialPublicKey: userCredential.publicKey,
      credentialID: response.id,
      counter: userCredential.currentCounter,
    },
    requireUserVerification: true,
  });

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

  const { authenticatorData } = verification.authenticationInfo;
  // Authenticator data flags byte is located at index 32
  const flagsByte = authenticatorData[32];
  const isBackupEligible = (flagsByte & AUTH_DATA_FLAG_MASK.BE) !== 0;
  const isBackedUp = (flagsByte & AUTH_DATA_FLAG_MASK.BS) !== 0;

  // Invariant Violation Check: A non-backup-eligible key cannot be backed up
  if (!isBackupEligible && isBackedUp) {
    throw new Error('Malformed AuthenticatorData: BS asserted without BE');
  }

  // High-assurance policy enforcement: Reject all multi-device synced passkeys
  if (isBackupEligible || isBackedUp) {
    throw new Error(
      'Security Policy Violation: High-assurance actions require a non-exportable, hardware-bound passkey (BE=0, BS=0). Synced passkeys are rejected.'
    );
  }

  return {
    verified: true,
    isDeviceBoundHardware: true,
    newCounter: verification.authenticationInfo.newCounter,
  };
}
```

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 L3 Backup State Assertion & Device-Bound Token Enforcement

WebAuthn L3 Backup State Assertion & Device-Bound Token Enforcement defines an industrial-grade behavioral standard for security engineering. Enforces strict discrimination between multi-device synced passkeys and hardware-bound passkeys using WebAuthn Level 3 AuthenticatorData Backup Eligibility (BE) and Backup State (BS) flags. Prevents privilege escalation and session exportability on high-assurance operations (e.g., step-up authentication, cryptographic key authorization, admin actions) by cryptographically guaranteeing credentials cannot leave their initial physical Secure Element or FIPS-validated enclave. 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 generic WebAuthn credentials for high-assurance actions without validating BE/BS flags, allowing synced passkeys to bypass physical hardware requirements. 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 generic WebAuthn credentials for high-assurance actions without validating BE/BS flags, allowing synced passkeys to bypass physical hardware requirements.Critical
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 inspect AuthenticatorData bit flags at byte offset 32

Engineers MUST ALWAYS inspect AuthenticatorData bit flags at byte offset 32: bit index 3 (mask 0x08) for Backup Eligibility (BE) and bit index 4 (mask 0x10) for Backup State (BS).

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 permit operations flagged with High Assurance (FIPS 140-3, step-up auth, admin console access) to succeed if the WebAuthn credential has `flags.BE === true` or `flags.BS === true`.

Engineers MUST NOT permit operations flagged with High Assurance (FIPS 140-3, step-up auth, admin console access) to succeed if the WebAuthn credential has `flags.BE === true` or `flags.BS === true`.

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 record and persist `credentialDeviceType` ('singleDevice' vs 'multiDevice') at registration by checking `BE === 0` (single-device) or `BE === 1` (multi-device).

Services MUST record and persist `credentialDeviceType` ('singleDevice' vs 'multiDevice') at registration by checking `BE === 0` (single-device) or `BE === 1` (multi-device).

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 reject authentication if `flags.BS === true` while `flags.BE === false` as this violates the WebAuthn L3 specification invariant.

Services MUST reject authentication if `flags.BS === true` while `flags.BE === false` as this violates the WebAuthn L3 specification invariant.

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 assume `authenticatorAttachment

Components NEVER assume `authenticatorAttachment: 'cross-platform'` guarantees a non-synced hardware token; attachment modality does not prevent multi-device ecosystem passkeys from responding over CTAP2/FIDO.

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 L3 Backup State Assertion & Device-Bound Token Enforcement critical for AI coding assistants?

Enforces strict discrimination between multi-device synced passkeys and hardware-bound passkeys using WebAuthn Level 3 AuthenticatorData Backup Eligibility (BE) and Backup State (BS) flags. Prevents privilege escalation and session exportability on high-assurance operations (e.g., step-up authentication, cryptographic key authorization, admin actions) by cryptographically guaranteeing credentials cannot leave their initial physical Secure Element or FIPS-validated enclave. 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 generic WebAuthn credentials for high-assurance actions without validating BE/BS flags, allowing synced passkeys to bypass physical hardware requirements.) 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