Skip to content

feat(download): verify sha256 against GitHub Releases asset digest#83

Open
pdugas wants to merge 1 commit into
criblio:masterfrom
pdugas:pdugas/verify-download-checksum
Open

feat(download): verify sha256 against GitHub Releases asset digest#83
pdugas wants to merge 1 commit into
criblio:masterfrom
pdugas:pdugas/verify-download-checksum

Conversation

@pdugas
Copy link
Copy Markdown

@pdugas pdugas commented May 13, 2026

Stream the response through a sha256 hasher and, for URLs that match the GitHub Releases download pattern, look up the asset's digest field on the Releases API. On mismatch, reject with ERR_CHECKSUM_MISMATCH and remove the partial file. Older assets without a published digest and non-GitHub URLs (e.g. nodejs.org tarballs) warn and continue, so the change is backward compatible for callers that previously relied on unverified downloads.

Adds tests (test/download.test.js) covering getExpectedSha256 parsing, the happy path, mismatch detection, missing-digest and API-down fallbacks, redirect following, and multi-chunk hashing.

Stream the response through a sha256 hasher and, for URLs that match the
GitHub Releases download pattern, look up the asset's `digest` field on
the Releases API. On mismatch, reject with ERR_CHECKSUM_MISMATCH and
remove the partial file. Older assets without a published `digest` and
non-GitHub URLs (e.g. nodejs.org tarballs) warn and continue, so the
change is backward compatible for callers that previously relied on
unverified downloads.

Adds tests (test/download.test.js) covering getExpectedSha256 parsing,
the happy path, mismatch detection, missing-digest and API-down
fallbacks, redirect following, and multi-chunk hashing.
Comment thread src/util.js
patchFile,
assertSupportedKey,
getExpectedSha256,
__setGithubHostsForTest,
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.

The __ prefix signals intent, but shipping a test-mutation hook in the production bundle is a bit of code smell. Please consider restructuring getExpectedSha256 to accept the hosts as parameters so tests can pass them directly without needing global mutation at all.

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.

If you do so, I think you would need to change the signature of download and, eventually, there would be no need to export getExpectedSha256 either.

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