mirror of
https://github.com/strapi/strapi.git
synced 2025-12-12 15:32:42 +00:00
Add rate limit on auth routes
This commit is contained in:
parent
6c091378a8
commit
738cbf656a
@ -51,4 +51,4 @@
|
||||
"npm": ">= 5.0.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
@ -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": [
|
||||
@ -42,4 +42,4 @@
|
||||
"npm": ">= 5.3.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
@ -42,4 +42,4 @@
|
||||
"npm": ">= 5.3.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
@ -42,4 +42,4 @@
|
||||
"npm": ">= 5.3.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
@ -41,4 +41,4 @@
|
||||
"npm": ">= 5.3.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
@ -42,4 +42,4 @@
|
||||
"npm": ">= 5.3.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
@ -43,4 +43,4 @@
|
||||
"npm": ">= 5.3.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
@ -115,4 +115,4 @@
|
||||
"webpack-hot-middleware": "^2.18.2",
|
||||
"whatwg-fetch": "^2.0.3"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -43,4 +43,4 @@
|
||||
"npm": ">= 5.0.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
@ -45,4 +45,4 @@
|
||||
"npm": ">= 5.3.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
@ -44,4 +44,4 @@
|
||||
"npm": ">= 5.3.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
@ -41,4 +41,4 @@
|
||||
"babel-eslint": "^8.2.3",
|
||||
"prettier": "^1.12.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -43,4 +43,4 @@
|
||||
"npm": ">= 5.3.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
@ -49,4 +49,4 @@
|
||||
"npm": ">= 5.3.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
@ -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?",
|
||||
|
||||
@ -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);
|
||||
};
|
||||
@ -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": ""
|
||||
}
|
||||
},
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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
|
||||
|
||||
@ -43,4 +43,4 @@
|
||||
"npm": ">= 5.3.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
@ -43,4 +43,4 @@
|
||||
"npm": ">= 5.3.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
@ -39,4 +39,4 @@
|
||||
"npm": ">= 5.3.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
@ -13,4 +13,4 @@
|
||||
"pkgcloud": "^1.5.0",
|
||||
"streamifier": "^0.1.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -49,4 +49,4 @@
|
||||
"npm": ">= 5.3.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
@ -91,4 +91,4 @@
|
||||
},
|
||||
"preferGlobal": true,
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user