Add reset MFA button for admin s on user profile edit #6056

Manually merged
clauvaldez merged 1 commit from clauvaldez/mfaReset into development 2026-05-17 14:06:43 +02:00
clauvaldez commented 2026-03-11 16:35:55 +01:00 (Migrated from github.com)

Summary

This pull request adds a Reset MFA button to the user profile edit page, allowing administrators to easily reset a user's multi-factor authentication configuration.

Motivation

If a user loses access to their MFA device or is unable to complete the authentication process, administrators currently have no quick way to reset MFA from the interface. This feature provides a simple and controlled way for admins to resolve such situations.

Changes

  • Added a Reset MFA button in the user profile edit view.
  • Implemented a controller method to handle MFA reset for the selected user.
  • Restricted the action to users with the appropriate UsersManage permission.
  • The reset operation removes the user's stored MFA values, forcing them to reconfigure MFA on next login.

Security

Only administrators with the UsersManage permission can perform this action.

Result

Administrators can quickly reset MFA for users who are locked out due to lost or misconfigured authentication devices, improving support and account recovery workflows.

### Summary This pull request adds a **Reset MFA button** to the user profile edit page, allowing administrators to easily reset a user's multi-factor authentication configuration. ### Motivation If a user loses access to their MFA device or is unable to complete the authentication process, administrators currently have no quick way to reset MFA from the interface. This feature provides a simple and controlled way for admins to resolve such situations. ### Changes - Added a **Reset MFA** button in the user profile edit view. - Implemented a controller method to handle MFA reset for the selected user. - Restricted the action to users with the appropriate **UsersManage permission**. - The reset operation removes the user's stored MFA values, forcing them to reconfigure MFA on next login. ### Security Only administrators with the `UsersManage` permission can perform this action. ### Result Administrators can quickly reset MFA for users who are locked out due to lost or misconfigured authentication devices, improving support and account recovery workflows.
ssddanbrown (Migrated from github.com) requested changes 2026-04-19 12:51:49 +02:00
ssddanbrown (Migrated from github.com) left a comment

Thanks for offering this!
I've added a range of comments regarding some changes to be made.
We will also need testing coverage of the core actions here. If unsure, I can add these later.

Note: If you're heavily using AI/LLM generation for this contribution please let me know, as I don't want to be spending time reviewing and providing feedback to a machine via a proxy.

If anything is unclear or you need further guidance just let me know!

