Disconnect agents that send the same console value in a loop.

Ylian Saint-Hilaire committed Jan 9, 2022 at 14:49 UTC aed785f14730057001e77115861a1f1f83f95102
1 file changed +11
meshagent.js
+11
@@ -1203,6 +1203,17 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1203 switch (command.action) {
1204 case 'msg':
1205 {
1206 + // If the same console command is processed many times, kick out this agent.
1207 + // This is a safety mesure to guard against the agent DOS'ing the server.
1208 + if (command.type == 'console') {
1209 + if (obj.consoleKickValue == command.value) {
1210 + if (obj.consoleKickCount) { obj.consoleKickCount++; } else { obj.consoleKickCount = 1; }
1211 + if (obj.consoleKickCount > 30) { obj.close(); return; } // 30 identical console messages received, kick out this agent.
1212 + } else {
1213 + obj.consoleKickValue = command.value;
1214 + }
1215 + }
1216 +
1217 // Route a message
1218 parent.routeAgentCommand(command, obj.domain.id, obj.dbNodeKey, obj.dbMeshKey);
1219 break;