silverstripe / silverstripe-mfa

MultiFactor Authentication for Silverstripe CMS
BSD 3-Clause "New" or "Revised" License
11 stars 25 forks source link

Incorrect creation date shown for recovery codes #571

Open gavynj opened 2 weeks ago

gavynj commented 2 weeks ago

Module version(s) affected

5.2.4

Description

When viewing a member, at the bottom of their member screen on the backend it says whether they have MFA setup and when their recovery codes were created. However, for any user that has MFA setup, the recovery codes created date always shows as today.

Screenshot 2024-10-18 at 9 48 36 AM

For the above example, the date in the database was 25th May 2024.

How to reproduce

Possible Solution

There are two things wrong with this section in the admin.

Firstly, there is a typo which is why the date is always the current date.

Line 61 of src/FormField/RegisteredMFAMethodListField.php

'backupCreationDate' => $this->getBackupMethod()

backupCreationDate should be backupCreatedDate, as that is what the frontend code is expecting. This is causing the date to always show the current date.

Secondly, even when that is fixed, the backup method of the currently logged in user is being shown, not the user you are viewing.

Line 78 of src/FormField/RegisteredMFAMethodListField.php shows Security::getCurrentUser() being used whenever getBackupMethod() is called.

protected function getBackupMethod(): ?RegisteredMethod
{
     $backupMethod = MethodRegistry::singleton()->getBackupMethod();
     return RegisteredMethodManager::singleton()->getFromMember(Security::getCurrentUser(), $backupMethod);
}

I have a working solution here: https://github.com/gavynj/silverstripe-mfa/commit/fbc9369b2ce7756a7dfbaf2474e2f1ecb6c7b54b#diff-84c429bec93f6d0c4a4cdd55997e8d496dc14b3cf61d27e0a7aad8325ed12638R61

Additional Context

No response

Validations

PRs