Skip to content

Commit e91229e

Browse files
authored
Respond with a 401 on git push when password isn't changed yet (#20026)
If the user-agent starts with git and user must change password but hasn't return a 401 with the message. It must be a 401, git doesn't seem to show the contents of the error message when we return a 403 Fixes #19090
1 parent 62104b4 commit e91229e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

modules/context/auth.go

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package context
77

88
import (
99
"net/http"
10+
"strings"
1011

1112
"code.gitea.io/gitea/models/auth"
1213
"code.gitea.io/gitea/modules/log"
@@ -41,6 +42,10 @@ func Toggle(options *ToggleOptions) func(ctx *Context) {
4142

4243
if ctx.Doer.MustChangePassword {
4344
if ctx.Req.URL.Path != "/user/settings/change_password" {
45+
if strings.HasPrefix(ctx.Req.UserAgent(), "git") {
46+
ctx.Error(http.StatusUnauthorized, ctx.Tr("auth.must_change_password"))
47+
return
48+
}
4449
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
4550
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/change_password"
4651
if ctx.Req.URL.Path != "/user/events" {

0 commit comments

Comments
 (0)