only log possible dos attack if >5 throttled messages (#1946)

This commit is contained in:
woodser 2025-09-09 09:21:13 -04:00 committed by GitHub
parent 171acd5221
commit 729b5a3a74
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 6 additions and 5 deletions

View file

@ -117,6 +117,7 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
private static final int SOCKET_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(240);
private static final int SHUTDOWN_TIMEOUT = 100;
private static final String THREAD_ID = Connection.class.getSimpleName();
public static final int POSSIBLE_DOS_THRESHOLD = 5;
public static int getPermittedMessageSize() {
return PERMITTED_MESSAGE_SIZE;
@ -656,7 +657,7 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
private static synchronized void resetReportedInvalidRequestsThrottle(boolean logReport) {
if (logReport) {
if (numThrottledInvalidRequestReports > 0) log.warn("Possible DoS attack detected. We received {} other reports of invalid requests since the last log entry", numThrottledInvalidRequestReports);
if (numThrottledInvalidRequestReports > 0) log.warn("We received {} throttled reports of invalid requests since the last log entry" + (numThrottledInvalidRequestReports >= POSSIBLE_DOS_THRESHOLD ? ". Possible DoS attack detected" : ""), numThrottledInvalidRequestReports);
numThrottledInvalidRequestReports = 0;
lastLoggedInvalidRequestReportTs = System.currentTimeMillis();
}
@ -942,7 +943,7 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
boolean doLog = System.currentTimeMillis() - lastLoggedWarningTs > LOG_THROTTLE_INTERVAL_MS;
if (doLog) {
log.warn(msg);
if (numThrottledWarnings > 0) log.warn("Possible DoS attack detected. {} warnings were throttled since the last log entry", numThrottledWarnings);
if (numThrottledWarnings > 0) log.warn("We received {} throttled warnings since the last log entry" + (numThrottledWarnings >= POSSIBLE_DOS_THRESHOLD ? ". Possible DoS attack detected" : ""), numThrottledWarnings);
numThrottledWarnings = 0;
lastLoggedWarningTs = System.currentTimeMillis();
} else {
@ -954,7 +955,7 @@ public class Connection implements HasCapabilities, Runnable, MessageListener {
boolean doLog = System.currentTimeMillis() - lastLoggedInfoTs > LOG_THROTTLE_INTERVAL_MS;
if (doLog) {
log.info(msg);
if (numThrottledInfos > 0) log.info("Possible DoS attack detected. {} info logs were throttled since the last log entry", numThrottledInfos);
if (numThrottledInfos > 0) log.warn("We received {} throttled info logs since the last log entry" + (numThrottledInfos >= POSSIBLE_DOS_THRESHOLD ? ". Possible DoS attack detected" : ""), numThrottledInfos);
numThrottledInfos = 0;
lastLoggedInfoTs = System.currentTimeMillis();
} else {

View file

@ -173,7 +173,7 @@ class KeepAliveHandler implements MessageListener {
boolean logWarning = System.currentTimeMillis() - lastLoggedWarningTs > LOG_THROTTLE_INTERVAL_MS;
if (logWarning) {
log.warn(msg);
if (numThrottledWarnings > 0) log.warn("Possible DoS attack detected. {} warnings were throttled since the last log entry", numThrottledWarnings);
if (numThrottledWarnings > 0) log.warn("We received {} throttled warnings since the last log entry" + (numThrottledWarnings >= Connection.POSSIBLE_DOS_THRESHOLD ? ". Possible DoS attack detected" : ""), numThrottledWarnings);
numThrottledWarnings = 0;
lastLoggedWarningTs = System.currentTimeMillis();
} else {

View file

@ -222,7 +222,7 @@ class PeerExchangeHandler implements MessageListener {
boolean logWarning = System.currentTimeMillis() - lastLoggedWarningTs > LOG_THROTTLE_INTERVAL_MS;
if (logWarning) {
log.warn(msg);
if (numThrottledWarnings > 0) log.warn("Possible DoS attack detected. {} warnings were throttled since the last log entry", numThrottledWarnings);
if (numThrottledWarnings > 0) log.warn("We received {} throttled warnings since the last log entry" + (numThrottledWarnings >= Connection.POSSIBLE_DOS_THRESHOLD ? ". Possible DoS attack detected" : ""), numThrottledWarnings);
numThrottledWarnings = 0;
lastLoggedWarningTs = System.currentTimeMillis();
} else {