From d122863cac529f5c7cc2865b766f7c4a33f468ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6ran=20Sander?= Date: Wed, 28 Aug 2024 19:59:22 +0000 Subject: [PATCH] fix(sense-events): Better handling of unknown UDP messages Fixes #880 --- src/lib/udp_handlers_log_events.js | 18 ++++++++++++++++++ src/lib/udp_handlers_user_activity.js | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/lib/udp_handlers_log_events.js b/src/lib/udp_handlers_log_events.js index b5b61f30..2e3a9417 100644 --- a/src/lib/udp_handlers_log_events.js +++ b/src/lib/udp_handlers_log_events.js @@ -89,6 +89,24 @@ export function udpInitLogEventServer() { `LOG EVENT: ${msg[0]}:${msg[5]}:${msg[4]}, ${msg[6]}: ${msg[8]}` ); + // Check if the message is a log event message we recognise + // If not, log a warning and return + // Take into account that msg[0] may be undefined, so check for that first + if ( + msg[0] === undefined || + (msg[0].toLowerCase() !== '/qseow-engine/' && + msg[0].toLowerCase() !== '/qseow-proxy/' && + msg[0].toLowerCase() !== '/qseow-repository/' && + msg[0].toLowerCase() !== '/qseow-scheduler/') + ) { + // Show warning, include first 512 characters of the message + const msgShort = message.toString().substring(0, 512); + globals.logger.warn( + `LOG EVENT: Received message that is not a recognised log event: ${msgShort}` + ); + return; + } + // Check if any of the log event sources are enabled in the configuration if ( (globals.config.get('Butler-SOS.logEvents.source.engine.enable') === true && diff --git a/src/lib/udp_handlers_user_activity.js b/src/lib/udp_handlers_user_activity.js index 2456ba31..4ceb4d1c 100644 --- a/src/lib/udp_handlers_user_activity.js +++ b/src/lib/udp_handlers_user_activity.js @@ -64,6 +64,22 @@ export function udpInitUserActivityServer() { msg[0] = msg[0].toLowerCase().replace('/', ''); msg[0] = msg[0].replace('/', ''); + // Check if the message is a user event message we recognise + // If not, log a warning and return + // Take into account that msg[0] may be undefined, so check for that first + if ( + msg[0] === undefined || + (msg[0].toLowerCase() !== 'qseow-proxy-connection' && + msg[0].toLowerCase() !== 'qseow-proxy-session') + ) { + // Show warning, include first 512 characters of the message + const msgShort = message.toString().substring(0, 512); + globals.logger.warn( + `USER EVENT: Received message that is not a recognised user event: ${msgShort}` + ); + return; + } + // Build object and convert to JSON let msgObj; if (msg[0] === 'qseow-proxy-connection' || msg[0] === 'qseow-proxy-session') {