plugin/antibrute: reset delay after successful login
Massimo Melina committed
May 2, 2024 at 17:53 UTC
336a96e868612f618d23f7645a6d2c267d9e5a8c
1 file changed
+5
-2
plugins/antibrute/plugin.js
+5
-2
@@ -1,4 +1,4 @@
1
-exports.version = 2
1
+exports.version = 2.1
2
exports.description = "Introduce increasing delays between login attempts."
3
exports.apiRequired = 3 // log
4
@@ -15,10 +15,13 @@ const byIp = {}
15
exports.init = api => {
16
const LOGIN_URI = api.Const.API_URI + 'loginSrp1'
17
const { getOrSet } = api.require('./misc')
18
+ const { getCurrentUsername } = api.require('./auth')
19
return {
20
async middleware(ctx) {
20
- if (ctx.path !== LOGIN_URI) return
21
const { ip } = ctx
22
+ if (getCurrentUsername(ctx)) // login was successful
23
+ delete byIp[ip]
24
+ if (ctx.path !== LOGIN_URI) return
25
const now = Date.now()
26
const rec = getOrSet(byIp, ip, () => ({ delay: 0, next: now }))
27
const wait = rec.next - now