MM-66886 Add rate limiting to login endpoint (#34943) (#35314)

Automatic Merge
Этот коммит содержится в:
Mattermost Build
2026-02-16 12:39:39 +02:00
коммит произвёл GitHub
родитель eb8c99fe9c
Коммит 39ba0a3cd7
2 изменённых файлов: 5 добавлений и 1 удалений

Просмотреть файл

@@ -220,6 +220,10 @@ func (api *API) APILocal(h handlerFunc, opts ...APIHandlerOption) http.Handler {
}
func (api *API) RateLimitedHandler(apiHandler http.Handler, settings model.RateLimitSettings) http.Handler {
if !*api.srv.Config().RateLimitSettings.Enable {
return apiHandler
}
settings.SetDefaults()
rateLimiter, err := app.NewRateLimiter(&settings, []string{})

Просмотреть файл

@@ -64,7 +64,7 @@ func (api *API) InitUser() {
api.BaseRoutes.User.Handle("/mfa", api.APISessionRequiredMfa(updateUserMfa)).Methods(http.MethodPut)
api.BaseRoutes.User.Handle("/mfa/generate", api.APISessionRequiredMfa(generateMfaSecret)).Methods(http.MethodPost)
api.BaseRoutes.Users.Handle("/login", api.APIHandler(login)).Methods(http.MethodPost)
api.BaseRoutes.Users.Handle("/login", api.RateLimitedHandler(api.APIHandler(login), model.RateLimitSettings{PerSec: model.NewPointer(5), MaxBurst: model.NewPointer(10)})).Methods(http.MethodPost)
api.BaseRoutes.Users.Handle("/login/sso/code-exchange", api.APIHandler(loginSSOCodeExchange)).Methods(http.MethodPost)
api.BaseRoutes.Users.Handle("/login/desktop_token", api.RateLimitedHandler(api.APIHandler(loginWithDesktopToken), model.RateLimitSettings{PerSec: model.NewPointer(2), MaxBurst: model.NewPointer(1)})).Methods(http.MethodPost)
api.BaseRoutes.Users.Handle("/login/switch", api.APIHandler(switchAccountType)).Methods(http.MethodPost)