From d883a7040518c00aad8f4763573063b2f6f4b47b Mon Sep 17 00:00:00 2001 From: HeavenVR Date: Sat, 5 Dec 2026 02:22:09 +0100 Subject: [PATCH] fix(ota): reject update requests with an invalid version The gateway OTA handler built a SemVer from the message's prerelease and build strings without validating them, and the version is later formatted into the firmware repository URL path. A string with '/', '..', '?' or '#' could change the requested path or query on that host. Validate with SemVer::isValid() in the handler and again in OtaUpdateManager::TryStartFirmwareUpdate, which every update request passes through. Resolves code scanning alert #10 (CWE-20). --- .changes/ota-version-validation.md | 11 +++++++++++ .../websocket/gateway/OtaUpdateRequest.cpp | 4 ++++ components/ota/src/OtaUpdateManager.cpp | 6 ++++++ 3 files changed, 21 insertions(+) create mode 100644 .changes/ota-version-validation.md diff --git a/.changes/ota-version-validation.md b/.changes/ota-version-validation.md new file mode 100644 index 000000000..6a7c4514b --- /dev/null +++ b/.changes/ota-version-validation.md @@ -0,0 +1,11 @@ +--- +kind: security +--- +Reject OTA update requests with an invalid version + +## Release Note +Firmware updates reject malformed version numbers + +An update request whose version is not a valid version number is now refused, so it can no longer change which file the hub downloads. + +- The gateway OTA handler and OtaUpdateManager::TryStartFirmwareUpdate both call SemVer::isValid() before the version reaches the firmware repository URL diff --git a/components/core/src/message_handlers/websocket/gateway/OtaUpdateRequest.cpp b/components/core/src/message_handlers/websocket/gateway/OtaUpdateRequest.cpp index d1bb6108e..e8a34deab 100644 --- a/components/core/src/message_handlers/websocket/gateway/OtaUpdateRequest.cpp +++ b/components/core/src/message_handlers/websocket/gateway/OtaUpdateRequest.cpp @@ -32,6 +32,10 @@ void _Private::HandleOtaUpdateRequest(OpenShock::GatewayClient&, const OpenShock } OpenShock::SemVer version(semver->major(), semver->minor(), semver->patch(), prerelease, build); + if (!version.isValid()) { + OS_LOGE(TAG, "OTA update requested with an invalid version"); + return; + } OS_LOGI( TAG, diff --git a/components/ota/src/OtaUpdateManager.cpp b/components/ota/src/OtaUpdateManager.cpp index dad9a88c5..959da8793 100644 --- a/components/ota/src/OtaUpdateManager.cpp +++ b/components/ota/src/OtaUpdateManager.cpp @@ -815,6 +815,12 @@ std::optional OtaUpdateManager::TryGetFirmwar bool OtaUpdateManager::TryStartFirmwareUpdate(const OpenShock::SemVer& version) { + // The version ends up in the firmware repository URL path: only the SemVer grammar may get there + if (!version.isValid()) { + OS_LOGE(TAG, "Rejecting firmware update to an invalid version"); + return false; + } + OS_LOGD(TAG, "Requesting firmware version " SEMVER_FMT, SEMVER_ARG(version)); return otaum_try_queue_update_request(version);