mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6546] [MERGED] fix(panel): accept 2FA codes from adjacent TOTP windows #6344
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6344
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/MHSanaei/3x-ui/pull/6546
Author: @sdhfsl
Created: 9/15/2026
Status: ✅ Merged
Merged: 9/15/2026
Merged by: @BlindMaster24
Base:
main← Head:main📝 Commits (3)
959e6fdfix(panel): accept 2FA codes from adjacent TOTP windowsf3096bbfix(panel): share TOTP skew tolerance with VerifyTwoFactorCode198ac75Merge branch 'main' into main📊 Changes
5 files changed (+65 additions, -4 deletions)
View changed files
➕
internal/util/totp/totp.go(+22 -0)➕
internal/util/totp/totp_test.go(+34 -0)📝
internal/web/service/panel/user.go(+3 -2)📝
internal/web/service/setting.go(+2 -2)📝
internal/web/service/setting_security_test.go(+4 -0)📄 Description
Problem
Fixes #6535.
Every 2FA login fails once with
invalid 2FA codeand then succeeds on an immediate retry (see timestamps in the issue: fail at 00:54:59, success at 00:55:01).Root cause
UserService.CheckUser(internal/web/service/panel/user.go) compared onlygotp.NewDefaultTOTP(token).Now()— the single current 30s window. A code submitted near the end of its window (or with slight client/server clock drift) arrives after the server has rolled over, so the first attempt fails and the retry in the next window succeeds. Classic missing-skew bug.Fix
Accept the current window ±1 step (
verifyTOTPWithSkew), the standard TOTP clock-drift tolerance. Wrong codes and codes two windows away are still rejected.Tests
New
TestVerifyTOTPWithSkew: current/previous/next window accept, ±2 windows and wrong code reject — passes. Fullpanelpackage has one pre-existing failure (TestUpdateProxyEnvVars, fails on clean tree too, unrelated env-casing issue).🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.