Skip to content

Commit

Permalink
feat(indiekit): rate limit some requests
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Jan 29, 2022
1 parent 3b5fd97 commit 6a7d520
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
20 changes: 20 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions packages/indiekit/lib/routes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import express from 'express';
import frontend from '@indiekit/frontend';
import rateLimit from 'express-rate-limit';
import * as assetsController from './controllers/assets.js';
import * as homepageController from './controllers/homepage.js';
import * as sessionController from './controllers/session.js';
Expand All @@ -8,6 +9,12 @@ import {authenticate} from './middleware/authentication.js';

const {assetsPath} = frontend;
const router = express.Router(); // eslint-disable-line new-cap
const limit = rateLimit({
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100,
standardHeaders: true,
legacyHeaders: false,
});

export const routes = indiekitConfig => {
const {application, publication} = indiekitConfig;
Expand Down Expand Up @@ -42,9 +49,9 @@ export const routes = indiekitConfig => {
}

// Session
router.get('/session/login', sessionController.login);
router.post('/session/login', sessionController.authenticate);
router.get('/session/auth', sessionController.authenticationCallback);
router.get('/session/login', limit, sessionController.login);
router.post('/session/login', limit, sessionController.authenticate);
router.get('/session/auth', limit, sessionController.authenticationCallback);
router.get('/session/logout', sessionController.logout);

// Endpoints
Expand Down
1 change: 1 addition & 0 deletions packages/indiekit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"debug": "^4.3.2",
"deepmerge": "^4.2.2",
"express": "^4.17.1",
"express-rate-limit": "^6.2.0",
"got": "^12.0.0",
"http-errors": "^2.0.0",
"i18n": "^0.14.0",
Expand Down

0 comments on commit 6a7d520

Please sign in to comment.