Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions pkg/fail2ban/fail2ban.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,28 @@
return true
}

if utime.Now().Before(ip.Viewed.Add(u.rules.Findtime)) {
if ip.Count+1 >= u.rules.MaxRetry {
u.IPs[remoteIP] = ipchecking.IPViewed{
Viewed: utime.Now(),
Count: ip.Count + 1,
Denied: true,
}

fmt.Printf("%q is banned for %d>=%d request",
remoteIP, ip.Count+1, u.rules.MaxRetry)

return false
}

u.IPs[remoteIP] = ipchecking.IPViewed{
Viewed: ip.Viewed,
Count: ip.Count + 1,
Denied: false,
}
return true

Check failure on line 184 in pkg/fail2ban/fail2ban.go

View workflow job for this annotation

GitHub Actions / Main Process

return with no blank line before (nlreturn)
}

fmt.Printf("welcome back %q", remoteIP)

return true
Comment on lines +165 to 189
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Bug: IP state is never reset when findtime expires, preventing future bans.

When the findtime window has elapsed (the if on line 165 is false), execution falls through to line 187 which returns true without resetting Viewed or Count. Because Viewed remains stuck at its old value, every subsequent call will also fail the findtime check on line 165 — the IP can never accumulate new counts toward a ban again.

ShouldAllow correctly handles this (lines 106–114) by resetting the IP entry. The same reset is needed here.

🐛 Proposed fix: reset IP state when findtime expires
 		return true
 	}
 
+	u.IPs[remoteIP] = ipchecking.IPViewed{
+		Viewed: utime.Now(),
+		Count:  0,
+		Denied: false,
+	}
+
 	fmt.Printf("welcome back %q", remoteIP)
 
 	return true

Note: Count is set to 0 (instead of 1 in ShouldAllow) to stay consistent with this function's initial-visit logic on line 132 which also uses Count: 0.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/fail2ban/fail2ban.go` around lines 165 - 189, When the findtime window
has elapsed the code currently returns true without resetting the IP entry, so
future calls never re-enter the counting window; update the else-path (the
branch after the utime.Now().Before(...) check that prints "welcome back") to
reset u.IPs[remoteIP] using an ipchecking.IPViewed struct (set Viewed to
utime.Now(), Count to 0, Denied to false) before returning true so the IP state
is cleared the same way ShouldAllow does.

Expand Down
Loading