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);