Architectural Invariant Design: Strict WebAuthn/FIDO2 Origin Binding, Attestation, and Replay Protection
Strict WebAuthn/FIDO2 Origin Binding, Attestation, and Replay Protection defines an industrial-grade behavioral standard for security engineering. Enforces strict cryptographic verification of WebAuthn and FIDO2 passkey assertions and registrations. Guarantees immutable clientDataJSON origin validation, exact challenge-response replay matching with single-use eviction, RP ID boundary enforcement, and authenticator counter regression checks to defeat reverse-proxy adversary-in-the-middle (AiTM) phishing. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.
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 Mode | AI Symptom (The Anti-Pattern) | Severity | Production Impact & Remedy |
|---|---|---|---|
| AI Hallucination & Deprecation Drift | Trusting Client-Supplied Origins, Non-Atomic Challenges, or Skipping Cryptographic Counter & Origin Verification | 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 Inconsistency | AI 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. |
Step-by-Step Production Directives
Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:
Engineers MUST ALWAYS validate clientDataJSON.origin against an explicit, immutable allowlist of fully qualified origins (protocol, domain, port) configured server-side, never trusting HTTP Request headers (e.g., Host, X-Forwarded-Host).
Engineers MUST ALWAYS validate clientDataJSON.origin against an explicit, immutable allowlist of fully qualified origins (protocol, domain, port) configured server-side, never trusting HTTP Request headers (e.g., Host, X-Forwarded-Host).
Engineers MUST atomically consume and delete the WebAuthn challenge from server-side storage (e.g., Redis session or signed ephemeral cookie) immediately upon receipt to prevent replay attacks.
Engineers MUST atomically consume and delete the WebAuthn challenge from server-side storage (e.g., Redis session or signed ephemeral cookie) immediately upon receipt to prevent replay attacks.
Engineers MUST enforce strict RP ID hashing invariants (SHA-256 of rpId matching authenticatorData.rpIdHash), ensuring rpId conforms to the exact registrable domain of the relying party.
Engineers MUST enforce strict RP ID hashing invariants (SHA-256 of rpId matching authenticatorData.rpIdHash), ensuring rpId conforms to the exact registrable domain of the relying party.
Engineers MUST verify that authenticatorData.flags has the User Present (UP) bit set for all operations, and User Verified (UV) bit set whenever required by authentication policy.
Engineers MUST verify that authenticatorData.flags has the User Present (UP) bit set for all operations, and User Verified (UV) bit set whenever required by authentication policy.
Engineers MUST compare the received signCount against the stored credential counter
Engineers MUST compare the received signCount against the stored credential counter; if received signCount is non-zero and less than or equal to stored signCount, the authenticator MUST be marked as cloned and the session aborted immediately.
Engineers MUST NOT rely on client-side parsing or validation of attestation/assertion objects
Engineers MUST NOT rely on client-side parsing or validation of attestation/assertion objects; cryptographic signatures MUST be verified using canonical public keys (COSE/WebCrypto) on the backend server.
Frequently Asked Technical Questions
Common questions developers face when configuring AI coding assistants for this stack:
Q:Why is Strict WebAuthn/FIDO2 Origin Binding, Attestation, and Replay Protection critical for AI coding assistants?
Enforces strict cryptographic verification of WebAuthn and FIDO2 passkey assertions and registrations. Guarantees immutable clientDataJSON origin validation, exact challenge-response replay matching with single-use eviction, RP ID boundary enforcement, and authenticator counter regression checks to defeat reverse-proxy adversary-in-the-middle (AiTM) phishing. 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 (Trusting Client-Supplied Origins, Non-Atomic Challenges, or Skipping Cryptographic Counter & Origin Verification) 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.