Add rate limit on auth routes

This commit is contained in:
Jim LAURIE 2018-08-01 14:56:31 +02:00
parent 6c091378a8
commit 738cbf656a
25 changed files with 41 additions and 27 deletions

View File

@ -1,6 +1,6 @@
{
"name": "strapi-email-amazon-ses",
"version": "3.0.0-alpha.13",
"version": "3.0.0-alpha.13.0.1",
"description": "Amazon SES provider for strapi email",
"homepage": "http://strapi.io",
"keywords": [

View File

@ -45,6 +45,7 @@
"Auth.form.error.params.provide": "Incorrect params provided.",
"Auth.form.error.username.taken": "Username is already taken",
"Auth.form.error.email.taken": "Email is already taken",
"Auth.form.error.ratelimit": "Too many attempts, please try again in a minute.",
"Auth.link.forgot-password": "Forgot your password?",
"Auth.link.ready": "Ready to sign in?",

View File

@ -0,0 +1,12 @@
const RateLimit = require('koa2-ratelimit').RateLimit;
module.exports = async (ctx, next) => {
const message = ctx.request.admin ? [{ messages: [{ id: 'Auth.form.error.ratelimit' }] }] : 'Too many attempts, please try again in a minute.';
return RateLimit.middleware({
interval: 1*60*1000,
max: 5,
prefixKey: `${ctx.request.url}:${ctx.request.ip}`,
message
})(ctx, next);
};

View File

@ -153,7 +153,7 @@
"path": "/connect/*",
"handler": "Auth.connect",
"config": {
"policies": [],
"policies": ["plugins.users-permissions.ratelimit"],
"prefix": ""
}
},
@ -162,7 +162,7 @@
"path": "/auth/local",
"handler": "Auth.callback",
"config": {
"policies": [],
"policies": ["plugins.users-permissions.ratelimit"],
"prefix": ""
}
},
@ -171,7 +171,7 @@
"path": "/auth/local/register",
"handler": "Auth.register",
"config": {
"policies": [],
"policies": ["plugins.users-permissions.ratelimit"],
"prefix": ""
}
},
@ -189,7 +189,7 @@
"path": "/auth/forgot-password",
"handler": "Auth.forgotPassword",
"config": {
"policies": [],
"policies": ["plugins.users-permissions.ratelimit"],
"prefix": ""
}
},
@ -198,7 +198,7 @@
"path": "/auth/reset-password",
"handler": "Auth.changePassword",
"config": {
"policies": [],
"policies": ["plugins.users-permissions.ratelimit"],
"prefix": ""
}
},

View File

@ -26,6 +26,7 @@
"grant-koa": "^3.8.1",
"jsonwebtoken": "^8.1.0",
"koa": "^2.1.0",
"koa2-ratelimit": "^0.6.1",
"purest": "^2.0.1",
"request": "^2.83.0",
"uuid": "^3.1.0"

View File

@ -134,7 +134,7 @@ const getProfile = async (provider, query, callback) => {
callback(err);
} else {
// Combine username and discriminator because discord username is not unique
var username = body.username + '#' + body.discriminator;
var username = `${body.username}#${body.discriminator}`;
callback(null, {
username: username,
email: body.email