diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-11-03 04:38:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-02 21:38:08 +0100 |
commit | 1dedf9bba0bf909f9e275565604ec8f2adb5a86e (patch) | |
tree | 199e1c02030f9e9a9dd3e404d28049923167676e /routers/web/githttp.go | |
parent | 2147bfde0573a2f2492ca0c78c2e042cf327903a (diff) | |
download | gitea-1dedf9bba0bf909f9e275565604ec8f2adb5a86e.tar.gz gitea-1dedf9bba0bf909f9e275565604ec8f2adb5a86e.zip |
Fix http protocol auth (#27875) (#27878)
backport #27875
Diffstat (limited to 'routers/web/githttp.go')
-rw-r--r-- | routers/web/githttp.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/routers/web/githttp.go b/routers/web/githttp.go new file mode 100644 index 0000000000..b2fb5b472f --- /dev/null +++ b/routers/web/githttp.go @@ -0,0 +1,43 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package web + +import ( + "net/http" + + "code.gitea.io/gitea/modules/context" + "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/web" + "code.gitea.io/gitea/routers/web/repo" + context_service "code.gitea.io/gitea/services/context" +) + +func requireSignIn(ctx *context.Context) { + if !setting.Service.RequireSignInView { + return + } + + // rely on the results of Contexter + if !ctx.IsSigned { + // TODO: support digit auth - which would be Authorization header with digit + ctx.Resp.Header().Set("WWW-Authenticate", `Basic realm="Gitea"`) + ctx.Error(http.StatusUnauthorized) + } +} + +func gitHTTPRouters(m *web.Route) { + m.Group("", func() { + m.PostOptions("/git-upload-pack", repo.ServiceUploadPack) + m.PostOptions("/git-receive-pack", repo.ServiceReceivePack) + m.GetOptions("/info/refs", repo.GetInfoRefs) + m.GetOptions("/HEAD", repo.GetTextFile("HEAD")) + m.GetOptions("/objects/info/alternates", repo.GetTextFile("objects/info/alternates")) + m.GetOptions("/objects/info/http-alternates", repo.GetTextFile("objects/info/http-alternates")) + m.GetOptions("/objects/info/packs", repo.GetInfoPacks) + m.GetOptions("/objects/info/{file:[^/]*}", repo.GetTextFile("")) + m.GetOptions("/objects/{head:[0-9a-f]{2}}/{hash:[0-9a-f]{38}}", repo.GetLooseObject) + m.GetOptions("/objects/pack/pack-{file:[0-9a-f]{40}}.pack", repo.GetPackFile) + m.GetOptions("/objects/pack/pack-{file:[0-9a-f]{40}}.idx", repo.GetIdxFile) + }, ignSignInAndCsrf, requireSignIn, repo.HTTPGitEnabledHandler, repo.CorsHandler(), context_service.UserAssignmentWeb()) +} |