RTC Unit/System Tests PR-5.4-dev 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.

avatar arib06 arib06 - change - 11 Aug 2026
Labels Added: Unit/System Tests PR-5.4-dev
avatar rvbgnu
rvbgnu - comment - 21 Aug 2026

I cannot reproduce the issue. On each Login form , both front end and back end,

  • I have the 6 digit code request on a separate page: is it the expected behaviour (I quikcly checked the settings to force having all 3 login fields on the same page, but not found the settings)
  • Each time the "Please match the requested format" tooltip appears, preventing me to enter more than 5 digit after the "+" string
Screenshot 2026-08-21 at 14-10-35 Joomla 5 4 Test Site - Administration Screenshot 2026-08-21 at 14-09-46 Home Screenshot 2026-08-21 at 13-54-04 Multi-factor Authentication - Joomla 5 4 Test Site - Administration
avatar rvbgnu
rvbgnu - comment - 21 Aug 2026

I cannot reproduce the issue. On each Login form , both front end and back end,

  • I have the 6 digit code request on a separate page: is it the expected behaviour ?? (I quikcly checked the settings to force having all 3 login fields on the same page, but not found the settings)
  • Each time the "Please match the requested format" tooltip appears, preventing me to enter more than 5 digit after the "+" string
Screenshot 2026-08-21 at 14-10-35 Joomla 5 4 Test Site - Administration Screenshot 2026-08-21 at 14-09-46 Home Screenshot 2026-08-21 at 13-54-04 Multi-factor Authentication - Joomla 5 4 Test Site - Administration
avatar arib06
arib06 - comment - 21 Aug 2026

Thanks for testing. The separate code page is the captive login step, that's expected.

The reason the browser won't let you submit +123456 is that the code field carries pattern="[0-9]{6}" and maxlength="6" (the input_attributes in the totp plugin), so HTML5 validation blocks it before anything is sent. That check is client-side only though, and it isn't what the server relies on. Remove those two attributes in devtools, or post the login/setup request directly, and the raw value reaches the server. On the current code checkCode() compares with a loose == against a zero-padded numeric string, so +123456, 123456, 0012345 and similar juggle equal and are accepted. With the patch only the exact code passes.

If it's easier to see without a browser, the unit test in the PR covers it: testCheckCodeRejectsTypeJuggledPasscode fails on the old == and passes with hash_equals.

avatar dautrich dautrich - test_item - 21 Aug 2026 - Tested successfully
avatar dautrich
dautrich - comment - 21 Aug 2026

I have tested this item ✅ successfully on a797ac0

At first, I was not able to reproduce the issue. But following @arib06 comment, I removed some checks from the page's HTML code. After that, the issue could be reproduced, and I was able to successfully complete the MFA login with a seven-digit code like ' nnnnnn' or '+nnnnnn'.
After applying the patch, I did the identical manipulation to the page's HTML code, but the previously successful entries didn't work anymore.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/48056.

avatar dautrich
dautrich - comment - 21 Aug 2026

I have tested this item ✅ successfully on a797ac0

At first, I was not able to reproduce the issue. But following @arib06 comment, I removed some checks from the page's HTML code. After that, the issue could be reproduced, and I was able to successfully complete the MFA login with a seven-digit code like ' nnnnnn' or '+nnnnnn'.
After applying the patch, I did the identical manipulation to the page's HTML code, but the previously successful entries didn't work anymore.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/48056.

avatar dautrich
dautrich - comment - 21 Aug 2026

I have tested this item ✅ successfully on a797ac0

At first, I was not able to reproduce the issue. But following @arib06's comment, I removed some checks from the page's HTML code. After that, the issue could be reproduced, and I was able to successfully complete the MFA login with a seven-digit code like ' nnnnnn' or '+nnnnnn'.
After applying the patch, I did the identical manipulation to the page's HTML code, but the previously successful entries didn't work anymore.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/48056.

avatar richard67 richard67 - change - 21 Aug 2026
Labels Added: PBF
avatar richard67 richard67 - alter_testresult - 21 Aug 2026 - dautrich: Tested successfully
avatar rbuelund rbuelund - test_item - 22 Aug 2026 - Tested successfully
avatar rbuelund
rbuelund - comment - 22 Aug 2026

I have tested this item ✅ successfully on d36ba75


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/48056.

avatar rbuelund
rbuelund - comment - 22 Aug 2026

I have tested this item ✅ successfully on d36ba75


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/48056.

avatar alikon alikon - change - 22 Aug 2026
The description was changed
Status Pending ⇒ Ready to Commit
avatar alikon
alikon - comment - 22 Aug 2026

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/48056.

avatar alikon
alikon - comment - 22 Aug 2026

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/48056.

avatar muhme muhme - change - 28 Aug 2026
The description was changed
Labels Added: RTC
Removed: PBF
avatar muhme
muhme - comment - 28 Aug 2026

✅ Final test before merge with JBT and macOS Safari

  • Created user and set up Two-Factor login with Google authenticator verification code
  • Before every test, deleted pattern="[0-9]{6}" maxlength="6" in HTML code
  • Seen before PR:
    • Two-Factor login using a space, a '+' or a '0' before the 6-digit verification code also works
  • Applied PR with Patch Tester:
    • Two-Factor login with correct 6-digit verification code works
    • Logging in with an extra space at the start, a ‘+’ or a ‘0’ fails
    • Login with a leading '0' in the 6-digit number is working
    • The number of unit tests was increased from 1,134 to 1,136 and was manually run twice, both times successfully
    • No unusual Joomla or PHP log messages
avatar muhme muhme - change - 28 Aug 2026
Status Ready to Commit ⇒ Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 ⇒ 2026-08-28 06:58:05
Closed_By ⇒ muhme
avatar muhme muhme - close - 28 Aug 2026
avatar muhme muhme - merge - 28 Aug 2026
avatar muhme
muhme - comment - 28 Aug 2026

Thank you very much @arib06 for your first-time contribution. Thank you @brianteeman for your support. Thanks to @rvbgnu, @dautrich and @rbuelund for testing.

Add a Comment

Login with GitHub to post a comment