AsyncEvents/ServerSideEvents: prevent internal DOS by prevent overflowing messageQueue (#621)

* Prevent tcp/wifi DOS lockup by preventing number of messages in queue, drop otherwise

* Define (renamed) MAX_SSE_Clients
This commit is contained in:
Arjan Filius 2019-10-17 09:05:13 +02:00 committed by Me No Dev
parent a84f16989a
commit f13685ee97
2 changed files with 25 additions and 4 deletions

View File

@ -184,10 +184,14 @@ void AsyncEventSourceClient::_queueMessage(AsyncEventSourceMessage *dataMessage)
delete dataMessage;
return;
}
_messageQueue.add(dataMessage);
_runQueue();
if(_messageQueue.length() >= SSE_MAX_QUEUED_MESSAGES){
ets_printf("ERROR: Too many messages queued\n");
delete dataMessage;
} else {
_messageQueue.add(dataMessage);
}
if(_client->canSend())
_runQueue();
}
void AsyncEventSourceClient::_onAck(size_t len, uint32_t time){

View File

@ -23,11 +23,28 @@
#include <Arduino.h>
#ifdef ESP32
#include <AsyncTCP.h>
#define SSE_MAX_QUEUED_MESSAGES 32
#else
#include <ESPAsyncTCP.h>
#define SSE_MAX_QUEUED_MESSAGES 8
#endif
#include <ESPAsyncWebServer.h>
#include "AsyncWebSynchronization.h"
#ifdef ESP8266
#include <Hash.h>
#ifdef CRYPTO_HASH_h // include Hash.h from espressif framework if the first include was from the crypto library
#include <../src/Hash.h>
#endif
#endif
#ifdef ESP32
#define DEFAULT_MAX_SSE_CLIENTS 8
#else
#define DEFAULT_MAX_SSE_CLIENTS 4
#endif
class AsyncEventSource;
class AsyncEventSourceResponse;
class AsyncEventSourceClient;