2017-01-23 22:44:39 +01:00
|
|
|
var url = require('url'),
|
|
|
|
spamPrevention = require('./api/spam-prevention');
|
2016-11-08 11:33:19 +00:00
|
|
|
|
2017-01-23 22:44:39 +01:00
|
|
|
/**
|
|
|
|
* We set ignoreIP to false, because we tell brute-knex to use `req.ip`.
|
|
|
|
* We can use `req.ip`, because express trust proxy option is enabled.
|
|
|
|
*/
|
2016-11-08 11:33:19 +00:00
|
|
|
module.exports = {
|
2017-01-23 22:44:39 +01:00
|
|
|
/**
|
|
|
|
* block per route per ip
|
|
|
|
*/
|
2016-11-08 11:33:19 +00:00
|
|
|
globalBlock: spamPrevention.globalBlock.getMiddleware({
|
2017-01-23 22:44:39 +01:00
|
|
|
ignoreIP: false,
|
2016-11-08 11:33:19 +00:00
|
|
|
key: function (req, res, next) {
|
2017-01-23 22:44:39 +01:00
|
|
|
next(url.parse(req.url).pathname);
|
2016-11-08 11:33:19 +00:00
|
|
|
}
|
|
|
|
}),
|
2017-01-23 22:44:39 +01:00
|
|
|
/**
|
|
|
|
* block per route per ip
|
|
|
|
*/
|
2016-11-08 11:33:19 +00:00
|
|
|
globalReset: spamPrevention.globalReset.getMiddleware({
|
2017-01-23 22:44:39 +01:00
|
|
|
ignoreIP: false,
|
2016-11-08 11:33:19 +00:00
|
|
|
key: function (req, res, next) {
|
2017-01-23 22:44:39 +01:00
|
|
|
next(url.parse(req.url).pathname);
|
2016-11-08 11:33:19 +00:00
|
|
|
}
|
|
|
|
}),
|
2017-01-23 22:44:39 +01:00
|
|
|
/**
|
|
|
|
* block per user
|
|
|
|
* username === email!
|
|
|
|
*/
|
2016-11-08 11:33:19 +00:00
|
|
|
userLogin: spamPrevention.userLogin.getMiddleware({
|
2017-01-23 22:44:39 +01:00
|
|
|
ignoreIP: false,
|
2016-11-08 11:33:19 +00:00
|
|
|
key: function (req, res, next) {
|
2016-11-17 13:02:56 +00:00
|
|
|
if (req.body.username) {
|
2017-01-23 22:44:39 +01:00
|
|
|
return next(req.body.username + 'login');
|
2016-11-17 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (req.body.authorizationCode) {
|
2017-01-23 22:44:39 +01:00
|
|
|
return next(req.body.authorizationCode + 'login');
|
2016-11-17 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (req.body.refresh_token) {
|
2017-01-23 22:44:39 +01:00
|
|
|
return next(req.body.refresh_token + 'login');
|
2016-11-17 13:02:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return next();
|
2016-11-08 11:33:19 +00:00
|
|
|
}
|
|
|
|
}),
|
2017-01-23 22:44:39 +01:00
|
|
|
/**
|
|
|
|
* block per user
|
|
|
|
*/
|
2016-11-08 11:33:19 +00:00
|
|
|
userReset: spamPrevention.userReset.getMiddleware({
|
2017-01-23 22:44:39 +01:00
|
|
|
ignoreIP: false,
|
2016-11-08 11:33:19 +00:00
|
|
|
key: function (req, res, next) {
|
2017-01-23 22:44:39 +01:00
|
|
|
next(req.body.username + 'reset');
|
2016-11-08 11:33:19 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
privateBlog: spamPrevention.privateBlog.getMiddleware({
|
2017-01-23 22:44:39 +01:00
|
|
|
ignoreIP: false,
|
2016-11-08 11:33:19 +00:00
|
|
|
key: function (req, res, next) {
|
2017-01-23 22:44:39 +01:00
|
|
|
next('privateblog');
|
2016-11-08 11:33:19 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
};
|