From 3789183ca302942b640efd0e479cf4d4cfe4dd46 Mon Sep 17 00:00:00 2001 From: Thomas Basler Date: Wed, 3 Aug 2022 21:23:22 +0200 Subject: [PATCH] Fix #45: Dont allow spaces in MQTT topics --- src/WebApi_mqtt.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/WebApi_mqtt.cpp b/src/WebApi_mqtt.cpp index 08bc9130..92eb7896 100644 --- a/src/WebApi_mqtt.cpp +++ b/src/WebApi_mqtt.cpp @@ -141,6 +141,13 @@ void WebApiMqttClass::onMqttAdminPost(AsyncWebServerRequest* request) return; } + if (root[F("mqtt_topic")].as().indexOf(' ') != -1) { + retMsg[F("message")] = F("Topic must not contain space characters!"); + response->setLength(); + request->send(response); + return; + } + if (root[F("mqtt_port")].as() == 0 || root[F("mqtt_port")].as() > 65535) { retMsg[F("message")] = F("Port must be a number between 1 and 65535!"); response->setLength(); @@ -155,6 +162,13 @@ void WebApiMqttClass::onMqttAdminPost(AsyncWebServerRequest* request) return; } + if (root[F("mqtt_lwt_topic")].as().indexOf(' ') != -1) { + retMsg[F("message")] = F("LWT topic must not contain space characters!"); + response->setLength(); + request->send(response); + return; + } + if (root[F("mqtt_lwt_online")].as().length() > MQTT_MAX_LWTVALUE_STRLEN) { retMsg[F("message")] = F("LWT online value must not longer then " STR(MQTT_MAX_LWTVALUE_STRLEN) " characters!"); response->setLength(); @@ -183,6 +197,13 @@ void WebApiMqttClass::onMqttAdminPost(AsyncWebServerRequest* request) request->send(response); return; } + + if (root[F("mqtt_hass_topic")].as().indexOf(' ') != -1) { + retMsg[F("message")] = F("Hass topic must not contain space characters!"); + response->setLength(); + request->send(response); + return; + } } }