[GH-ISSUE #5216] [Bug]: 2FA Becomes Disabled After Page Refresh #3657

Closed
opened 2026-10-31 20:34:01 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @aLIEz-xue on GitHub (Jun 12, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5216

Describe the bug

After successfully enabling Two-Factor Authentication (2FA), refreshing the page causes the 2FA toggle button to display as disabled. In addition, 2FA is no longer effective and users can log in without OTP verification.

How to reproduce the problem

  1. Install 3x-ui v3.3.0 on Ubuntu 24.04.4 LTS.
  2. Log in using the default administrator account.
  3. Change the default account to a custom username.
  4. Log out and log back in using the new account.
  5. Enable Two-Factor Authentication (2FA) successfully.
  6. Refresh the web interface page.

Expected behavior

No response

Actual behavior

No response

Relevant logs

Jun 12 03:35:35 hostname systemd[1]: Started x-ui.service - x-ui Service.
Jun 12 03:35:35 hostname x-ui[5090]: 2026/06/12 03:35:35 Starting x-ui 3.3.0
Jun 12 03:35:36 hostname /usr/local/x-ui/x-ui[5090]: INFO - Web server running HTTPS on [::]:11111
Jun 12 03:35:36 hostname /usr/local/x-ui/x-ui[5090]: INFO - custom geo startup: no custom geofiles configured
Jun 12 03:35:36 hostname /usr/local/x-ui/x-ui[5090]: INFO - Sub server running HTTPS on [::]:2096
Jun 12 03:35:36 hostname /usr/local/x-ui/x-ui[5090]: INFO - XRAY: infra/conf/serial: Reading config: &{Name:bin/config.json Format:json}
Jun 12 03:35:36 hostname /usr/local/x-ui/x-ui[5090]: WARNING - XRAY: core: Xray 26.6.1 started
Jun 12 03:35:47 hostname /usr/local/x-ui/x-ui[5090]: INFO - kfLy9mzUxl logged in successfully, Ip Address: x.x.x.x
Jun 12 03:35:47 hostname /usr/local/x-ui/x-ui[5090]: INFO - kfLy9mzUxl logged in successfully
Jun 12 03:36:17 hostname /usr/local/x-ui/x-ui[5090]: INFO - username logged in successfully, Ip Address: x.x.x.x
Jun 12 03:36:17 hostname /usr/local/x-ui/x-ui[5090]: INFO - username logged in successfully
Jun 12 03:38:00 hostname /usr/local/x-ui/x-ui[5090]: INFO - Received SIGHUP signal. Restarting servers...
Jun 12 03:38:00 hostname /usr/local/x-ui/x-ui[5090]: INFO - WebSocket hub stopped
Jun 12 03:38:01 hostname /usr/local/x-ui/x-ui[5090]: INFO - Web server running HTTPS on [::]:11111
Jun 12 03:38:01 hostname /usr/local/x-ui/x-ui[5090]: INFO - custom geo startup: no custom geofiles configured
Jun 12 03:38:01 hostname x-ui[5090]: 2026/06/12 03:38:01 Web server restarted successfully.
Jun 12 03:38:01 hostname /usr/local/x-ui/x-ui[5090]: INFO - Sub server running HTTPS on [::]:2096
Jun 12 03:38:01 hostname x-ui[5090]: 2026/06/12 03:38:01 Sub server restarted successfully.
Jun 12 03:38:08 hostname /usr/local/x-ui/x-ui[5090]: INFO - username logged out successfully
Jun 12 03:38:13 hostname /usr/local/x-ui/x-ui[5090]: INFO - username logged in successfully, Ip Address: x.x.x.x
Jun 12 03:38:13 hostname /usr/local/x-ui/x-ui[5090]: INFO - username logged in successfully
Jun 12 03:45:22 hostname x-ui[5090]: 2026/06/12 03:45:22 http: TLS handshake error from x.x.x.x:14927: EOF
Jun 12 03:47:33 hostname x-ui[5090]: 2026/06/12 03:47:33 http: TLS handshake error from x.x.x.x:42304: EOF
Jun 12 03:47:37 hostname x-ui[5090]: 2026/06/12 03:47:37 http: TLS handshake error from x.x.x.x:34039: EOF
Jun 12 03:47:38 hostname x-ui[5090]: 2026/06/12 03:47:38 http: TLS handshake error from x.x.x.x:41935: EOF
Jun 12 03:47:39 hostname x-ui[5090]: 2026/06/12 03:47:39 http: TLS handshake error from x.x.x.x:46752: EOF
Jun 12 03:47:39 hostname x-ui[5090]: 2026/06/12 03:47:39 http: TLS handshake error from x.x.x.x:14285: EOF
Jun 12 03:47:40 hostname x-ui[5090]: 2026/06/12 03:47:40 http: TLS handshake error from x.x.x.x:46857: EOF
Jun 12 03:48:10 hostname x-ui[5090]: 2026/06/12 03:48:10 http: TLS handshake error from x.x.x.x:16402: EOF
Jun 12 03:48:19 hostname /usr/local/x-ui/x-ui[5090]: INFO - Received SIGHUP signal. Restarting servers...
Jun 12 03:48:19 hostname /usr/local/x-ui/x-ui[5090]: INFO - WebSocket hub stopped
Jun 12 03:48:19 hostname /usr/local/x-ui/x-ui[5090]: INFO - Web server running HTTPS on [::]:11111
Jun 12 03:48:19 hostname /usr/local/x-ui/x-ui[5090]: INFO - custom geo startup: no custom geofiles configured
Jun 12 03:48:19 hostname x-ui[5090]: 2026/06/12 03:48:19 Web server restarted successfully.
Jun 12 03:48:19 hostname /usr/local/x-ui/x-ui[5090]: INFO - Sub server running HTTPS on [::]:2096
Jun 12 03:48:19 hostname x-ui[5090]: 2026/06/12 03:48:19 Sub server restarted successfully.
Jun 12 03:48:21 hostname x-ui[5090]: 2026/06/12 03:48:21 http: TLS handshake error from x.x.x.x:57455: EOF
Jun 12 03:48:21 hostname x-ui[5090]: 2026/06/12 03:48:21 http: TLS handshake error from x.x.x.x:41950: EOF
Jun 12 03:48:21 hostname x-ui[5090]: 2026/06/12 03:48:21 http: TLS handshake error from x.x.x.x:48713: EOF
Jun 12 03:48:23 hostname x-ui[5090]: 2026/06/12 03:48:23 http: TLS handshake error from x.x.x.x:11060: EOF

Screenshots

No response

3x-ui version

3.3.0

Xray-core version

No response

How did you install 3x-ui?

install.sh script

Operating system

Ubuntu 24.04.4 LTS

Which parts of the panel are affected?

No response

Browser (only if it is a UI bug)

No response

Is the panel behind a reverse proxy or CDN?

None

Before submitting

  • I searched existing issues and this bug has not been reported.
  • I am running the latest released version of 3x-ui (or have verified the bug still exists on it).
  • This bug report is written in English.
  • I have redacted any sensitive data (tokens, real domains, client UUIDs).
Originally created by @aLIEz-xue on GitHub (Jun 12, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5216 ### Describe the bug After successfully enabling Two-Factor Authentication (2FA), refreshing the page causes the 2FA toggle button to display as disabled. In addition, 2FA is no longer effective and users can log in without OTP verification. ### How to reproduce the problem 1. Install 3x-ui v3.3.0 on Ubuntu 24.04.4 LTS. 2. Log in using the default administrator account. 3. Change the default account to a custom username. 4. Log out and log back in using the new account. 5. Enable Two-Factor Authentication (2FA) successfully. 6. Refresh the web interface page. ### Expected behavior _No response_ ### Actual behavior _No response_ ### Relevant logs ```shell Jun 12 03:35:35 hostname systemd[1]: Started x-ui.service - x-ui Service. Jun 12 03:35:35 hostname x-ui[5090]: 2026/06/12 03:35:35 Starting x-ui 3.3.0 Jun 12 03:35:36 hostname /usr/local/x-ui/x-ui[5090]: INFO - Web server running HTTPS on [::]:11111 Jun 12 03:35:36 hostname /usr/local/x-ui/x-ui[5090]: INFO - custom geo startup: no custom geofiles configured Jun 12 03:35:36 hostname /usr/local/x-ui/x-ui[5090]: INFO - Sub server running HTTPS on [::]:2096 Jun 12 03:35:36 hostname /usr/local/x-ui/x-ui[5090]: INFO - XRAY: infra/conf/serial: Reading config: &{Name:bin/config.json Format:json} Jun 12 03:35:36 hostname /usr/local/x-ui/x-ui[5090]: WARNING - XRAY: core: Xray 26.6.1 started Jun 12 03:35:47 hostname /usr/local/x-ui/x-ui[5090]: INFO - kfLy9mzUxl logged in successfully, Ip Address: x.x.x.x Jun 12 03:35:47 hostname /usr/local/x-ui/x-ui[5090]: INFO - kfLy9mzUxl logged in successfully Jun 12 03:36:17 hostname /usr/local/x-ui/x-ui[5090]: INFO - username logged in successfully, Ip Address: x.x.x.x Jun 12 03:36:17 hostname /usr/local/x-ui/x-ui[5090]: INFO - username logged in successfully Jun 12 03:38:00 hostname /usr/local/x-ui/x-ui[5090]: INFO - Received SIGHUP signal. Restarting servers... Jun 12 03:38:00 hostname /usr/local/x-ui/x-ui[5090]: INFO - WebSocket hub stopped Jun 12 03:38:01 hostname /usr/local/x-ui/x-ui[5090]: INFO - Web server running HTTPS on [::]:11111 Jun 12 03:38:01 hostname /usr/local/x-ui/x-ui[5090]: INFO - custom geo startup: no custom geofiles configured Jun 12 03:38:01 hostname x-ui[5090]: 2026/06/12 03:38:01 Web server restarted successfully. Jun 12 03:38:01 hostname /usr/local/x-ui/x-ui[5090]: INFO - Sub server running HTTPS on [::]:2096 Jun 12 03:38:01 hostname x-ui[5090]: 2026/06/12 03:38:01 Sub server restarted successfully. Jun 12 03:38:08 hostname /usr/local/x-ui/x-ui[5090]: INFO - username logged out successfully Jun 12 03:38:13 hostname /usr/local/x-ui/x-ui[5090]: INFO - username logged in successfully, Ip Address: x.x.x.x Jun 12 03:38:13 hostname /usr/local/x-ui/x-ui[5090]: INFO - username logged in successfully Jun 12 03:45:22 hostname x-ui[5090]: 2026/06/12 03:45:22 http: TLS handshake error from x.x.x.x:14927: EOF Jun 12 03:47:33 hostname x-ui[5090]: 2026/06/12 03:47:33 http: TLS handshake error from x.x.x.x:42304: EOF Jun 12 03:47:37 hostname x-ui[5090]: 2026/06/12 03:47:37 http: TLS handshake error from x.x.x.x:34039: EOF Jun 12 03:47:38 hostname x-ui[5090]: 2026/06/12 03:47:38 http: TLS handshake error from x.x.x.x:41935: EOF Jun 12 03:47:39 hostname x-ui[5090]: 2026/06/12 03:47:39 http: TLS handshake error from x.x.x.x:46752: EOF Jun 12 03:47:39 hostname x-ui[5090]: 2026/06/12 03:47:39 http: TLS handshake error from x.x.x.x:14285: EOF Jun 12 03:47:40 hostname x-ui[5090]: 2026/06/12 03:47:40 http: TLS handshake error from x.x.x.x:46857: EOF Jun 12 03:48:10 hostname x-ui[5090]: 2026/06/12 03:48:10 http: TLS handshake error from x.x.x.x:16402: EOF Jun 12 03:48:19 hostname /usr/local/x-ui/x-ui[5090]: INFO - Received SIGHUP signal. Restarting servers... Jun 12 03:48:19 hostname /usr/local/x-ui/x-ui[5090]: INFO - WebSocket hub stopped Jun 12 03:48:19 hostname /usr/local/x-ui/x-ui[5090]: INFO - Web server running HTTPS on [::]:11111 Jun 12 03:48:19 hostname /usr/local/x-ui/x-ui[5090]: INFO - custom geo startup: no custom geofiles configured Jun 12 03:48:19 hostname x-ui[5090]: 2026/06/12 03:48:19 Web server restarted successfully. Jun 12 03:48:19 hostname /usr/local/x-ui/x-ui[5090]: INFO - Sub server running HTTPS on [::]:2096 Jun 12 03:48:19 hostname x-ui[5090]: 2026/06/12 03:48:19 Sub server restarted successfully. Jun 12 03:48:21 hostname x-ui[5090]: 2026/06/12 03:48:21 http: TLS handshake error from x.x.x.x:57455: EOF Jun 12 03:48:21 hostname x-ui[5090]: 2026/06/12 03:48:21 http: TLS handshake error from x.x.x.x:41950: EOF Jun 12 03:48:21 hostname x-ui[5090]: 2026/06/12 03:48:21 http: TLS handshake error from x.x.x.x:48713: EOF Jun 12 03:48:23 hostname x-ui[5090]: 2026/06/12 03:48:23 http: TLS handshake error from x.x.x.x:11060: EOF ``` ### Screenshots _No response_ ### 3x-ui version 3.3.0 ### Xray-core version _No response_ ### How did you install 3x-ui? install.sh script ### Operating system Ubuntu 24.04.4 LTS ### Which parts of the panel are affected? _No response_ ### Browser (only if it is a UI bug) _No response_ ### Is the panel behind a reverse proxy or CDN? None ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this bug has not been reported. - [x] I am running the latest released version of 3x-ui (or have verified the bug still exists on it). - [x] This bug report is written in English. - [x] I have redacted any sensitive data (tokens, real domains, client UUIDs).
bsakaguchi 2026-10-31 20:34:01 +07:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@github-actions[bot] commented on GitHub (Jun 12, 2026):

The reported behavior is caused by two distinct bugs. The steps in this issue trigger the first one; the second is a related latent issue worth noting.


Bug 1 — 2FA toggle does not auto-save (root cause of this report)

Confirmed in frontend/src/pages/settings/SecurityTab.tsx and frontend/src/api/queries/useAllSettings.ts.

When the 2FA toggle is clicked, toggleTwoFactor() generates a TOTP secret locally, opens the confirmation modal, and — after the user scans the QR code and enters a correct code — calls:

updateSetting({ twoFactorToken: newToken, twoFactorEnable: true });

updateSetting updates only the in-memory React draft. The change is not sent to the backend until the user explicitly clicks the Save button at the top of the Settings page (the same button used to persist port, base path, Telegram settings, etc.). A page refresh before that click discards the unsaved draft, re-fetches server state (POST /panel/api/setting/all), and restores twoFactorEnable: false — which is also why logging in without OTP continues to work, because the backend setting was never changed.

The success toast that appears after the modal is confirmed ("Two-factor authentication has been enabled") fires before the network save, making it appear that the operation is complete.

Workaround (immediate): after confirming the TOTP modal, scroll to the top of the Settings page and click Save before navigating away or refreshing.


Bug 2 — Changing credentials via the web UI silently disables 2FA

Confirmed in internal/web/service/panel/user.go, UpdateUser(), lines 122–130:

twoFactorEnable, err := s.settingService.GetTwoFactorEnable()
...
if twoFactorEnable {
    s.settingService.SetTwoFactorEnable(false)
    s.settingService.SetTwoFactorToken("")
}

Any call to the /panel/api/setting/updateUser endpoint (Settings → Security → Admin credentials form) unconditionally clears twoFactorEnable and twoFactorToken in the database if 2FA is currently enabled. This did not trigger in the steps above because the credential change (step 3) occurred before 2FA was enabled (step 5). However, a user who enables and saves 2FA and then later changes their username or password will have 2FA silently erased on the next credential update. A closely related variant of this bug (in the x-ui.sh CLI reset path) was fixed in #4758.


To confirm which bug applies to your situation: after going through steps 1–5 exactly as described, check whether you clicked the Save button in the header before refreshing. If you did not, Bug 1 is the cause. If you did click Save, please share the panel's response (success toast or error) at that point, as that would indicate a different code path.

This reply was generated automatically; a maintainer may follow up.

<!-- gh-comment-id:4687346834 --> @github-actions[bot] commented on GitHub (Jun 12, 2026): The reported behavior is caused by two distinct bugs. The steps in this issue trigger the first one; the second is a related latent issue worth noting. --- **Bug 1 — 2FA toggle does not auto-save (root cause of this report)** Confirmed in `frontend/src/pages/settings/SecurityTab.tsx` and `frontend/src/api/queries/useAllSettings.ts`. When the 2FA toggle is clicked, `toggleTwoFactor()` generates a TOTP secret locally, opens the confirmation modal, and — after the user scans the QR code and enters a correct code — calls: ```ts updateSetting({ twoFactorToken: newToken, twoFactorEnable: true }); ``` `updateSetting` updates only the **in-memory React draft**. The change is not sent to the backend until the user explicitly clicks the **Save** button at the top of the Settings page (the same button used to persist port, base path, Telegram settings, etc.). A page refresh before that click discards the unsaved draft, re-fetches server state (`POST /panel/api/setting/all`), and restores `twoFactorEnable: false` — which is also why logging in without OTP continues to work, because the backend setting was never changed. The success toast that appears after the modal is confirmed ("Two-factor authentication has been enabled") fires before the network save, making it appear that the operation is complete. **Workaround (immediate):** after confirming the TOTP modal, scroll to the top of the Settings page and click **Save** before navigating away or refreshing. --- **Bug 2 — Changing credentials via the web UI silently disables 2FA** Confirmed in `internal/web/service/panel/user.go`, `UpdateUser()`, lines 122–130: ```go twoFactorEnable, err := s.settingService.GetTwoFactorEnable() ... if twoFactorEnable { s.settingService.SetTwoFactorEnable(false) s.settingService.SetTwoFactorToken("") } ``` Any call to the `/panel/api/setting/updateUser` endpoint (Settings → Security → Admin credentials form) unconditionally clears `twoFactorEnable` and `twoFactorToken` in the database if 2FA is currently enabled. This did **not** trigger in the steps above because the credential change (step 3) occurred before 2FA was enabled (step 5). However, a user who enables and saves 2FA and then later changes their username or password will have 2FA silently erased on the next credential update. A closely related variant of this bug (in the `x-ui.sh` CLI reset path) was fixed in #4758. --- **To confirm which bug applies to your situation:** after going through steps 1–5 exactly as described, check whether you clicked the **Save** button in the header before refreshing. If you did not, Bug 1 is the cause. If you did click Save, please share the panel's response (success toast or error) at that point, as that would indicate a different code path. *This reply was generated automatically; a maintainer may follow up.*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
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
MHSanaei/3x-ui#3657
No description provided.