-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
closes #7766, refs #7579 - ensure we are using the correct brute keys - ensure we are using req.ip as Ghost is configured with trust proxy option - tidy up a little
- Loading branch information
Showing
9 changed files
with
164 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,64 @@ | ||
var spamPrevention = require('./api/spam-prevention'); | ||
var url = require('url'), | ||
spamPrevention = require('./api/spam-prevention'); | ||
|
||
/** | ||
* 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. | ||
*/ | ||
module.exports = { | ||
/** | ||
* block per route per ip | ||
*/ | ||
globalBlock: spamPrevention.globalBlock.getMiddleware({ | ||
// We want to ignore req.ip and instead use req.connection.remoteAddress | ||
ignoreIP: true, | ||
ignoreIP: false, | ||
key: function (req, res, next) { | ||
req.authInfo = req.authInfo || {}; | ||
req.authInfo.ip = req.connection.remoteAddress; | ||
req.body.connection = req.connection.remoteAddress; | ||
|
||
next(req.authInfo.ip); | ||
next(url.parse(req.url).pathname); | ||
} | ||
}), | ||
/** | ||
* block per route per ip | ||
*/ | ||
globalReset: spamPrevention.globalReset.getMiddleware({ | ||
ignoreIP: true, | ||
ignoreIP: false, | ||
key: function (req, res, next) { | ||
req.authInfo = req.authInfo || {}; | ||
req.authInfo.ip = req.connection.remoteAddress; | ||
// prevent too many attempts for the same email address but keep separate to login brute force prevention | ||
next(req.authInfo.ip); | ||
next(url.parse(req.url).pathname); | ||
} | ||
}), | ||
/** | ||
* block per user | ||
* username === email! | ||
*/ | ||
userLogin: spamPrevention.userLogin.getMiddleware({ | ||
ignoreIP: true, | ||
ignoreIP: false, | ||
key: function (req, res, next) { | ||
req.authInfo = req.authInfo || {}; | ||
req.authInfo.ip = req.connection.remoteAddress || req.ip; | ||
// prevent too many attempts for the same username | ||
if (req.body.username) { | ||
return next(req.authInfo.ip + req.body.username + 'login'); | ||
return next(req.body.username + 'login'); | ||
} | ||
|
||
if (req.body.authorizationCode) { | ||
return next(req.authInfo.ip + req.body.authorizationCode + 'login'); | ||
return next(req.body.authorizationCode + 'login'); | ||
} | ||
|
||
if (req.body.refresh_token) { | ||
return next(req.authInfo.ip + req.body.refresh_token + 'login'); | ||
return next(req.body.refresh_token + 'login'); | ||
} | ||
|
||
return next(); | ||
} | ||
}), | ||
/** | ||
* block per user | ||
*/ | ||
userReset: spamPrevention.userReset.getMiddleware({ | ||
ignoreIP: true, | ||
ignoreIP: false, | ||
key: function (req, res, next) { | ||
req.authInfo = req.authInfo || {}; | ||
req.authInfo.ip = req.connection.remoteAddress; | ||
// prevent too many attempts for the same email address but keep separate to login brute force prevention | ||
next(req.authInfo.ip + req.body.username + 'reset'); | ||
next(req.body.username + 'reset'); | ||
} | ||
}), | ||
privateBlog: spamPrevention.privateBlog.getMiddleware({ | ||
ignoreIP: true, | ||
ignoreIP: false, | ||
key: function (req, res, next) { | ||
req.authInfo = req.authInfo || {}; | ||
req.authInfo.ip = req.connection.remoteAddress; | ||
// prevent too many attempts for the same email address but keep separate to login brute force prevention | ||
next(req.authInfo.ip + 'private'); | ||
next('privateblog'); | ||
} | ||
}) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters