Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: when changing email with email based 2FA enabled, fail fast #19831

Merged
merged 5 commits into from
Feb 3, 2025

Conversation

netroms
Copy link
Contributor

@netroms netroms commented Jan 31, 2025

Summary

Throw an exception if a user with email-based 2FA enabled attempts to change their email address.
The user must be forced to disable their 2FA, before they can change their email address.
If this is not enforced, the consequence will be that the user no longer has a verified email, since the 2FA code only will be sent to a verified email address, the user will not be able to log in.

Automatic tests

  • TwoFactorControllerTest

Manual test steps:

  1. Enable email 2FA on a user
    1.1 Configure dhis.conf, set login.security.email_2fa.enabled = true
    1.2 Set up SMTP/email server in settings.
    1.3 Verify user email (user profile app)
    1.4 Enroll in email 2FA, POST http://localhost:8080/api/2fa/enrollEmail2FA (observe you get an email with a 2fa code)
    1.5 Call endpoint to enable email 2FA, POST http://localhost:8080/api/2fa/enable. (JSON payload: {"code": "THE_CODE_FROM_THE_EMAIL"} )
    1.6 Log out and try log in, observe you get an email with a 2FA code
  2. Try to change the user's email via /me endpoint
  3. Observe you get an error
  4. Try to change the user's email via /user endpoint, as admin
  5. Observe you get an error

Copy link

sonarqubecloud bot commented Feb 2, 2025

@netroms netroms merged commit e0327d8 into master Feb 3, 2025
17 checks passed
@netroms netroms deleted the DHIS2-18912 branch February 3, 2025 08:51
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