2020-10-27 11:27:17 +01:00
|
|
|
'use strict';
|
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
const lazyRateLimit = {
|
|
|
|
get RateLimit() {
|
|
|
|
return require('koa2-ratelimit').RateLimit;
|
|
|
|
},
|
|
|
|
};
|
2018-08-01 14:56:31 +02:00
|
|
|
|
|
|
|
module.exports = async (ctx, next) => {
|
2019-08-21 12:10:23 +02:00
|
|
|
const message = [
|
|
|
|
{
|
|
|
|
messages: [
|
|
|
|
{
|
|
|
|
id: 'Auth.form.error.ratelimit',
|
|
|
|
message: 'Too many attempts, please try again in a minute.',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
];
|
2018-08-01 14:56:31 +02:00
|
|
|
|
2019-04-05 16:11:09 +02:00
|
|
|
return lazyRateLimit.RateLimit.middleware(
|
|
|
|
Object.assign(
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
interval: 1 * 60 * 1000,
|
|
|
|
max: 5,
|
2020-06-15 10:34:59 +02:00
|
|
|
prefixKey: `${ctx.request.path}:${ctx.request.ip}`,
|
2019-04-05 16:11:09 +02:00
|
|
|
message,
|
|
|
|
},
|
2021-08-17 19:28:10 +02:00
|
|
|
strapi.config.get('plugin.users-permissions.ratelimit')
|
2019-04-05 16:11:09 +02:00
|
|
|
)
|
|
|
|
)(ctx, next);
|
2018-08-01 14:56:31 +02:00
|
|
|
};
|