Skip to content

fix: add SHA-256 checksum verification to GitHub release downloads#288

Open
xiaolai wants to merge 1 commit intonextlevelbuilder:mainfrom
xiaolai:fix/nlpm-github-checksum-verify
Open

fix: add SHA-256 checksum verification to GitHub release downloads#288
xiaolai wants to merge 1 commit intonextlevelbuilder:mainfrom
xiaolai:fix/nlpm-github-checksum-verify

Conversation

@xiaolai
Copy link
Copy Markdown

@xiaolai xiaolai commented Apr 26, 2026

Automated audit: This PR was generated by NLPM, a natural language programming linter, running via claude-code-action. Please evaluate the diff on its merits.

Security Fix (Medium)

cli/src/utils/github.tsdownloadRelease() fetches a ZIP from GitHub releases and writes it directly to disk without any integrity check. init.ts then extracts and installs the contents into the user's project. A compromised release asset (e.g. from a hijacked GitHub token or a compromised release pipeline) would be silently installed with no way for the user to detect the tamper.

Fix: This PR adds opt-in SHA-256 verification using a companion checksum asset pattern:

  1. getChecksumUrl(release, assetName) — looks for a <asset-name>.sha256 or checksums.txt asset in the GitHub release
  2. downloadRelease(url, dest, checksumUrl?) — if checksumUrl is provided and the fetch succeeds, computes SHA-256 of the downloaded buffer and compares against the expected hash before writing to disk; throws GitHubChecksumError on mismatch
  3. init.ts now calls getChecksumUrl(release, assetName) and passes the result to downloadRelease

This is backward-compatible: if no companion checksum asset is uploaded, the behavior is identical to the current code. To enable full verification, upload a release.zip.sha256 (or checksums.txt) companion file to each GitHub release — the CLI will then automatically verify before installation.

downloadRelease() previously wrote the downloaded ZIP to disk without any
integrity check. A compromised release asset would be silently installed
into user projects.

Changes:
- Add getChecksumUrl() helper that looks for a companion `.sha256` or
  `checksums.txt` asset in the release
- Add optional checksumUrl parameter to downloadRelease(); if a checksum
  URL is provided and the fetch succeeds, compute SHA-256 of the downloaded
  buffer and compare before writing to disk
- Add GitHubChecksumError class for mismatch failures
- Update init.ts to look up and pass the checksum URL when present

This is forward-compatible: if no checksum asset is uploaded the behavior
is unchanged. Maintainers can enable full verification by uploading a
`<asset-name>.sha256` companion file to each release.

Co-Authored-By: Claude Code <[email protected]>
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.

1 participant