Files
skillshare/website/docs/reference
star-nebulaandWillie 2bf7e66790 fix(upgrade): verify the release archive before replacing the binary (#335)
* refactor(version): own the release checksum helpers

The UI asset download already verifies its tarball against the release
checksums file, but the fetch, parse, and hashing helpers were private to
`internal/uidist`, so a second caller had nothing to reuse: `internal/version`
builds the checksums URL and `internal/utils` already hashes files.

Move the parser and the fetcher next to the URL they consume, keep the same
messages, and drop uidist's private SHA-256 duplicate in favour of
`utils.FileHash`. No behavior change.

* fix(upgrade): verify the release archive before replacing the binary

`skillshare upgrade --cli` streamed the release archive straight into the
extractor and renamed the result over the live executable, so an archive that
did not match the release was installed anyway. The UI asset download in the
same product has always refused on a mismatch, and the release workflow checks
every asset against checksums.txt before publishing, so the published hashes
were the one integrity signal this path did not consult.

Stage the archive to a temp file, compare its SHA-256 with the entry for the
downloaded asset name, and extract only when they agree. A mismatch, an entry
for a different file, or an unreachable checksums.txt stops the upgrade and
leaves the running binary untouched. This guards against damaged or mismatched
downloads rather than a release whose assets and checksums were replaced
together.

Tests use a local server and build the archive each platform extracts, so all
four outcomes are covered without network access. The sudo child re-enters this
same function, so elevated upgrades are covered too.

---------

Co-authored-by: Willie <egg358358@gmail.com>
2026-10-02 22:35:47 +08:00
..