summaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2023-09-07 16:31:46 +0800
committerGitHub <noreply@github.com>2023-09-07 08:31:46 +0000
commite97e883ad50774f249c8c694598c25a17227299b (patch)
treead48381f40d2be7cb14265625f2fe7138f509537 /routers/api
parent1221221595122c212ace8bc50f2904bead8d2655 (diff)
downloadgitea-e97e883ad50774f249c8c694598c25a17227299b.tar.gz
gitea-e97e883ad50774f249c8c694598c25a17227299b.zip
Add reverseproxy auth for API back with default disabled (#26703)
This feature was removed by #22219 to avoid possible CSRF attack. This PR takes reverseproxy auth for API back but with default disabled. To prevent possbile CSRF attack, the responsibility will be the reverseproxy but not Gitea itself. For those want to enable this `ENABLE_REVERSE_PROXY_AUTHENTICATION_API`, they should know what they are doing. --------- Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/api.go10
1 files changed, 8 insertions, 2 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index 74e68e9ee2..757b406799 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -333,8 +333,11 @@ func reqExploreSignIn() func(ctx *context.APIContext) {
}
}
-func reqBasicAuth() func(ctx *context.APIContext) {
+func reqBasicOrRevProxyAuth() func(ctx *context.APIContext) {
return func(ctx *context.APIContext) {
+ if ctx.IsSigned && setting.Service.EnableReverseProxyAuthAPI && ctx.Data["AuthedMethod"].(string) == auth.ReverseProxyMethodName {
+ return
+ }
if !ctx.IsBasicAuth {
ctx.Error(http.StatusUnauthorized, "reqBasicAuth", "auth required")
return
@@ -698,6 +701,9 @@ func buildAuthGroup() *auth.Group {
&auth.HTTPSign{},
&auth.Basic{}, // FIXME: this should be removed once we don't allow basic auth in API
)
+ if setting.Service.EnableReverseProxyAuthAPI {
+ group.Add(&auth.ReverseProxy{})
+ }
specialAdd(group)
return group
@@ -800,7 +806,7 @@ func Routes() *web.Route {
m.Combo("").Get(user.ListAccessTokens).
Post(bind(api.CreateAccessTokenOption{}), reqToken(), user.CreateAccessToken)
m.Combo("/{id}").Delete(reqToken(), user.DeleteAccessToken)
- }, reqBasicAuth())
+ }, reqBasicOrRevProxyAuth())
m.Get("/activities/feeds", user.ListUserActivityFeeds)
}, context_service.UserAssignmentAPI())