Skip to content

computer: Let the remoteExec plugin check builds against pinned hashes - #347

Open
scuffi wants to merge 2 commits into
mainfrom
computer/remote-exec-pinned-hashes
Open

scuffi wants to merge 2 commits into
mainfrom
computer/remote-exec-pinned-hashes

Conversation

@scuffi

@scuffi scuffi commented Nov 25, 2026

Copy link
Copy Markdown
Member

remoteExec() downloads the remote-exec builds from the @cloudflare/computer GitHub release and checks each against the release's SHA256SUMS. That file comes from the same release as the builds, so it catches a broken download, but not a release whose assets were replaced after it was published: the new sums match the new builds. The builds run as root in the consumer's containers, so a consumer that wants more pins the hashes in its own repository. Today that means not using the plugin's download: it fetches the builds with a script of its own, checks them against its pins, and hands the plugin a builds directory.

This lets the plugin do it. sha256 takes the hash each build must have, by architecture, copied from the release's SHA256SUMS when you install or bump @cloudflare/computer:

remoteExec({
  arch: ["x86_64", "aarch64"],
  sha256: {
    x86_64: "70290a39f2c5c8fa918debd1312ab003bb6e7b9665ec185d9a8fde56ca278e9d",
    aarch64: "6c41ea200a74beda1343063841d0f3fa47f84a0645b8765bc6ff401be4154e75",
  },
});

With it, every build the plugin uses is checked against its pin, whether it was just downloaded, came from Vite's cache, or from builds, so a cache filled before the pin changed can't slip past it. A mismatch fails the build and says to pin the hashes of the release in use, which is also what happens when you bump the package and forget the pins. The plugin throws when it's created if an architecture in arch has no pin, or a pin isn't a hex SHA-256. Without sha256, nothing changes.

Testing

remote-exec.test.ts builds a fixture Worker against a local release server: pinned builds go through, a wrong pin is refused on download, from the cache with no new requests, and for local builds, and a missing or malformed pin throws when the plugin is created.

The remoteExec() Vite plugin checks each build it downloads against the
release's SHA256SUMS. That file comes from the same release as the
builds, so it catches a broken download, but not a release whose
assets were replaced after it was published: the new sums would match
the new builds. A consumer that wanted more downloaded the builds with
a script of its own, against hashes pinned in its repository, and
handed them to the plugin as local builds.

The plugin now takes `sha256`, the hash each build must have by
architecture, and refuses any build that doesn't match, downloaded,
cached or local. It needs one for every architecture it carries, so a
pin can't be left out by mistake.
@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@cloudflare/computer@347

commit: 476f20a

@scuffi
scuffi marked this pull request as ready for review November 27, 2026 10:48
devin-ai-integration[bot]

This comment was marked as resolved.

A build cached before its release was replaced never downloaded
again, so updating the pin to the new release's hash couldn't fix the
build. A cached build that doesn't match its pin is now downloaded
again, and checked against SHA256SUMS and the pin as usual.

Two builds in one process share the cache, and one could replace a
file after the other checked it, so the bundle could carry bytes that
were never checked. A build that matches its pin is now kept under
its hash and served from there. Pins may be upper case, as some tools
print them, and the changeset and the remote-exec example point at the
docs.
@changeset-bot

changeset-bot Bot commented Nov 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 476f20a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@cloudflare/computer Patch
@cloudflare/dofs Patch
@cloudflare/computer-rpc Patch
@cloudflare/computerd Patch
@cloudflare/remote-exec Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Devin Review found 2 new potential issues.

Devin Review

Comment on lines +276 to +279
for (const file of files) {
const cached = await exists(file.path);
if (!cached || (pinned !== undefined && (await sha256Of(file.path)) !== pinned[file.arch]))
missing.push(file);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 Rejected refresh evicts the cached build

After a release is replaced, download overwrites the version cache even if checkPinned rejects the replacement. Subsequent builds with the original pin fail because download ignores the verified copy stored under that pin.

Learn more

The version cache holds one build per package version and architecture. When that build differs from the requested pin, download fetches a replacement and writes it to the version cache after checking only the release's SHA256SUMS. checkPinned runs afterward, so rejecting the replacement does not undo the write. It stores verified copies under their hashes, but download never looks there. Even a successful refresh with a new pin prevents a later build using the original pin from reusing its verified copy.

Example: Build version 1.0.0 with pin A to warm the cache. The release replaces A with B. Build with a mistyped pin C, then restore pin A. The C build rejects B but leaves B in the version cache. The A build downloads B again and fails even though the verified A file is still on disk.

Recommended fix: Resolve pinned downloads from the hash-keyed cache first and verify the bytes before reuse. On a miss, check the existing version cache and then the release. Verify downloaded bytes against both the release checksum and the requested pin before publishing them to the hash-keyed cache. Leave the version-only cache unchanged during pinned refreshes so a rejected refresh cannot affect other builds.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +260 to +261
await expect(build(project(), wrong, cache)).rejects.toThrow(refused);
expect(requests).toEqual([`/${TAG}/SHA256SUMS`, `/${TAG}/remote-exec-linux-x86_64`]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔍 Cache test contradicts testing summary

The testing summary says a cached wrong pin makes no requests. The requests assertion expects both the checksum request and the binary download before the build rejects the pin.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@ben-reitz ben-reitz 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.

I think this is a good idea but if I'm understanding it right, this approach means that anytime someone bumps @cloudflare/computer, they have to manually copy to the 2 hashes by hand from the releases page (or get their agent to do it obvs). plus I assume any auto updates like their dependabot PRs will fail the build until someone does that too.

could we make it so the package itself carries the hashes? the release workflow builds the binaries before changeset publish, so we actually know the sums when we publish. the plugin could check downloads against sums shipped in the npm package, which the consumer's lockfile already pins. that would protect everyone by default, with no extra options and nothing for them to think about on a version bump.

the hashes would need to go in the npm package (rather than the GitHub release). the release already has them as SHA256SUMS, which is the file that can be replaced along with the binaries.

the only ohter thing I'd add is a check in the workflow's upload step to compare the rebuilt binaries against the sums in the package before uploading, and fail the run if they differ. otherwise we'll cause problems with peoples' upgrades

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