Skip to content

v3.81.2: Fix two-factor login rejecting every code; restyle challenge page - #23

Merged
agit8or1 merged 1 commit into
mainfrom
fix/3.81.2-2fa-login
Nov 12, 2026
Merged

agit8or1 merged 1 commit into
mainfrom
fix/3.81.2-2fa-login

Conversation

@agit8or1

Copy link
Copy Markdown
Owner

Problem

twofactor_setup.php stores the TOTP secret as hex (bin2hex(random_bytes(16))) and hands the authenticator app the base32 encoding of those bytes. verify2fa.php passed the stored hex to TwoFactorAuth::verify(), which base32-decodes its input. That gave a different key, so enrolment succeeded and every login code afterwards was rejected.

Changes

  • TwoFactorAuth::verifyStored() hex-decodes the stored secret (anything that isn't hex is still treated as base32). verify2fa.php now uses it.
  • The challenge page is now a standalone page that matches the login screen: theme toggle, large code field, autocomplete="one-time-code", back-to-sign-in link.
  • The login styles moved to assets/css/auth.css, which login.php and verify2fa.php now share.
  • Version bumped to 3.81.2 and changelog entry added.

Testing

  • tests/twofactor_test.php 16/16 and tests/mfa_requirement_test.php 13/13, run against opnsense_fw_test.
  • Generated a code the way an authenticator does (raw secret bytes) and checked it: verifyStored() accepts it, the old verify() rejects it.
  • Already deployed to production: the login page and auth.css return 200, and verify2fa.php redirects (302) when there's no pending session.

🤖 Generated with Claude Code

… page

twofactor_setup.php stores the TOTP secret as hex, but verify2fa.php
passed it to TwoFactorAuth::verify(), which base32-decodes its input.
Decoding hex as base32 yields the wrong key, so enrolment succeeded and
every login code was then rejected. Add TwoFactorAuth::verifyStored(),
which decodes the stored hex, and use it at login.

The challenge page now matches the login screen instead of rendering
inside the app layout. Login styles move to assets/css/auth.css, shared
by both pages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@agit8or1
agit8or1 merged commit e72928b into main Nov 12, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants