Skip to content

Respond with a 401 on git push when password isn't changed yet #20026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 19, 2022
Merged
Changes from 1 commit
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
Next Next commit
Respond with a 401 on git push when password isn't changed yet
Fixes #19090

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
  • Loading branch information
42wim committed Jun 18, 2022
commit 4587b1d3f6ae7d7ca92db2b882d2ef31a6776361
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