feat(npm): verify SHA-256 of downloaded binary against checksums.txt - #63
Open
saurabhhhcodes wants to merge 1 commit into
Open
feat(npm): verify SHA-256 of downloaded binary against checksums.txt#63saurabhhhcodes wants to merge 1 commit into
saurabhhhcodes wants to merge 1 commit into
Conversation
Closes optiqor#28 postinstall.js streamed the release tarball straight into tar without validating its digest, so a MITM'd or hijacked release asset could run arbitrary code on any npm install -g @optiqor/cli host. - Fetch checksums.txt from the same release tag. - Hash the downloaded tarball with crypto sha256 before extracting. - Compare against the entry matching the archive filename; a missing or malformed entry is treated as failure. - On mismatch: delete the tarball and exit 1 instead of proceeding. - Other network errors keep the existing non-fatal exit-0 path so an offline npm install still falls back to the source-build hint. Signed-off-by: Saurabh Kumar Bajpai <saurabhkumarbajpaiai@gmail.com>
|
First PR — welcome aboard! A few things to expect:
If you get stuck, reply here or jump to Discussions. We want this PR to land. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #28
Problem
npm/postinstall.jsdownloaded the release tarball and piped it straight intotar -xzfwithout validating its digest, so a MITM'd, hijacked, or compromised release asset would run arbitrary code on anynpm install -g @optiqor/clihost. GoReleaser shipschecksums.txtwith every release; the install path never used it.Changes (
npm/postinstall.js)checksums.txtfrom the same release tag.crypto.createHash('sha256')before extraction.optiqor_${VERSION}_${target}.tar.gz). A missing entry or a malformed digest is treated as a failure.refusing to install a tampered binary) instead of proceeding.Other network errors keep the existing non-fatal exit-0 path, so an offline
npm installstill surfaces the source-build hint instead of aborting the whole install.Verification
Logic exercised standalone: entry match, missing entry → null, malformed digest → null, uppercase digest normalization, file-hash comparison — all pass.
Example failure output:
Cosign verification of
checksums.txtitself is left as follow-up (bonus item in the issue).