Pending

User tests: Successful: Unsuccessful:

avatar arib06
arib06
8 Jul 2026

Pull Request resolves # .

  • I read the Generative AI policy and my contribution is either not created with the help of AI or is compatible with the policy and GNU/GPL 2 or later.

Summary of Changes

Totp::checkCode() matched the generated one-time passcode against the submitted value with a loose ==. getCode() returns a zero-padded numeric string, so PHP numeric juggling makes non-codes compare equal ("012345" == 12345, "123456" == "+123456", "123456" == " 123456"), and the comparison is not constant time. Switched to hash_equals() with a string cast. The TOTP setup handler read the code with getInt('code'), which drops leading zeros before it ever reaches the check; it now uses getCmd('code'), the same as the email MFA plugin and the captive login path, so the strict comparison keeps working for codes that start with 0. The fixed MFA plugin already uses hash_equals; this aligns the TOTP path with it.

Testing Instructions

  1. Enable the TOTP multi-factor method for a user and complete the Google Authenticator setup.
  2. On the captive login page, enter the current 6-digit code prefixed with a + (for example +123456).

Unit test: tests/Unit/Libraries/Cms/Encrypt/TotpTest.php.

Actual result BEFORE applying this Pull Request

+123456 (and other numeric-juggling variants of the current code) is accepted as a valid code.

Expected result AFTER applying this Pull Request

Only the exact current code is accepted; juggling variants are rejected, and codes with a leading zero still validate.

Link to documentations

Please select:

  • Documentation link for guide.joomla.org:

  • No documentation changes for guide.joomla.org needed

  • Pull Request link for manual.joomla.org:

  • No documentation changes for manual.joomla.org needed

avatar arib06 arib06 - open - 8 Jul 2026
avatar arib06 arib06 - change - 8 Jul 2026
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 8 Jul 2026
Category Libraries Front End Plugins Unit Tests
avatar richard67
richard67 - comment - 8 Jul 2026

@arib06 Do we have to tell you for each of your PRs that you shall check the check box that you have read the AI policy? I did that already for your other PR and have to do the same again now.

avatar richard67 richard67 - change - 8 Jul 2026
Title
use hash_equals for totp code verification
[5.4] Use hash_equals for totp code verification
avatar richard67 richard67 - edited - 8 Jul 2026
avatar arib06 arib06 - change - 9 Jul 2026
The description was changed
avatar arib06 arib06 - edited - 9 Jul 2026
avatar arib06
arib06 - comment - 9 Jul 2026

Sorry about that, ticked the box. Will make sure it's checked on future PRs.

Add a Comment

Login with GitHub to post a comment