Active
Project:
Two-factor Authentication (TFA)
Version:
2.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
20 Jan 2023 at 12:59 UTC
Updated:
18 Aug 2023 at 22:13 UTC
Jump to comment: Most recent
Comments
Comment #2
gregglesCan you provide more "steps to repeat" this bug? How did you get Encrypt into a state where it's throwing the exception?
i guess TFA should catch the exception and display a reasonable error message.
Updating title to match.
For sites affected by this, I suggest fixing whatever is making encrypt broken?
Comment #3
michel.g commentedIn my case the exception was thrown because we still HTTP authentication enabled on our website (hence the authenticator not being able to communicate with our test website)
Regardless I guess we could take inspiration from this patch for 2.x
https://git.drupalcode.org/project/tfa/-/merge_requests/17/diffs
In which we catch the exceptions and return FALSE, with the difference where we should properly log those exceptions in the Drupal log.
Comment #4
gregglesIf there was an exception and a 500 error there should be an error either displayed to the page or in watchdog or in the apache or php error log. Can you find those errors and copy and paste them here?
Comment #5
cmlaraThis is indeed a legitimate fault that we have.
An example workflow that could cause this in 1.x is TfaTotpValidation::ready()->TfaTotpValidation::getSeed()->tfaBasePlugin::Decrypt($data) which can throw \Drupal\encrypt\Exception\EncryptionMethodCanNotDecryptException or \Drupal\encrypt\Exception\EncryptException. Similar path exists in the HOTP plugin.
Real AES is known to throw this when its key is misconfiguration in some manner, however it could be any sort of issue from any of the various encryption engines, including network faults to remote systems.
We call ready() when a user logs in to check if they have a token configured, we have no provision in our API for raising an exception, and at the same time we also can not just return FALSE from the ready() method when an exception occurs as that could allow an access bypass. Returning true() would also pose issues.
Yes fixing the root fault in Real AES is the correct solution to solve however that doesn't really absolve us of our obligation to handle exceptions.
Realistically anything that calls tfaBasePlugin::Decrypt() needs to expect a failure to occur, the big question is how we present this. WSOD's and Raised Exceptions at least prevent a login from occurring, but its not the most user friendly presentation.
Moving this to 2.x, this could involve API changes.
Comment #6
ambient.impactAs a related aside (I skimmed some of this so apologies if you already addressed this) but I noticed the code referenced in the diff in #3 has this:
which is found in
src/Plugin/Tfa/TfaHotp.php. I was trying to set up TFA on a site where I hadn't provided the key to the Encrypt module and couldn't figure out why TFA wasn't working until I dug into the code and found thatcatch (EncryptException $e) {is doing nothing with the exception that would have told me what the problem was (I did adpm()call to the Devel module there to eventually figure it out). I feel like that needs to be addressed as part of this or a related issue as well.