I threat-model the download button. Nobody threat-models the download button. It’s a link to a file on a server, and between that server and your disk there’s a CDN, a mirror, a corporate proxy, the café Wi-Fi, and possibly a man in a trench coat in the server room whispering “what if node printed something else.” Every convenience is an attack surface with better marketing, and “Download for Linux (x64)” is a big green button that means “run whatever arrives.”
SEVERITY: whoever controls any hop between you and the release server
ATTACK VECTOR: the tarball you're about to extract and put on your PATH
EXPLOIT: swap the file, swap the hash printed next to it, wait
The usual advice is to check the hash. That’s correct, and it’s also only half of it. The tip comes from an it-journey.dev Security Specialist quest report; this is the paranoid half: how to check a download, and why a hash that came from the same page as the file proves less than it looks like it does.
Everything in the console blocks below ran on my machine: bash 5.3.9, GnuPG 2.4.8, and a sha256sum that is uutils coreutils 0.10.0 rather than GNU. I also ran the format checks under GNU coreutils 9.7 (debian:stable-slim), GNU 9.1 (debian:bookworm-slim) and busybox 1.37.0 (alpine:3) in Docker, and under Perl shasum 6.04 (the same script macOS ships, though I ran it on Linux, not on a Mac). The download is a real release file: node-v22.12.0-headers.tar.gz from nodejs.org/dist/v22.12.0/, plus the SHASUMS256.txt listing published next to it.
The one-liner
A checksum line is the hash, whitespace, and the filename. Pipe one into sha256sum --check and it hashes the file it names and compares:
$ echo "c0760383af3c23637f46959a53113490fefb84cb388ac71a08d28761527e7b1b node-v22.12.0-headers.tar.gz" | sha256sum --check
node-v22.12.0-headers.tar.gz: OK
$ echo "exit=$?"
exit=0
When the publisher gives you a whole list, skip the copy-paste and check against the file. Node’s list names 41 files, and you downloaded one, so plain --check complains about the other forty:
$ sha256sum --check SHASUMS256.txt
...
win-x86/node_pdb.zip: FAILED open or read
sha256sum: WARNING: 40 listed files could not be read
$ echo "exit=$?"
exit=1
$ sha256sum --check --ignore-missing SHASUMS256.txt
node-v22.12.0-headers.tar.gz: OK
And a file I appended one byte to, to prove it’s actually looking:
$ sha256sum --check --ignore-missing SHASUMS256.txt
node-v22.12.0-headers.tar.gz: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
sha256sum: SHASUMS256.txt: no file was verified
$ echo "exit=$?"
exit=1
Busybox doesn’t have --ignore-missing (sha256sum: unrecognized option: ignore-missing), so on Alpine pull out the one line with grep or awk and pipe that in instead.
The part where the brief was wrong (the two spaces)
The brief I worked from said the two spaces between the hash and the filename are load-bearing, and that one space errors with “improperly formatted checksum line.” So I tested one space on every implementation I could reach:
| implementation | one space | EXPECTED_HASH placeholder |
CRLF line ending |
|---|---|---|---|
| uutils coreutils 0.10.0 | OK, exit 0 |
no properly formatted checksum lines found, exit 1 |
not tested |
| GNU coreutils 9.7 | OK, exit 0 |
no properly formatted checksum lines found, exit 1 |
OK, exit 0 |
| GNU coreutils 9.1 | OK, exit 0 |
no properly formatted checksum lines found, exit 1 |
OK, exit 0 |
| busybox 1.37.0 | OK, exit 0 |
FAILED, exit 1 |
FAILED + can't open, exit 1 |
Perl shasum -a 256 6.04 |
no properly formatted SHA checksum lines found, exit 1 |
not tested | not tested |
So the two spaces aren’t load-bearing for sha256sum on Linux. They’re load-bearing for shasum, which is what a Mac user types. Write two spaces anyway: it’s the format sha256sum itself prints, and it’s the only one every tool in the table accepts. The placeholder row is reassuring in a grim way: paste the tutorial’s EXPECTED_HASH literally and every tool refuses, it just disagrees on which error to print. And the CRLF row is the Windows copy-paste: busybox reads the \r as part of the filename and goes looking for a file that doesn’t exist.
The thriller (the hash in the docs)
Now I become the attacker. I own the mirror, or the proxy, or I’ve talked my way into the release bucket. I build my own node-v22.12.0-headers.tar.gz with a payload.sh inside it, and since the checksum list is just a text file sitting next to the tarball on my server, I edit the one line in SHASUMS256.txt to match my file. You download both from me and do everything above correctly:
$ sha256sum --check --ignore-missing SHASUMS256.txt
node-v22.12.0-headers.tar.gz: OK
$ echo "exit=$?"
exit=0
OK. Of course it’s OK. I wrote both halves of the test. A hash from the same place as the file proves the bytes weren’t mangled in transit, which is worth something against a flaky connection and nothing against whoever controls the source. If the sha256 printed under the download button came from the same web page, it’s the same server and the same attacker. That’s the trap in the title.
Now walk it back: nobody is doing this to your Node headers. Most of the time the thing that corrupts a download is a truncated transfer, and the plain check catches that. But the fix for the thriller is small, so here it is.
The three mitigations, ranked
1. Verify the signature on the checksum list, with a key you got somewhere else. Node signs SHASUMS256.txt and publishes the signature next to it as SHASUMS256.txt.sig. The signature is only worth something if the public key didn’t also come from the attacker’s server, so I fetched Node’s release keyring from a different host, the nodejs/release-keys repository on GitHub, and cross-checked the signing key’s fingerprint against the release-team list in the nodejs/node README (108F52B48DB57BB0CC439B2997B01419BD92F80A, Ruy Adorno, the releaser for v22.12.0):
$ curl -fsSL -o node-keys.kbx https://github.com/nodejs/release-keys/raw/HEAD/gpg-only-active-keys/pubring.kbx
$ gpg --no-default-keyring --keyring "$PWD/node-keys.kbx" --verify SHASUMS256.txt.sig SHASUMS256.txt
gpg: Signature made Tue Dec 3 20:37:27 2024 UTC
gpg: using RSA key 108F52B48DB57BB0CC439B2997B01419BD92F80A
gpg: Good signature from "Ruy Adorno <ruyadorno@hotmail.com>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 108F 52B4 8DB5 7BB0 CC43 9B29 97B0 1419 BD92 F80A
That WARNING is gpg noting that you haven’t personally certified the key. The check that matters is that the fingerprint matches the one you looked up independently. Here is my doctored SHASUMS256.txt against Node’s real signature:
$ gpg --no-default-keyring --keyring "$PWD/node-keys.kbx" --verify SHASUMS256.txt.sig SHASUMS256.txt
gpg: Signature made Tue Dec 3 20:37:27 2024 UTC
gpg: using RSA key 108F52B48DB57BB0CC439B2997B01419BD92F80A
gpg: BAD signature from "Ruy Adorno <ruyadorno@hotmail.com>" [unknown]
$ echo "exit=$?"
exit=1
A smarter attacker re-signs the list with their own key. I generated one called “Totally Node Release” and signed my fake list. Against the pinned keyring, gpg can’t find the key and exits 2. Against a keyring that also holds whatever key the mirror offered, it’s delighted:
$ gpg --no-default-keyring --keyring "$PWD/node-keys.kbx" --verify SHASUMS256.txt.sig SHASUMS256.txt
gpg: Signature made Thu Dec 3 22:44:56 2026 UTC
gpg: using EDDSA key 8AE2618225A4FDE5076B5ADD72EB292EA6FCB448
gpg: Can't check signature: No public key
$ echo "exit=$?"
exit=2
$ gpg --verify SHASUMS256.txt.sig SHASUMS256.txt
...
gpg: Good signature from "Totally Node Release <release@nodejs.example>" [ultimate]
$ echo "exit=$?"
exit=0
“Good signature” means good for some key you hold, not good for the publisher. Don’t import keys from the download page, and verify against a keyring that holds only the publisher’s keys.
One more thing I tripped on: I first wrote --keyring node-keys.kbx without the path, and gpg read that bare name relative to ~/.gnupg, quietly created an empty keybox there, and answered Can't check signature: No public key. That fails closed, at least. Pass an absolute path.
2. Check the file against the list gpg actually verified, not the plain one next to it. Node also publishes SHASUMS256.txt.asc, which is the checksum list with the signature wrapped around it (a clearsigned file, not a detached signature). Pointing gpg --verify at it looks like the same check, and against my doctored SHASUMS256.txt it passes:
$ gpg --no-default-keyring --keyring "$PWD/node-keys.kbx" --verify SHASUMS256.txt.asc
gpg: Signature made Tue Dec 3 20:36:30 2024 UTC
gpg: using RSA key 108F52B48DB57BB0CC439B2997B01419BD92F80A
gpg: Good signature from "Ruy Adorno <ruyadorno@hotmail.com>" [unknown]
...
gpg: WARNING: not a detached signature; file 'SHASUMS256.txt' was NOT verified!
$ echo "exit=$?"
exit=0
Exit 0, “Good signature,” and the actual verdict in a warning on the last line: it verified the copy inside the .asc and never opened the doctored SHASUMS256.txt. If you only have the .asc, have gpg write out the content it verified and check against that:
$ gpg --no-default-keyring --keyring "$PWD/node-keys.kbx" --quiet --output verified.txt --decrypt SHASUMS256.txt.asc
$ sha256sum --check --ignore-missing verified.txt
node-v22.12.0-headers.tar.gz: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
sha256sum: verified.txt: no file was verified
That FAILED is the right answer: the signed list says my tarball isn’t Node’s.
3. Do both in a function that stops before you extract. A check you run by hand is a check you skip at 6 p.m. This one verifies the signature first, then checks exactly one named file against the list it just verified, and returns non-zero if either step fails:
# verify.sh: check a download against a SIGNED checksum list. Source it: . ./verify.sh
# usage: verify_download <keyring> <sums-file> <detached-sig> <file>
verify_download() {
local keyring=$1 sums=$2 sig=$3 file=$4
case $keyring in /*) ;; *) keyring="$PWD/$keyring" ;; esac # gpg reads a bare name from ~/.gnupg
if ! gpg --quiet --no-default-keyring --keyring "$keyring" --verify "$sig" "$sums" 2>/dev/null; then
echo "REJECT: $sums is not signed by a key in $keyring" >&2
return 1
fi
awk -v f="$file" '$2 == f' "$sums" | sha256sum --check
}
The real release, my tarball with Node’s real signature, my tarball with my own signature, and a typo in the filename:
$ verify_download node-keys.kbx SHASUMS256.txt SHASUMS256.txt.sig node-v22.12.0-headers.tar.gz
node-v22.12.0-headers.tar.gz: OK
exit=0
$ verify_download node-keys.kbx SHASUMS256.txt SHASUMS256.txt.sig node-v22.12.0-headers.tar.gz # doctored list, Node's .sig
REJECT: SHASUMS256.txt is not signed by a key in /tmp/evil/node-keys.kbx
exit=1
$ verify_download node-keys.kbx SHASUMS256.txt SHASUMS256.txt.sig node-v22.12.0-headers.tar.gz # doctored list, attacker's .sig
REJECT: SHASUMS256.txt is not signed by a key in /tmp/evil/node-keys.kbx
exit=1
$ verify_download node-keys.kbx SHASUMS256.txt SHASUMS256.txt.sig node-v22.12.0-header.tar.gz # typo
sha256sum: 'standard input': no properly formatted checksum lines found
exit=1
The typo case matters: if awk finds no line, sha256sum gets empty input and fails instead of passing. Use it as a gate, verify_download … && tar xzf node-v22.12.0-headers.tar.gz, so a rejection means nothing gets extracted. Its limits: it uses sha256sum and awk, so on a Mac you’d swap in shasum -a 256 -c (which I haven’t run on a Mac), and it trusts whatever keyring you hand it, which is why mitigation 1 is about where the keyring came from.
What a normal person should do
For a quick sanity check, sha256sum --check --ignore-missing SHASUMS256.txt with two spaces in any line you type yourself catches truncated and corrupted downloads. For anything you’ll run, put on your PATH or ship to production, verify the signature on the checksum list too, with the publisher’s key fetched from somewhere other than the download page and its fingerprint checked against a second source. If the project publishes a hash and no signature, the hash still catches a broken download, but it’s the project’s own word repeated next to the file.
Same genre, other files: make a bootable Debian USB from a Mac has the one checksum you should never skip before dd, and rotate the secret you already deleted covers what happens after something unverified gets in.