diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-12-28 03:24:43 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-27 20:24:43 +0100 |
commit | 9b4da56963692819d236b07504e565d4b4fb4021 (patch) | |
tree | ff2843eaa7eedc88aabff659f00617285a2ea4b3 | |
parent | 5583eaa90430edfa553c93f61e4fc2cc3a10d8b8 (diff) | |
download | gitea-9b4da56963692819d236b07504e565d4b4fb4021.tar.gz gitea-9b4da56963692819d236b07504e565d4b4fb4021.zip |
Remove ReverseProxy authentication from the API (#22219) (#22251)
backport from #22219
Since we changed the /api/v1/ routes to disallow session authentication
we also removed their reliance on CSRF. However, we left the
ReverseProxy authentication here - but this means that POSTs to the API
are no longer protected by CSRF.
Now, ReverseProxy authentication is a kind of session authentication,
and is therefore inconsistent with the removal of session from the API.
This PR proposes that we simply remove the ReverseProxy authentication
from the API and therefore users of the API must explicitly use tokens
or basic authentication.
Replace #22077
Close #22221
Close #22077
Signed-off-by: Andrew Thornton <art27@cantab.net>
Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: zeripath <art27@cantab.net>
-rw-r--r-- | routers/api/v1/api.go | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index a515551a57..9f6bcf4f85 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -232,13 +232,10 @@ func reqExploreSignIn() func(ctx *context.APIContext) { } } -func reqBasicOrRevProxyAuth() func(ctx *context.APIContext) { +func reqBasicAuth() func(ctx *context.APIContext) { return func(ctx *context.APIContext) { - if ctx.IsSigned && setting.Service.EnableReverseProxyAuth && ctx.Data["AuthedMethod"].(string) == auth.ReverseProxyMethodName { - return - } if !ctx.Context.IsBasicAuth { - ctx.Error(http.StatusUnauthorized, "reqBasicOrRevProxyAuth", "auth required") + ctx.Error(http.StatusUnauthorized, "reqBasicAuth", "auth required") return } ctx.CheckForOTP() @@ -597,9 +594,6 @@ 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.EnableReverseProxyAuth { - group.Add(&auth.ReverseProxy{}) - } specialAdd(group) return group @@ -689,7 +683,7 @@ func Routes(ctx gocontext.Context) *web.Route { m.Combo("").Get(user.ListAccessTokens). Post(bind(api.CreateAccessTokenOption{}), user.CreateAccessToken) m.Combo("/{id}").Delete(user.DeleteAccessToken) - }, reqBasicOrRevProxyAuth()) + }, reqBasicAuth()) }, context_service.UserAssignmentAPI()) }) |