Skip to content

fix(node): limit an OTA requestor to downloading the image it was offered - #5075

Open
Apollon77 wants to merge 1 commit into
mainfrom
fix/bdx-scope-direction
Open

Apollon77 wants to merge 1 commit into
mainfrom
fix/bdx-scope-direction

Conversation

@Apollon77

Copy link
Copy Markdown
Collaborator

Why

When the OTA provider offers an update over BDX, it registers the requestor for the update storage scope with BdxProtocol.enablePeerForScope(). The registration stored neither a transfer direction nor a file, and BdxProtocol accepts both SendInit and ReceiveInit. The requestor could therefore send a SendInit for ota/<any name> and write into the storage that holds the images for all requestors, including overwriting an image that is later offered to other nodes. It could also read stored images it was not offered. A new test reproduces the overwrite on the code before this change: the upload succeeds.

Design

  • BdxProtocol.Config gets two optional restrictions:

    • allowedInitMessages: the Init messages the peer may start a transfer with. Any other Init is answered with UNEXPECTED_MESSAGE, which is what the CHIP SDK answers for an Init in the wrong direction (BdxTransferSession.cpp, HandleTransferInit).
    • fileDesignators: the complete designators the peer may transfer. Any other designator is answered with FILE_DESIGNATOR_UNKNOWN, as the CHIP OTA provider does for an unknown designator.

    Both checks run before a BDX session is created, so a refused transfer starts no session and changes no OTA attempt state.

  • The OTA provider allows only ReceiveInit of the offered designator. The comparison is against the complete designator text, so variants with extra path parts or different encoding do not match.

  • Without the new fields a registration behaves as before. enablePeerForScope is part of the public API, and a permissive default keeps external callers working; the OTA provider is the only caller in this repository.

  • Registrations stay per peer and scope, so parallel OTA transfers to different nodes keep working; a new test runs two downloads at the same time.

  • Behaviour change: if a requestor is offered a different image while its own transfer still runs, the registration differs and enablePeerForScope returns false, so the provider answers Busy. A node has one software version, and admitQuery already refuses or closes most of these overlaps earlier, so this is a narrow case.

  • A refused transfer now logs at info instead of warn, because a peer can repeat it.

Tests

  • BdxTest: a SendInit on a ReceiveInit-only scope, a ReceiveInit for an existing file outside fileDesignators, and a transfer that both restrictions allow.
  • OtaTest: after a real offer, the requestor opens its own BDX exchange and tries to overwrite the offered image, to write a new file, and to read a stored image it was not offered. Each is refused with the expected status, the storage content is unchanged, and the requestor's own download and apply still complete. A characterization test runs two requestor downloads in parallel.
  • Each new check was reverted once to confirm a test fails.

Verification

npm run build         -> exit 0
npm run format-verify -> exit 0
npm run lint          -> exit 0
npm test -- esm       -> exit 0, all 12 packages

🤖 Generated with Claude Code

…ered

After an offer, the OTA provider enabled BDX for the requestor on the
update storage without a transfer direction or file restriction. The
requestor could therefore send a SendInit and write any file into the
storage that all requestors share, including an image offered to other
nodes, or read images it was not offered.

BdxProtocol.Config gets allowedInitMessages and fileDesignators. An Init
message the registration does not allow is answered with
UNEXPECTED_MESSAGE, as the CHIP SDK does for an Init in the wrong
direction; a designator outside the list gets FILE_DESIGNATOR_UNKNOWN.
The OTA provider allows only ReceiveInit of the offered image. Without
the new fields a registration keeps its old behaviour.

A refused transfer now logs at info, because a peer can repeat it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 28, 2026 18:15
@mergify

mergify Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue). If it does not match the queue conditions yet, it enters the queue once it does.

  • Queue this pull request once it meets the queue conditions

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues were identified for the change restricting OTA requestors to downloading only their offered image.

No open issues 🎉

What changed in this PR

This PR restricts OTA requestors to downloading only their offered image, preventing uploads into shared update storage and reads of other images. It adds optional BDX restrictions while preserving existing behavior for callers that omit them.

Changes:

  • Add transfer-direction and exact file-designator checks before creating a BDX session.
  • Configure the OTA provider to allow only downloads of the offered image.
  • Add regression tests for refused transfers, unchanged storage, successful downloads, and parallel requestors.

The PR reports successful build, formatting, lint, and ESM tests across all 12 packages. These checks were not rerun here.

File Description
packages/​protocol/​test/​bdx/​BdxTest.ts Tests direction restrictions, file restrictions, and permitted transfers.
packages/​protocol/​test/​bdx/​bdx-helpers.ts Accepts protocol-level restrictions in the transfer helper.
packages/​protocol/​src/​bdx/​BdxProtocol.ts Adds optional restrictions and logs refused transfers at info level.
packages/​node/​test/​behaviors/​ota/​OtaTest.ts Tests unauthorized transfers, storage integrity, and parallel downloads.
packages/​node/​src/​behaviors/​ota-software-update-provider/​OtaSoftwareUpdateProviderServer.ts Limits each requestor to downloading its offered image.
CHANGELOG.md Documents the OTA protection and new BDX configuration options.

Review effort: Balanced

@Apollon77 Apollon77 added automerge Set this label if the PR is ready to automatically merged after approval and removed automerge Set this label if the PR is ready to automatically merged after approval labels Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants