mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
coderd: tighten /login rate limiting (#4432)
* coderd: tighten /login rate limit * coderd: add Bypass rate limit header
This commit is contained in:
+13
-5
@@ -204,7 +204,7 @@ func New(options *Options) *API {
|
||||
// app URL. If it is, it will serve that application.
|
||||
api.handleSubdomainApplications(
|
||||
// Middleware to impose on the served application.
|
||||
httpmw.RateLimitPerMinute(options.APIRateLimit),
|
||||
httpmw.RateLimit(options.APIRateLimit, time.Minute),
|
||||
httpmw.ExtractAPIKey(httpmw.ExtractAPIKeyConfig{
|
||||
DB: options.Database,
|
||||
OAuth2Configs: oauthConfigs,
|
||||
@@ -229,7 +229,7 @@ func New(options *Options) *API {
|
||||
apps := func(r chi.Router) {
|
||||
r.Use(
|
||||
tracing.Middleware(api.TracerProvider),
|
||||
httpmw.RateLimitPerMinute(options.APIRateLimit),
|
||||
httpmw.RateLimit(options.APIRateLimit, time.Minute),
|
||||
httpmw.ExtractAPIKey(httpmw.ExtractAPIKeyConfig{
|
||||
DB: options.Database,
|
||||
OAuth2Configs: oauthConfigs,
|
||||
@@ -267,7 +267,7 @@ func New(options *Options) *API {
|
||||
r.Use(
|
||||
tracing.Middleware(api.TracerProvider),
|
||||
// Specific routes can specify smaller limits.
|
||||
httpmw.RateLimitPerMinute(options.APIRateLimit),
|
||||
httpmw.RateLimit(options.APIRateLimit, time.Minute),
|
||||
)
|
||||
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
httpapi.Write(r.Context(), w, http.StatusOK, codersdk.Response{
|
||||
@@ -304,7 +304,7 @@ func New(options *Options) *API {
|
||||
apiKeyMiddleware,
|
||||
// This number is arbitrary, but reading/writing
|
||||
// file content is expensive so it should be small.
|
||||
httpmw.RateLimitPerMinute(12),
|
||||
httpmw.RateLimit(12, time.Minute),
|
||||
)
|
||||
r.Get("/{fileID}", api.fileByID)
|
||||
r.Post("/", api.postFile)
|
||||
@@ -391,7 +391,15 @@ func New(options *Options) *API {
|
||||
r.Route("/users", func(r chi.Router) {
|
||||
r.Get("/first", api.firstUser)
|
||||
r.Post("/first", api.postFirstUser)
|
||||
r.Post("/login", api.postLogin)
|
||||
r.Group(func(r chi.Router) {
|
||||
// We use a tight limit for password login to protect
|
||||
// against audit-log write DoS, pbkdf2 DoS, and simple
|
||||
// brute-force attacks.
|
||||
//
|
||||
// Making this too small can break tests.
|
||||
r.Use(httpmw.RateLimit(60, time.Minute))
|
||||
r.Post("/login", api.postLogin)
|
||||
})
|
||||
r.Get("/authmethods", api.userAuthMethods)
|
||||
r.Route("/oauth2", func(r chi.Router) {
|
||||
r.Route("/github", func(r chi.Router) {
|
||||
|
||||
Reference in New Issue
Block a user