|
@@ -18,6 +18,7 @@ import * as userActivation from './user-activation';
|
|
|
const rateLimit = require('express-rate-limit');
|
|
const rateLimit = require('express-rate-limit');
|
|
|
const multer = require('multer');
|
|
const multer = require('multer');
|
|
|
const autoReap = require('multer-autoreap');
|
|
const autoReap = require('multer-autoreap');
|
|
|
|
|
+const { RateLimiterMemory } = require('rate-limiter-flexible');
|
|
|
|
|
|
|
|
const apiLimiter = rateLimit({
|
|
const apiLimiter = rateLimit({
|
|
|
windowMs: 15 * 60 * 1000, // 15 minutes
|
|
windowMs: 15 * 60 * 1000, // 15 minutes
|
|
@@ -26,6 +27,13 @@ const apiLimiter = rateLimit({
|
|
|
'Too many requests sent from this IP, please try again after 15 minutes',
|
|
'Too many requests sent from this IP, please try again after 15 minutes',
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+const opts = {
|
|
|
|
|
+ points: 10, // set default value
|
|
|
|
|
+ duration: 100, // set default value
|
|
|
|
|
+};
|
|
|
|
|
+
|
|
|
|
|
+const rateLimiter = new RateLimiterMemory(opts);
|
|
|
|
|
+
|
|
|
autoReap.options.reapOnError = true; // continue reaping the file even if an error occurs
|
|
autoReap.options.reapOnError = true; // continue reaping the file even if an error occurs
|
|
|
|
|
|
|
|
module.exports = function(crowi, app) {
|
|
module.exports = function(crowi, app) {
|
|
@@ -53,6 +61,7 @@ module.exports = function(crowi, app) {
|
|
|
const search = require('./search')(crowi, app);
|
|
const search = require('./search')(crowi, app);
|
|
|
const hackmd = require('./hackmd')(crowi, app);
|
|
const hackmd = require('./hackmd')(crowi, app);
|
|
|
const ogp = require('./ogp')(crowi);
|
|
const ogp = require('./ogp')(crowi);
|
|
|
|
|
+ const apiRateLimiter = require('../middlewares/api-rate-limiter')(crowi, rateLimiter);
|
|
|
|
|
|
|
|
const unavailableWhenMaintenanceMode = generateUnavailableWhenMaintenanceModeMiddleware(crowi);
|
|
const unavailableWhenMaintenanceMode = generateUnavailableWhenMaintenanceModeMiddleware(crowi);
|
|
|
const unavailableWhenMaintenanceModeForApi = generateUnavailableWhenMaintenanceModeMiddlewareForApi(crowi);
|
|
const unavailableWhenMaintenanceModeForApi = generateUnavailableWhenMaintenanceModeMiddlewareForApi(crowi);
|
|
@@ -71,6 +80,9 @@ module.exports = function(crowi, app) {
|
|
|
// API v3 for auth
|
|
// API v3 for auth
|
|
|
app.use('/_api/v3', apiV3AuthRouter);
|
|
app.use('/_api/v3', apiV3AuthRouter);
|
|
|
|
|
|
|
|
|
|
+ // API rate limiter
|
|
|
|
|
+ app.use(apiRateLimiter);
|
|
|
|
|
+
|
|
|
app.get('/' , applicationInstalled, unavailableWhenMaintenanceMode, loginRequired, autoReconnectToSearch, injectUserUISettings, page.showTopPage);
|
|
app.get('/' , applicationInstalled, unavailableWhenMaintenanceMode, loginRequired, autoReconnectToSearch, injectUserUISettings, page.showTopPage);
|
|
|
|
|
|
|
|
app.get('/login/error/:reason' , applicationInstalled, login.error);
|
|
app.get('/login/error/:reason' , applicationInstalled, login.error);
|