@@ -204,7 +204,7 @@ func New(options *Options) *API {
204
204
// app URL. If it is, it will serve that application.
205
205
api .handleSubdomainApplications (
206
206
// Middleware to impose on the served application.
207
- httpmw .RateLimitPerMinute (options .APIRateLimit ),
207
+ httpmw .RateLimit (options .APIRateLimit , time . Minute ),
208
208
httpmw .ExtractAPIKey (httpmw.ExtractAPIKeyConfig {
209
209
DB : options .Database ,
210
210
OAuth2Configs : oauthConfigs ,
@@ -229,7 +229,7 @@ func New(options *Options) *API {
229
229
apps := func (r chi.Router ) {
230
230
r .Use (
231
231
tracing .Middleware (api .TracerProvider ),
232
- httpmw .RateLimitPerMinute (options .APIRateLimit ),
232
+ httpmw .RateLimit (options .APIRateLimit , time . Minute ),
233
233
httpmw .ExtractAPIKey (httpmw.ExtractAPIKeyConfig {
234
234
DB : options .Database ,
235
235
OAuth2Configs : oauthConfigs ,
@@ -267,7 +267,7 @@ func New(options *Options) *API {
267
267
r .Use (
268
268
tracing .Middleware (api .TracerProvider ),
269
269
// Specific routes can specify smaller limits.
270
- httpmw .RateLimitPerMinute (options .APIRateLimit ),
270
+ httpmw .RateLimit (options .APIRateLimit , time . Minute ),
271
271
)
272
272
r .Get ("/" , func (w http.ResponseWriter , r * http.Request ) {
273
273
httpapi .Write (r .Context (), w , http .StatusOK , codersdk.Response {
@@ -304,7 +304,7 @@ func New(options *Options) *API {
304
304
apiKeyMiddleware ,
305
305
// This number is arbitrary, but reading/writing
306
306
// file content is expensive so it should be small.
307
- httpmw .RateLimitPerMinute (12 ),
307
+ httpmw .RateLimit (12 , time . Minute ),
308
308
)
309
309
r .Get ("/{fileID}" , api .fileByID )
310
310
r .Post ("/" , api .postFile )
@@ -391,7 +391,15 @@ func New(options *Options) *API {
391
391
r .Route ("/users" , func (r chi.Router ) {
392
392
r .Get ("/first" , api .firstUser )
393
393
r .Post ("/first" , api .postFirstUser )
394
- r .Post ("/login" , api .postLogin )
394
+ r .Group (func (r chi.Router ) {
395
+ // We use a tight limit for password login to protect
396
+ // against audit-log write DoS, pbkdf2 DoS, and simple
397
+ // brute-force attacks.
398
+ //
399
+ // Making this too small can break tests.
400
+ r .Use (httpmw .RateLimit (60 , time .Minute ))
401
+ r .Post ("/login" , api .postLogin )
402
+ })
395
403
r .Get ("/authmethods" , api .userAuthMethods )
396
404
r .Route ("/oauth2" , func (r chi.Router ) {
397
405
r .Route ("/github" , func (r chi.Router ) {
@@ -495,6 +503,7 @@ func New(options *Options) *API {
495
503
apiKeyMiddleware ,
496
504
)
497
505
r .Get ("/" , api .workspaces )
506
+ r .Get ("/count" , api .workspaceCount )
498
507
r .Route ("/{workspace}" , func (r chi.Router ) {
499
508
r .Use (
500
509
httpmw .ExtractWorkspaceParam (options .Database ),
0 commit comments