Skip to content

Commit eff9eb6

Browse files
committed
add time for blocking user in abuseDetected system
1 parent 56a508a commit eff9eb6

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ const config = {
2828
},
2929
authAttempts: {
3030
forIp: 50,
31-
forIpAndUser: 7
31+
forIpAndUser: 7,
32+
durationOfBlocking: 24
3233
},
3334
jwt: {
3435
secret: {

server/modules/login/auth-attempt.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@ class AuthAttempt extends MongoModels {
2020
Assert.ok(ip, 'Missing ip argument.');
2121
Assert.ok(username, 'Missing username argument.');
2222

23+
const config = Config.get('/authAttempts');
24+
const duration = new Date(Date.now() - config.durationOfBlocking * 60 * 60 * 1000);
25+
2326
const [countByIp, countByIpAndUser] = await Promise.all([
24-
this.count({ ip }),
25-
this.count({ ip, username })
27+
this.count({ ip, timeCreated: { $gt: duration } }),
28+
this.count({ ip, username, timeCreated: { $gt: duration } })
2629
]);
27-
const config = Config.get('/authAttempts');
30+
2831
const ipLimitReached = countByIp >= config.forIp;
2932
const ipUserLimitReached = countByIpAndUser >= config.forIpAndUser;
3033

0 commit comments

Comments
 (0)