Skip to content

Commit

Permalink
Respond with a 401 on git push when password isn't changed yet (#20026)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
42wim committed Jun 19, 2022
1 parent 62104b4 commit e91229e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions modules/context/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package context

import (
"net/http"
"strings"

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

if ctx.Doer.MustChangePassword {
if ctx.Req.URL.Path != "/user/settings/change_password" {
if strings.HasPrefix(ctx.Req.UserAgent(), "git") {
ctx.Error(http.StatusUnauthorized, ctx.Tr("auth.must_change_password"))
return
}
ctx.Data["Title"] = ctx.Tr("auth.must_change_password")
ctx.Data["ChangePasscodeLink"] = setting.AppSubURL + "/user/change_password"
if ctx.Req.URL.Path != "/user/events" {
Expand Down

0 comments on commit e91229e

Please sign in to comment.