From 9c4424fbdd2d226012979651e93c35b9f2b46ec5 Mon Sep 17 00:00:00 2001 From: ElektroVodka <211697683+Elektr0Vodka@users.noreply.github.com> Date: Tue, 1 Dec 2026 21:31:23 +0100 Subject: [PATCH] fix(observer): check the OTA image URL, honour radio.watchdog on room servers The observer pull-OTA flashed whatever HTTPS `file` URL the manifest named, on any host. The companion OTA already refuses that with ota_firmware_url_allowed(). The observer now applies the same rule to the manifest base it fetched from: ".../mqtt/v" may only point under ".../mqtt/fw/", ".../mqtt/dev/v" only under ".../mqtt/dev/fw/", and the image must be https. All 140 live manifests (70 envs, stable and dev) already follow this layout (checked 2026-12-01), so no server change is needed. The room server had no getRadioWatchdogMillis() override, so `set radio.watchdog N` replied OK there and the watchdog stayed at 5 minutes. Also runs native_ota_channel in the unit-test workflow; test_ota_channel never ran in CI. --- .github/workflows/run-unit-tests.yml | 2 +- examples/simple_room_server/MyMesh.h | 5 +++++ src/helpers/ESP32ManifestOTA.cpp | 8 ++++++++ test/test_ota_manifest/test_ota_manifest.cpp | 17 +++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) diff --git a/.github/workflows/run-unit-tests.yml b/.github/workflows/run-unit-tests.yml index 0d42e9cf4d9..a620176f60f 100644 --- a/.github/workflows/run-unit-tests.yml +++ b/.github/workflows/run-unit-tests.yml @@ -28,7 +28,7 @@ jobs: run: python3 -B -m unittest discover -s scripts/tests -p 'test_*.py' -v - name: Run Unit Tests - run: pio test -e native -e native_kiss_modem -e native_region_gating -e native_jwt_helper -vv + run: pio test -e native -e native_kiss_modem -e native_region_gating -e native_jwt_helper -e native_ota_channel -vv - name: Upload Test Results # Upload test results even if the test step failed. diff --git a/examples/simple_room_server/MyMesh.h b/examples/simple_room_server/MyMesh.h index cfbdf000f75..f3ca8902798 100644 --- a/examples/simple_room_server/MyMesh.h +++ b/examples/simple_room_server/MyMesh.h @@ -259,6 +259,11 @@ class MyMesh : public mesh::Mesh, public CommonCLICallbacks int getAGCResetInterval() const override { return ((int)_prefs.agc_reset_interval) * 4000; // milliseconds } +#ifdef WITH_MQTT_BRIDGE + uint32_t getRadioWatchdogMillis() const override { + return ((uint32_t)_cli.getObserverPrefs()->radio_watchdog_minutes) * 60000UL; + } +#endif uint8_t getExtraAckTransmitCount() const override { return _prefs.multi_acks; } diff --git a/src/helpers/ESP32ManifestOTA.cpp b/src/helpers/ESP32ManifestOTA.cpp index 664770f144a..64faee1da51 100644 --- a/src/helpers/ESP32ManifestOTA.cpp +++ b/src/helpers/ESP32ManifestOTA.cpp @@ -27,6 +27,7 @@ #include #include "OtaChannel.h" #include "OtaCheckPolicy.h" +#include "OtaManifest.h" #include static portMUX_TYPE ota_check_mux = portMUX_INITIALIZER_UNLOCKED; @@ -363,6 +364,13 @@ bool ESP32Board::otaFromManifestImpl(const char* manifest_base, const char* curr strcpy(reply, "ERR: manifest missing file"); return false; } + // Only flash an image from this channel's firmware path on the same server, + // over TLS (".../mqtt/v" -> ".../mqtt/fw/", ".../mqtt/dev/v" -> ".../mqtt/dev/fw/"), + // so a tampered or mistaken manifest cannot point the device at another host. + if (!ota_url_is_https(file_url) || !ota_firmware_url_allowed(file_url, manifest_base)) { + strcpy(reply, "ERR: manifest file URL not allowed"); + return false; + } // Partition compatibility: prefer the precise per-build signature — compare the // target build's partition layout (manifest partSig) to what's actually flashed diff --git a/test/test_ota_manifest/test_ota_manifest.cpp b/test/test_ota_manifest/test_ota_manifest.cpp index e6bde2990eb..0518afc9b6c 100644 --- a/test/test_ota_manifest/test_ota_manifest.cpp +++ b/test/test_ota_manifest/test_ota_manifest.cpp @@ -138,6 +138,23 @@ TEST(OtaUrl, FirmwareElsewhereIsRefused) { EXPECT_FALSE(ota_firmware_url_allowed(nullptr, BASE)); } +// The observer pull-OTA applies the same rule to its own channels. These are the +// layouts the live stable and dev manifests use (checked 2026-12-01). +TEST(OtaUrl, ObserverChannelsAllowOnlyTheirOwnFwPath) { + const char* stable = "https://ota.dutchmeshcore.nl/mqtt/v"; + const char* dev = "https://ota.dutchmeshcore.nl/mqtt/dev/v"; + const char* stable_fw = + "https://ota.dutchmeshcore.nl/mqtt/fw/dmc-repeater-mqtt-v1.18.0.1/heltec_v4_repeater_observer_mqtt-v1.18.0.1-f314fba.bin"; + const char* dev_fw = + "https://ota.dutchmeshcore.nl/mqtt/dev/fw/observer-mqtt-dev/heltec_v4_repeater_observer_mqtt-v1.18.0.1-f314fba.bin"; + EXPECT_TRUE(ota_firmware_url_allowed(stable_fw, stable)); + EXPECT_TRUE(ota_firmware_url_allowed(dev_fw, dev)); + // a channel's manifest cannot hand out the other channel's images, or another product's + EXPECT_FALSE(ota_firmware_url_allowed(stable_fw, dev)); + EXPECT_FALSE(ota_firmware_url_allowed(dev_fw, stable)); + EXPECT_FALSE(ota_firmware_url_allowed("https://ota.dutchmeshcore.nl/meshcomod/fw/a/b.bin", stable)); +} + TEST(OtaUrl, BaseWithoutTrailingVAllowsNothing) { EXPECT_FALSE(ota_firmware_url_allowed("https://ota.dutchmeshcore.nl/meshcomod/fw/a.bin", "https://ota.dutchmeshcore.nl/meshcomod"));