@@ -187,7 +187,7 @@ func New(options *Options) *API {
187
187
// app URL. If it is, it will serve that application.
188
188
api .handleSubdomainApplications (
189
189
// Middleware to impose on the served application.
190
- httpmw .RateLimitPerMinute (options .APIRateLimit ),
190
+ httpmw .RateLimit (options .APIRateLimit , time . Minute ),
191
191
httpmw .ExtractAPIKey (httpmw.ExtractAPIKeyConfig {
192
192
DB : options .Database ,
193
193
OAuth2Configs : oauthConfigs ,
@@ -212,7 +212,7 @@ func New(options *Options) *API {
212
212
apps := func (r chi.Router ) {
213
213
r .Use (
214
214
tracing .Middleware (api .TracerProvider ),
215
- httpmw .RateLimitPerMinute (options .APIRateLimit ),
215
+ httpmw .RateLimit (options .APIRateLimit , time . Minute ),
216
216
apiKeyMiddlewareRedirect ,
217
217
httpmw .ExtractUserParam (api .Database ),
218
218
// Extracts the <workspace.agent> from the url
@@ -240,7 +240,7 @@ func New(options *Options) *API {
240
240
r .Use (
241
241
tracing .Middleware (api .TracerProvider ),
242
242
// Specific routes can specify smaller limits.
243
- httpmw .RateLimitPerMinute (options .APIRateLimit ),
243
+ httpmw .RateLimit (options .APIRateLimit , time . Minute ),
244
244
)
245
245
r .Get ("/" , func (w http.ResponseWriter , r * http.Request ) {
246
246
httpapi .Write (r .Context (), w , http .StatusOK , codersdk.Response {
@@ -273,7 +273,7 @@ func New(options *Options) *API {
273
273
apiKeyMiddleware ,
274
274
// This number is arbitrary, but reading/writing
275
275
// file content is expensive so it should be small.
276
- httpmw .RateLimitPerMinute (12 ),
276
+ httpmw .RateLimit (12 , time . Minute ),
277
277
)
278
278
r .Get ("/{hash}" , api .fileByHash )
279
279
r .Post ("/" , api .postFile )
@@ -359,7 +359,13 @@ func New(options *Options) *API {
359
359
r .Route ("/users" , func (r chi.Router ) {
360
360
r .Get ("/first" , api .firstUser )
361
361
r .Post ("/first" , api .postFirstUser )
362
- r .Post ("/login" , api .postLogin )
362
+ r .Group (func (r chi.Router ) {
363
+ // We use a tight limit for password login to protect
364
+ // against audit-log write DoS, pbkdf2 DoS, and simple
365
+ // brute-force attacks.
366
+ r .Use (httpmw .RateLimit (10 , time .Minute ))
367
+ r .Post ("/login" , api .postLogin )
368
+ })
363
369
r .Get ("/authmethods" , api .userAuthMethods )
364
370
r .Route ("/oauth2" , func (r chi.Router ) {
365
371
r .Route ("/github" , func (r chi.Router ) {
0 commit comments