Skip to content

Conversation

zmstone
Copy link
Member

@zmstone zmstone commented Jan 20, 2025

Fixes EMQX-13509

Release version: v/e5.9.0

Summary

See emqx_dashboard/README.md

PR Checklist

Please convert it to a draft if any of the following conditions are not met. Reviewers may skip over until all the items are checked:

  • Added tests for the changes
  • Change log has been added to changes/(ce|ee)/(feat|perf|fix|breaking)-<PR-id>.en.md files
  • For internal contributor: there is a jira ticket to track this change
  • Created PR to emqx-docs if documentation update is required, or link to a follow-up jira ticket
  • Schema changes are backward compatible

@zmstone zmstone force-pushed the 241118-totp branch 3 times, most recently from 17ba842 to 9a334c0 Compare January 21, 2025 08:41
@zmstone zmstone marked this pull request as ready for review January 21, 2025 20:27
@zmstone zmstone requested review from JimMoen, lafirest and a team as code owners January 21, 2025 20:27
@zmstone zmstone changed the title 2FA using TOTP for Enterprise edition dashboard Authenticator App (TOTP 2FA) for Enterprise edition dashboard Jan 22, 2025
Comment on lines 171 to 172
%% try to login with good TOTP but bad password
%% this should mark the TOTP setup complete,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be side-effects if the provided password is wrong? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TOTP secret is only provided when password was once correct.
The second login attempt providing a valid TOTP code indicates that the authenticator app is set up.
Otherwise the user will get presented with the QR code again.

thalesmg
thalesmg previously approved these changes Feb 5, 2025
thalesmg
thalesmg previously approved these changes Feb 5, 2025
Comment on lines +514 to +516
IsPwdOk = (ok =:= verify_hash(Password, PwdHash)),
MfaVerifyResult = verify_mfa_token(Username, MfaToken, IsPwdOk),
check_mfa_pwd(MfaVerifyResult, IsPwdOk, User);
Copy link
Contributor

@thalesmg thalesmg Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we shouldn't even do anything further once we establish that the password is incorrect.

i.e.:

Suggested change
IsPwdOk = (ok =:= verify_hash(Password, PwdHash)),
MfaVerifyResult = verify_mfa_token(Username, MfaToken, IsPwdOk),
check_mfa_pwd(MfaVerifyResult, IsPwdOk, User);
maybe
true ?= (ok =:= verify_hash(Password, PwdHash)) orelse {error, <<"password_error">>},
MfaVerifyResult = verify_mfa_token(Username, MfaToken),
check_mfa_pwd(MfaVerifyResult, User)
end;

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For TOTP, we can (and should) return token error over password error.
Otherwise a brute-force attacker can send any token to guess the password like without MFA.

For other mechanisms which costs to send the token (e.g. email / SMS, if we will need to implement), password needs to be checked before token.

@zmstone zmstone merged commit 5b84488 into master Feb 7, 2025
202 checks passed
@zmstone zmstone deleted the 241118-totp branch February 7, 2025 07:53
@emqxqa
Copy link

emqxqa commented Mar 31, 2025

TestExecution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants