Skip to content

fix(worker-build): verify the sha256 of downloaded tools - #1134

Open
rosalbito wants to merge 2 commits into
cloudflare:mainfrom
rosalbito:fix/worker-build-download-hashes
Open

rosalbito wants to merge 2 commits into
cloudflare:mainfrom
rosalbito:fix/worker-build-download-hashes

Conversation

@rosalbito

@rosalbito rosalbito commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor
  • Check the esbuild and wasm-opt archives against sha256 hashes pinned in worker-build/checksums.txt, and the wasm-bindgen archive against the .sha256sum its release publishes. A mismatch or a missing hash fails the build, names the URL and is not retried.
  • wasm-bindgen releases are immutable and npm doesn't allow a version to be republished, so for those two this is defense in depth. Binaryen releases and the emsdk tag can change, and those are the gaps this closes.
  • Fetch the emsdk archive by commit instead of by tag. What emsdk install fetches itself is unchanged.
  • worker-build/scripts/update-checksums.mjs regenerates the table from versions.rs. The README's release section says to run it when the esbuild, Binaryen or Emscripten version changes.

Tested with cargo test -p worker-build, clippy and fmt. Real downloads of esbuild 0.28.2, wasm-opt 133, wasm-bindgen 0.2.130 and the emsdk commit verified from an empty cache. macOS only.

Closes #1133

AI-generated with Claude, reviewed by me before posting.

Check the esbuild, wasm-opt and wasm-bindgen archives against sha256
hashes pinned in worker-build/checksums.txt before extracting them, and
fail on a mismatch. wasm-bindgen versions that are not pinned fall back
to the .sha256sum file their release publishes, with a warning. Fetch
the emsdk archive by commit instead of by tag.
@guybedford

Copy link
Copy Markdown
Member

I think it would help to have a clear description here first of the security model. Note that npm and GitHub releases are immutable for wasm-bindgen and esbuild. And since emsdk does its own install downloads, it seems the only real catch here is binaryen?

@rosalbito

Copy link
Copy Markdown
Contributor Author

You're right. wasm-bindgen releases are immutable from 0.2.120 (worker-build needs 0.2.122+), esbuild comes from npm, and what emsdk install downloads isn't worker-build's to check. Binaryen releases aren't immutable, so that's the one gap.

I can cut this down to a sha256 per target for the pinned Binaryen version, or close it if that isn't worth carrying for one tool. Which do you prefer?

AI-generated with Claude, reviewed by me before posting.

@guybedford guybedford left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for putting this together. I checked the table independently: all 46 GitHub-hosted hashes match the asset digests GitHub records, all 21 esbuild hashes match the npm tarballs and their registry integrity, and CUR_EMSDK_COMMIT is the commit the 6.0.10 tag points at.

One thing to frame this correctly: wasm-bindgen releases are immutable, and npm does not allow a version to be republished with different bytes, so for those two the URL is already effectively a pin. Binaryen releases are not immutable, and the emsdk tag could move, so those are where this closes a real gap. For the rest this is defense in depth, which I'm happy to take, but the upkeep should be proportionate to that.

With that in mind I'd like to simplify the wasm-bindgen handling:

  • Drop the wasm-bindgen rows from checksums.txt, and always verify the wasm-bindgen archive against the .sha256sum its release publishes. That keeps the table at a fixed 27 rows for the versions worker-build itself picks (esbuild and Binaryen), instead of growing by 5 rows per wasm-bindgen release, and avoids a warning for everyone on a wasm-bindgen newer than their worker-build.
  • Make a missing .sha256sum an error rather than a warning. Every supported wasm-bindgen release publishes one, so there should be no path where an archive is extracted unchecked.

Smaller points are inline.

Comment thread worker-build/checksums.txt Outdated
Comment on lines +3 to +42
36beadc86c5c02c511a152e8fc2c63850646887e97dc94ae04553640f839e808 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.122/wasm-bindgen-0.2.122-aarch64-apple-darwin.tar.gz
b1dfe472af0ee12cda087a0b28985df3b517415d9ae467cbcf851231bce856db https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.122/wasm-bindgen-0.2.122-aarch64-unknown-linux-musl.tar.gz
cb500a6b249c20474bbdd86d4d8d593fa65c9e5dbd56abb1ae7ee48c08390a11 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.122/wasm-bindgen-0.2.122-x86_64-apple-darwin.tar.gz
03ba3056eb0c2ad2d0d30a0c0edefb590656a1e237596226804abb87b71b77ad https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.122/wasm-bindgen-0.2.122-x86_64-pc-windows-msvc.tar.gz
122a3fe2ea9c6e3e89b50e42dd1a346e499f3f65a54aae0b4eaeb658139d1e0e https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.122/wasm-bindgen-0.2.122-x86_64-unknown-linux-musl.tar.gz
756065a71813819f21ff96e30a87404aa4d385002d77d0b6246fec1d6c66174f https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.123/wasm-bindgen-0.2.123-aarch64-apple-darwin.tar.gz
e7ac03e02ad6a8d167ed0877a35a2f2257ec59fba1f3faf254223a79752cc0a0 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.123/wasm-bindgen-0.2.123-aarch64-unknown-linux-musl.tar.gz
a5f1f2d2942e2fec1d19fd1c190a561b1fbb2ca95f7742e1808da99feef67d89 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.123/wasm-bindgen-0.2.123-x86_64-apple-darwin.tar.gz
2b8efedaef0f89c849c743524c9381f319df0eb0c61d957e2b00982fd964f389 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.123/wasm-bindgen-0.2.123-x86_64-pc-windows-msvc.tar.gz
80fc5c1d5c128fd67e99b14318eeabf79dfbadf459ece2d38ba93a82e55730c6 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.123/wasm-bindgen-0.2.123-x86_64-unknown-linux-musl.tar.gz
2b46fc01a6a2f5bcb24e5c5e92adf216a38ef4f57542b5291b44fa34f76ac6d2 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.125/wasm-bindgen-0.2.125-aarch64-apple-darwin.tar.gz
58844cdc1df8e725d9571cb8bf23f68b5ca0027ff3feaaa8c742fc0d76cf64f9 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.125/wasm-bindgen-0.2.125-aarch64-unknown-linux-musl.tar.gz
7e17f6656586a642d58cd77e63d696d8ef88df14ea4573c45af680111177e39b https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.125/wasm-bindgen-0.2.125-x86_64-apple-darwin.tar.gz
ddf9edc68a1ad546932f8bb65e4346caeb916a4822477e2c5b3c25941cc38a76 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.125/wasm-bindgen-0.2.125-x86_64-pc-windows-msvc.tar.gz
21d81ef7414a0a585861a60ea4ae2b7970eccaed09d4a4e05f8bc4b159827dea https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.125/wasm-bindgen-0.2.125-x86_64-unknown-linux-musl.tar.gz
7df536babe345deb68828148dbdc71179118afdab42d83547c7cebfbf1426bd5 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.126/wasm-bindgen-0.2.126-aarch64-apple-darwin.tar.gz
2245120254a9f6c9a9adf3601f3d52bb31309219e9ceab7696e74e24885c440a https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.126/wasm-bindgen-0.2.126-aarch64-unknown-linux-musl.tar.gz
6014dca993c8bf8a6ec10b6fccfbeabf599842d011f58a4abb7669afef784422 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.126/wasm-bindgen-0.2.126-x86_64-apple-darwin.tar.gz
5a3773c7e69cfb2d865e235e9210de184c8c3af1787720646ec1a8bbe09c6179 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.126/wasm-bindgen-0.2.126-x86_64-pc-windows-msvc.tar.gz
064948d58e2d6c0a745216477a639ba696216d6309aaa902939d1b865b1d869d https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.126/wasm-bindgen-0.2.126-x86_64-unknown-linux-musl.tar.gz
cd93e691eb5953ace5d8ffce52a20b024077a3dac3e2215b8224136b0efb7585 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.127/wasm-bindgen-0.2.127-aarch64-apple-darwin.tar.gz
699ddbb724ece16f912b73a98b5341a75f4b8c7886ce152d40dbe09f694e46c7 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.127/wasm-bindgen-0.2.127-aarch64-unknown-linux-musl.tar.gz
81049c79f4e283e1725e6582a0528af1301a70ad23add1df1c4d042ec825263d https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.127/wasm-bindgen-0.2.127-x86_64-apple-darwin.tar.gz
fd52ef9896cbb0f4f59ef115bdf2f4664a76d716b6201c35e5936018ad680cfc https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.127/wasm-bindgen-0.2.127-x86_64-pc-windows-msvc.tar.gz
61d4a7dc85acfa0d2354ccc0b8361928c7e52a746d17f28ebaa795ed3dc1614a https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.127/wasm-bindgen-0.2.127-x86_64-unknown-linux-musl.tar.gz
67ba17f260977725c0b541b516dbb5153538140f079a900329fb6077661b47ab https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.128/wasm-bindgen-0.2.128-aarch64-apple-darwin.tar.gz
079731dd1bc7798c1efa4f08fcc45130827cbcc9ff60a0b4c6047d64fc6fd25c https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.128/wasm-bindgen-0.2.128-aarch64-unknown-linux-musl.tar.gz
59d9af11d0a61b8019898d555de31153c3a50e7f1797e9849fb38589d16add43 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.128/wasm-bindgen-0.2.128-x86_64-apple-darwin.tar.gz
8fd8e2165da16b21ee3f5efd19e7f97d8d27cb7832f54edaef4b18e830283ec0 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.128/wasm-bindgen-0.2.128-x86_64-pc-windows-msvc.tar.gz
b51f0208fdff83515a787bd8ab9ac5865ed84dabb66d0c709957bb59793c645f https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.128/wasm-bindgen-0.2.128-x86_64-unknown-linux-musl.tar.gz
81d4a23d56b3c3eb8187658329116d50e0b228a93b343825fb71f70179051cd1 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.129/wasm-bindgen-0.2.129-aarch64-apple-darwin.tar.gz
2ed4351c35dd9440308bbb02767d47ea278efe851a52465300f3c94f5b6c2a87 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.129/wasm-bindgen-0.2.129-aarch64-unknown-linux-musl.tar.gz
7e028879a68ec53dae14048b55cc5215f6df75b17a9c1426fac8fa086d3202fd https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.129/wasm-bindgen-0.2.129-x86_64-apple-darwin.tar.gz
79e348c169d0c10c0b287647f1e753d0985353ca96800bc29be8f4261baf13e6 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.129/wasm-bindgen-0.2.129-x86_64-pc-windows-msvc.tar.gz
82d12bb940e2d4e72e0d5605387fc1b8ca179044e012b620f0ce4e7440e8320e https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.129/wasm-bindgen-0.2.129-x86_64-unknown-linux-musl.tar.gz
b90ddb9357f584b1af897d58ad77e4cce2b48fc17e2a967bc249a87f72809444 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.130/wasm-bindgen-0.2.130-aarch64-apple-darwin.tar.gz
99ffc93ce80081b91632e2b539b782821a8f3439ab0fddc645287462b2f55d3d https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.130/wasm-bindgen-0.2.130-aarch64-unknown-linux-musl.tar.gz
eb209c115b7cb95832423c1aa3f4d06d6c53f63ef74fc4b6fb79ef0b2eea5f10 https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.130/wasm-bindgen-0.2.130-x86_64-apple-darwin.tar.gz
844d23f1b56097549b936dd2e0d561fadebc1e8c9e985d5068b6b919654104ad https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.130/wasm-bindgen-0.2.130-x86_64-pc-windows-msvc.tar.gz
9687f3bb551b9f66f37ed32a40d7913a00f7962db653054e56857bc306c3227f https://github.com/wasm-bindgen/wasm-bindgen/releases/download/0.2.130/wasm-bindgen-0.2.130-x86_64-unknown-linux-musl.tar.gz

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These are the rows I'd drop. wasm-bindgen releases are immutable, so checking against the release's own .sha256sum is sufficient, and the table then only changes when worker-build bumps esbuild or Binaryen.

Comment thread worker-build/src/binary.rs Outdated
Comment on lines +279 to +281
None => PBAR.warn(&format!(
"No sha256 pinned or published for {url}; using it unverified"
)),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be an error. With esbuild and Binaryen always pinned, the only way to reach this is a wasm-bindgen release with no .sha256sum, which doesn't happen for any supported version, so continuing unverified is the one case we don't want.

Comment thread worker-build/src/binary.rs Outdated
Comment on lines +513 to +515
fn published_checksum_url(&self) -> Option<String> {
Some(format!("{}.sha256", self.download_url()))
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Binaryen is always pinned (and pinned_versions_have_checksums enforces it), so this is never used and can be removed.

Comment on lines +94 to +108
// wasm-bindgen: every 0.2.x from the minimum supported to the latest, since the
// version follows the project's Cargo.lock.
const [, , minPatch] = version("MIN_WASM_BINDGEN_LIB_VERSION").split(".").map(Number);
const [major, minor, latestPatch] = version("LATEST_WASM_BINDGEN_VERSION").split(".").map(Number);
for (let patch = minPatch; patch <= latestPatch; patch++) {
const v = `${major}.${minor}.${patch}`;
await addRelease(
"wasm-bindgen/wasm-bindgen",
v,
targets("WasmBindgen<'_>").map(
(t) =>
`https://github.com/wasm-bindgen/wasm-bindgen/releases/download/${v}/wasm-bindgen-${v}-${t}.tar.gz`,
),
);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This loop goes away with the wasm-bindgen rows. Could you also add a line to the release notes / contributing docs saying this script needs to be run when the esbuild, Binaryen or Emscripten versions in versions.rs change? Nothing in create-release-pr.yml runs it today.

- Drop the wasm-bindgen rows from checksums.txt; it now holds only the
  pinned esbuild and Binaryen archives (27 rows).
- Always check the wasm-bindgen archive against the .sha256sum file its
  release publishes.
- A missing .sha256sum, or a missing checksums.txt entry, is now an error
  instead of a warning, and is not retried. No archive is extracted
  unchecked.
- Remove the unused Binaryen .sha256 fallback.
- update-checksums.mjs no longer fetches wasm-bindgen releases. The
  README release notes say to run it when the esbuild, Binaryen or
  Emscripten version changes.
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.

worker-build runs downloaded tools without a hash check

2 participants