Thanks for offering this! I've added a range of comments regarding some changes to be made. We will also need [testing coverage](https://github.com/BookStackApp/BookStack/blob/development/dev/docs/php-testing.md) of the core actions here. If unsure, I can add these later. Note: If you're heavily using AI/LLM generation for this contribution please let me know, as I don't want to be spending time reviewing and providing feedback to a machine via a proxy. If anything is unclear or you need further guidance just let me know!
@ -211,0 +216,4 @@
{
$this->checkPermission(Permission::UsersManage);
$user = $this->userRepo->getById($id);
// Resetear el 2FA del usuario
ssddanbrown (Migrated from github.com) commented 2026-04-19 12:32:59 +02:00

Remove this comment, I think it's a bit redundant based on context and I'd prefer to keep comments in one language.

Remove this comment, I think it's a bit redundant based on context and I'd prefer to keep comments in one language.
danb marked this conversation as resolved
@ -211,0 +218,4 @@
$user = $this->userRepo->getById($id);
// Resetear el 2FA del usuario
$user->mfaValues()->delete();
session()->flash('success', trans('settings.users_mfa_reset_success', ['userName' => $user->name]));
ssddanbrown (Migrated from github.com) commented 2026-04-19 12:32:25 +02:00

Please can you use the $this->showSuccessNotification method instead to show a notification

Please can you use the `$this->showSuccessNotification` method instead to show a notification
danb marked this conversation as resolved
@ -211,0 +219,4 @@
// Resetear el 2FA del usuario
$user->mfaValues()->delete();
session()->flash('success', trans('settings.users_mfa_reset_success', ['userName' => $user->name]));
return redirect()->back();
ssddanbrown (Migrated from github.com) commented 2026-04-19 12:42:20 +02:00

Can we redirect directly to the user edit view?
Redirect backs like this can go wonky in a range of scenarios, so best to specify a location where known.

Can we redirect directly to the user edit view? Redirect backs like this can go wonky in a range of scenarios, so best to specify a location where known.
danb marked this conversation as resolved
@ -264,2 +264,4 @@
'users_mfa_x_methods' => ':count method configured|:count methods configured',
'users_mfa_configure' => 'Configure Methods',
'users_mfa_reset' => 'Reset 2FA',
'users_mfa_reset_desc' => 'Reset and clear all configured MFA methods for :userName. They will be prompted to reconfigure on next login.',
ssddanbrown (Migrated from github.com) commented 2026-04-19 12:40:12 +02:00

This is kind of incorrect. They will only be prompted to reconfigure on login if MFA is required for their role.

This is kind of incorrect. They will only be prompted to reconfigure on login **_if_** MFA is required for their role.
danb marked this conversation as resolved
@ -266,0 +267,4 @@
'users_mfa_reset_desc' => 'Reset and clear all configured MFA methods for :userName. They will be prompted to reconfigure on next login.',
'users_mfa_reset_confirm' => 'Are you sure you want to reset 2FA for :userName?',
'users_mfa_reset_success' => '2FA has been reset for :userName',
'users_mfa_reset_error' => 'Failed to reset 2FA for :userName',
ssddanbrown (Migrated from github.com) commented 2026-04-19 12:34:55 +02:00

Please can you use "multi-factor authentication" instead of "2FA" to keep the language used consistent in the app.

Also, avoid passing through the username here. We only do that where necessary, to keep translations simpler and avoid other issues, but it can be implied by context here so I don't think it's needed.

Please can you use "multi-factor authentication" instead of "2FA" to keep the language used consistent in the app. Also, avoid passing through the username here. We only do that where necessary, to keep translations simpler and avoid other issues, but it can be implied by context here so I don't think it's needed.
danb marked this conversation as resolved
@ -71,6 +71,26 @@
</div>
</div>
@if(user()->hasSystemRole('admin'))
ssddanbrown (Migrated from github.com) commented 2026-04-19 12:38:48 +02:00

This does not align with the actual permission used in the controller, and we're already checking the relevant permissions before providing the view, so a permission check here is redundant.

Instead, We should probably only show this section if the user has at least one MFA option configured.

This does not align with the actual permission used in the controller, and we're already checking the relevant permissions before providing the view, so a permission check here is redundant. Instead, We should probably only show this section if the user has at least one MFA option configured.
danb marked this conversation as resolved
@ -74,0 +83,4 @@
<form action="{{ url("/settings/users/{$user->id}/reset-mfa") }}" method="POST" style="display: inline;">
@csrf
<button type="submit" class="button neg"
onclick="return confirm('{{ trans('settings.users_mfa_reset_confirm', ['userName' => $user->name]) }}')">
ssddanbrown (Migrated from github.com) commented 2026-04-19 12:48:13 +02:00

This won't work due to CSP (security) blocking. We avoid any inline JavaScript.

Making the initial a dropdown, with a second button for confirmation, may be better. We do this in a select few other areas I think.

This won't work due to CSP (security) blocking. We avoid any inline JavaScript. Making the initial a dropdown, with a second button for confirmation, may be better. We do this in a select few other areas I think.
danb marked this conversation as resolved
clauvaldez commented 2026-04-20 14:55:38 +02:00 (Migrated from github.com)

Hello!
Thanks for the answers, I am working on the recommendations, it is the first time I make a contribution so there are many details to take into account.
Thank you very much for taking the time, I will work on the details you mentioned and

Hello! Thanks for the answers, I am working on the recommendations, it is the first time I make a contribution so there are many details to take into account. Thank you very much for taking the time, I will work on the details you mentioned and
danb manually merged commit 321271e7bd into development 2026-05-17 14:06:43 +02:00
danb deleted branch clauvaldez/mfaReset 2026-05-17 14:07:11 +02:00
Owner

I wanted to get this into the next release so have gone ahead and made the changes needed within 39a14cff8f, before merging.

Thanks again clauvaldez for providing this PR.

I wanted to get this into the next release so have gone ahead and made the changes needed within 39a14cff8f64f51fa3b4be2f4c2a7b85d7c2b600, before merging. Thanks again clauvaldez for providing this PR.
Sign in to join this conversation.
No reviewers
No milestone
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bookstack/bookstack!6056
No description provided.