2323import org .apache .logging .log4j .LogManager ;
2424import org .apache .logging .log4j .Logger ;
2525import org .b3log .latke .util .Execs ;
26+ import org .b3log .symphony .cache .UserCache ;
2627
2728import java .util .Map ;
2829import java .util .Set ;
@@ -84,6 +85,7 @@ public static boolean recordAndMaybeBan(final String ip) {
8485 }
8586
8687 final long nowBucket = System .currentTimeMillis () / WINDOW_MILLIS ;
88+ final int effectiveThreshold = UserCache .hasUserByIP (ip ) ? threshold : Math .min (threshold , 250 );
8789 final Counter counter = COUNTERS .compute (ip , (key , existing ) -> {
8890 if (existing == null || existing .bucket != nowBucket ) {
8991 return new Counter (nowBucket , 1 );
@@ -97,7 +99,7 @@ public static boolean recordAndMaybeBan(final String ip) {
9799 cleanupOldBuckets (nowBucket );
98100 }
99101
100- if (counter .count .sum () > threshold && BANNED .add (ip )) {
102+ if (counter .count .sum () > effectiveThreshold && BANNED .add (ip )) {
101103 // Run ban asynchronously on a virtual thread to keep request path light.
102104 Thread .startVirtualThread (() -> {
103105 try {
@@ -110,7 +112,7 @@ public static boolean recordAndMaybeBan(final String ip) {
110112 return false ;
111113 }
112114
113- System .out .println ("CC firewall allowed " + ip + " [" + counter .count + "]" );
115+ System .out .println ("CC firewall allowed " + ip + " [" + counter .count . sum () + "]" );
114116
115117 return !BANNED .contains (ip );
116118 }
0 commit comments