Skip to content

skillshare upgrade --cli replaces the running binary without verifying the release checksum #333

Closed

Description

@star-nebula

What happens

skillshare upgrade --cli downloads the release archive and renames the extracted
binary over the one in use without ever consulting the release's checksums.txt.
An archive that does not match the published hash is installed anyway.

The path is downloadBinary → downloadAndReplace → extractFrom{Zip,TarGz} →
writeBinary:

func downloadAndReplace(url, destPath string, onProgress utils.ProgressFunc) error {
	client := &http.Client{Timeout: 5 * time.Minute}
	resp, err := client.Get(url)
	...
	body := utils.NewProgressReader(resp.Body, resp.ContentLength, onProgress)

	// Windows uses zip, others use tar.gz
	if runtime.GOOS == "windows" {
		return extractFromZip(body, destPath)
	}
	return extractFromTarGz(body, destPath)
}

grep -rn "checksum\|sha256" cmd/skillshare/upgrade.go returns nothing on current main.

The rest of the product does verify

The UI asset download in the same release flow refuses to extract on a mismatch
(internal/uidist/uidist.go):

expectedHash, err := fetchChecksum(ver)
...
actualHash, err := fileSHA256(tmpFile)
if actualHash != expectedHash {
	return fmt.Errorf("checksum mismatch: expected %s, got %s", expectedHash, actualHash)
}

It downloads to a temp file, hashes it, compares against checksums.txt, and only
then extracts. So skillshare upgrade pre-downloads verified UI assets while
replacing the binary itself unverified — one command, two standards.

The hashes are always available: every release sampled (v0.1.0, v0.10.0,
v0.21.0, v0.23.0, v0.23.4) publishes checksums.txt alongside the six platform
archives, and the names GoReleaser writes there are exactly the names
version.BuildDownloadURL constructs. wiki/release.md records that the release
helper verifies all checksums, and that Publish Release verifies the downloaded
assets again before publication.

Proof it installs regardless

A temporary test (not committed) served a tar.gz containing a payload that was not
the real binary, together with a checksums.txt holding the hash of a different
archive, and pointed the stock function at it:

=== RUN   TestStock_InstallsTamperedArchive
    stock downloadAndReplace err = <nil>
    stock dest content after = "trojan payload"
    CONFIRMED: stock code replaced the live binary with an archive whose checksum does not match
--- PASS

No error, and the running binary was gone. The same harness with the fix returns
checksum mismatch and leaves the previous binary in place.

Why this matters (and what it is not)

Realistically this catches a damaged or partial transfer that still parses, a proxy or
cache returning a different asset, and an archive built for another platform — cases
where gzip/zip structure alone would not complain. It is not a defense against a
release whose assets and checksums.txt were replaced together, since both come from
the same origin over the same TLS connection; that needs signing and attestation,
which is a much larger decision.

The value is mostly consistency and cost: the check is ~20 lines built from helpers
that already exist, it runs before anything is moved, and it makes the two download
paths in upgrade agree. A checksum failure now aborts before any rename, so the
existing binary is never displaced by an archive the release did not publish.

Reproduction

Any platform:

# what the two download paths know about checksums
grep -rn "checksum\|sha256" cmd/skillshare/upgrade.go internal/uidist/uidist.go

cmd/skillshare/upgrade.go contributes no lines at all (grep exit 1 when run on it
alone); every match is in internal/uidist/uidist.go:

42:// checksum, extracts it to the cache directory, and cleans up old versions.
48:	expectedHash, err := fetchChecksum(ver)
67:		return fmt.Errorf("checksum mismatch: expected %s, got %s", expectedHash, actualHash)
120:func fetchChecksum(ver string) (string, error) {
130:		return "", fmt.Errorf("checksums.txt returned HTTP %d", resp.StatusCode)

Fix

I have it implemented with tests and command documentation; I'll open a PR shortly
unless there is a reason to keep this path unverified.

Activity

  1. added
    feature
    on Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions