Repository navigation
fix(tools): verify release downloads and add install opt-out - #199
Merged
Merged
Conversation
golangci-lint was installed by piping install.sh from the master branch into sh, and gitleaks was downloaded with curl; neither download was checked against anything. A curl | sh pipeline exits 0 when a step fails, so a failed golangci-lint install looked like a success and the go install fallback never ran. With golangci-lint v2.15.0 on darwin/arm64 the script fails its own checksum step, because the checksums file lists both the archive and its .sbom.json, and the lint check then only reported "golangci-lint not found". Install both tools from their GitHub release instead: download the pinned version's archive and checksums file over https, require exactly one checksums line for the archive's exact name, verify the SHA-256 before extracting, and extract only the binary (a regular file, size capped, no links or path traversal) into GOBIN, as before. Each failed step is an error naming the tool, version, and step. golangci-lint still falls back to go install, now with the v2 module path, and the checks pass the install error through with the exact install command. GO_PRE_COMMIT_AUTO_INSTALL_TOOLS=false turns automatic installs off: a missing tool then fails its check with the command that installs it.
Contributor
Code Coverage Analysis🟢 Overall Coverage: 91.1% Coverage Metrics
Coverage Breakdown
ResourcesGenerated via go-coverage • 2026-11-10 04:27:33 UTC |
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.
What Changed
internal/tools/release.go). The pinned version must be a release tag (v1.2.3). go-pre-commit downloads the archive and the checksums file over https only (redirects to plain http are refused), with size caps. It takes the one checksums line for the archive's exact name (zero or several lines are refused), checks the SHA-256 before extracting anything, and extracts only the binary: a regular file, with no links, no entries that escape the archive, and no duplicates. The binary is written to a temp file and renamed into$GOBIN(or$GOPATH/bin).latestis resolved from the/releases/latestredirect. No install script is downloaded or run.tool installation failed: golangci-lint v2.15.0: verify checksum: …. golangci-lint still falls back togo installon any failure, now with the/v2module path. When both methods fail, both errors are reported. A successful golangci-lint install is now checked against PATH, as the other tools already were.GO_PRE_COMMIT_AUTO_INSTALL_TOOLS(defaulttrue). Set tofalse, nothing is installed, and a missing tool fails its check with the exact command, for examplego install github.com/golangci/golangci-lint/v2/cmd/[email protected]. Tools already on PATH are used either way.github.com/zricethezav/gitleaks/v8..github/are updated.Why It Was Necessary
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- …: a script from a moving branch, piped to a shell. gitleaks was downloaded with curl and never checked.curl | shpipeline exits 0 when a step fails, so a failed install looked like a success and thego installfallback never ran. That fallback also used the v1 module path, so it could not install any v2 version.golangci-lint-2.15.0-darwin-arm64.tar.gzand…tar.gz.sbom.json, and the script matches the name as a substring. The lint check then reported onlygolangci-lint not foundand suggested a v1go install …@latest. golangci-lint could not be installed on Apple silicon.Testing Performed
internal/tools/installer_release_test.goand a rewritteninstaller_gitleaks_test.gocover:.sbom.jsonsibling line, which is ignoredlatestresolutiongo installfallback (v1 and v2 paths, both methods failing)InstallCommandinternal/checks/gotools/install_test.gochecks each check's message, suggestion and output with installs off and after a failed install.httptestinto tempGOBIN/GOPATH, the tools package'sTestMainmakes any other download fail, andmakeToolsUnavailablenow turns installs off.magex format:fix,magex lint(0 issues),magex test:race, andgo-pre-commit run --all-filespass.go test -race -shuffle=on -count=3passes forinternal/tools,internal/checks/gotools,internal/integration, andinternal/config.GOBIN. WithGO_PRE_COMMIT_AUTO_INSTALL_TOOLS=false, lint fails with the exact command and nothing is downloaded. With installs on, golangci-lint v2.15.0 is downloaded, verified and installed, and lint passes (withGOPROXY=off, so the fallback could not have done it). gitleaks v8.30.1 also installs and runs.Impact / Risk
runtime.GOOS/GOARCH) instead ofGOOS/GOARCHenvironment variables anduname. A platform a tool doesn't publish now fails clearly instead of downloading the linux x64 build. 32-bit ARM uses the armv6 build.curl,sh,tar, andunzipare no longer needed; downloads use Go's HTTP client and honorHTTPS_PROXY.$GOBIN(else$GOPATH/bin, else~/go/bin), like gitleaks. The script used$(go env GOPATH)/bin. They differ only whenGOBINis set.go installfallback, verified by the Go checksum database. The mismatched archive is never installed, and the warning shows the failure.command 'gitleaks' failed.GO_PRE_COMMIT_AUTO_INSTALL_TOOLSthat is not a boolean keeps installs on, like other boolean settings. A tool installed outside PATH still fails withtool installed but not found in PATH; that is a separate fix.