Repository navigation
Conversation
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.
commit: |
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 detectedLatest commit: 476f20a The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
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 |
| 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); |
There was a problem hiding this comment.
🔴 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
| await expect(build(project(), wrong, cache)).rejects.toThrow(refused); | ||
| expect(requests).toEqual([`/${TAG}/SHA256SUMS`, `/${TAG}/remote-exec-linux-x86_64`]); |
There was a problem hiding this comment.
ben-reitz
left a comment
There was a problem hiding this comment.
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
remoteExec()downloads the remote-exec builds from the@cloudflare/computerGitHub release and checks each against the release'sSHA256SUMS. 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 abuildsdirectory.This lets the plugin do it.
sha256takes the hash each build must have, by architecture, copied from the release'sSHA256SUMSwhen you install or bump@cloudflare/computer: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 inarchhas no pin, or a pin isn't a hex SHA-256. Withoutsha256, nothing changes.Testing
remote-exec.test.tsbuilds 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.