Skip to content

fix(ota): reject update requests with an invalid version - #598

Open
hhvrc wants to merge 1 commit into
developfrom
fix/ota-version-validation
Open

hhvrc wants to merge 1 commit into
developfrom
fix/ota-version-validation

Conversation

@hhvrc

@hhvrc hhvrc commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

What does this change?

The gateway's OtaUpdateRequest handler built an OpenShock::SemVer straight from the message's prerelease and build strings without calling SemVer::isValid(), which until now was only used by host tests. OtaUpdateManager::TryGetFirmwareRelease later formats that version into the firmware repository URL path with SEMVER_FMT, so a string containing /, .., ? or # could change the path or query of the request, pointing the hub at a different manifest on that host. The bad version was also logged and persisted.

The version is now checked with SemVer::isValid():

  • in the gateway handler, before it is logged or used;
  • in OtaUpdateManager::TryStartFirmwareUpdate, which every update request goes through before the version reaches the URL, so later callers are covered too.

Resolves code scanning alert #10 (CWE-20).

This touches firmware updates: valid versions take the same path as before; only versions outside the SemVer grammar TryParseSemVer already accepts are refused.

How was it tested?

  • Formatted with clang-format 21 (the CI version).
  • Not yet built or run on hardware. To check: an OTA update to a normal release version (e.g. 1.5.0, 1.5.0-rc.1) still starts; a version with / in its prerelease is rejected with "OTA update requested with an invalid version".

Checklist

  • The change is focused on one thing.
  • Tests, formatter and linter pass locally.
  • Documentation is updated where behaviour changed.
  • No secrets, credentials or personal data are included.
  • If this touches device control, limits, sharing, authentication or firmware updates, the description says so and explains how it was tested.

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).
@coderabbitai

coderabbitai Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 58 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e9dbf9aa-9d85-484a-9937-1b09baa35a01
Commits

Reviewing files that changed from the base of the PR and between d416e19 and d883a70.

Files selected for processing: 3

  • .changes/ota-version-validation.md
  • components/core/src/message_handlers/websocket/gateway/OtaUpdateRequest.cpp
  • components/ota/src/OtaUpdateManager.cpp
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

github-actions Bot commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Change file check

✅ OK: 1 valid change file(s) added in this PR.

Version impact: patch bump (fix). The next release stays 2.0.0 (latest stable: 1.6.0).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant