fix: admin/logs: blocking an ip may result in a new rule instead of appending to an existing one, if before it another disabled rule is matched
Massimo Melina committed
Mar 18, 2025 at 10:14 UTC
f61056980f12879ce5e85c8f35689887a63bcc8a
1 file changed
+5
-4
src/block.ts
+5
-4
@@ -42,9 +42,10 @@ setInterval(() => { // twice a minute, check if any block has expired
42
export function addBlock(rule: BlockingRule, merge?: Partial<BlockingRule>) {
43
if (isIP(rule.ip) && isBlocked(rule.ip)) return // already
44
block.set(was => {
45
- const foundIdx = merge ? _.findIndex(was, merge) : -1
46
- return foundIdx < 0 || was[foundIdx]?.disabled ? [...was, { ...merge, ...rule }] // add as new rule
47
- : netMatches(rule.ip, was[foundIdx]!.ip) ? was // in case the rule is disabled, and isBlocked returned false
48
- : was.map((x, i) => i === foundIdx ? { ...x, ...rule, ip: `${x.ip}|${rule.ip}` } : x)
45
+ const match = merge && _.matches(merge)
46
+ const foundIdx = match ? _.findIndex(was, v => match(v) && !v.disabled) : -1
47
+ // in case the rule is disabled, and isBlocked returned false
48
+ return foundIdx < 0 ? [...was, { ...merge, ...rule }] // add as new rule
49
+ : was.map((x, i) => i === foundIdx ? { ...x, ...rule, ip: `${x.ip}|${rule.ip}` } : x)
50
})
51
}
\ No newline at end of file