Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions core/app/api/v2/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ func (b *BaseApi) MFALogin(c *gin.Context) {
if err := helper.CheckBindAndValidate(&req, c); err != nil {
return
}
ip := common.GetRealClientIP(c)
if global.IPTracker.NeedCaptcha(ip) {
helper.BadAuth(c, "ErrMFA", nil)
return
Comment on lines +89 to +91
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Avoid hard-blocking MFA retries when captcha is required

This early return makes /core/auth/mfalogin reject all requests from a tracked IP with ErrMFA before verifying the submitted code. Because this same handler now sets NeedCaptcha after one wrong MFA code, a user who mistypes once cannot complete MFA on the current screen anymore: the frontend MFA handler (frontend/src/views/login/components/login-form.vue, mfaLogin) treats every 401 as a generic MFA error and does not expose captcha or route back to password login, so even a correct second code is rejected until the user manually restarts the whole login flow.

Useful? React with 👍 / 👎.

}

entranceItem := c.Request.Header.Get("EntranceCode")
var entrance []byte
Expand All @@ -95,13 +100,16 @@ func (b *BaseApi) MFALogin(c *gin.Context) {
user, msgKey, err := authService.MFALogin(c, req, string(entrance))
go saveLoginLogs(c, wrapLoginErr(msgKey, err))
if msgKey == "ErrAuth" || msgKey == "ErrMFA" {
global.IPTracker.SetNeedCaptcha(ip)
helper.BadAuth(c, msgKey, err)
return
}
if err != nil {
global.IPTracker.SetNeedCaptcha(ip)
helper.InternalServer(c, err)
return
}
global.IPTracker.Clear(ip)
helper.SuccessWithData(c, user)
}

Expand Down
Loading