feat(df): add a loopback Go module proxy that gates module zips

Description

Adds internal/dependencyfirewall/gomodproxy, the enforcement point for the upcoming glab df go. Nothing calls it yet; the next MR wires it into the run engine.

It's a small server on 127.0.0.1 that speaks the Go module proxy protocol. glab df go will point go at it with GOPROXY, so every module .zip passes through it:

  • A .zip request is parsed into a module path and version and checked against the project's Dependency Firewall policy. A blocked zip gets a 403 with a text/plain reason that go prints, and is never fetched.
  • Allowed zips, and the metadata requests (.info, .mod, @latest, version lists, /sumdb/), go to a backend built on goproxy, which fetches them.
  • Plain HTTP on loopback means no certificate is involved, which is why this replaces the closed !3928 (closed) MITM matcher for Go: go before 1.27 on macOS, and git, reject the MITM CA unless it's installed with sudo.

This is ported from the !3910 (closed) proof of concept, with these changes:

Change Why
A random per-run path token in the server URL, and a Host check The backend fetches with the user's credentials. Without these, another local process, or a web page using DNS rebinding, could read private modules through it.
Stop cancels in-flight checks and drains for at most 5s, then force-closes The PoC could make Ctrl-C wait about 65s. This matches the MITM proxy's 5s drain. A check the production CachingChecker won't cancel no longer delays Stop or records a verdict after it.
Only blocked and warned zips record verdicts; CheckedZips counts every decision Matches the MITM proxy. The count lets the next MR say "nothing was checked" when every module came from the cache.
golang.org/toolchain is exempt only for toolchain-shaped versions The PoC exempted any version of that path.
The fetcher pins GOTOOLCHAIN=local, GOWORK=off and -modcacherw, and those pins can't be overridden Keeps the fetcher from downloading a toolchain, applying a workspace, or leaving an undeletable module cache. Overriding its private module cache would let go skip the gated request.

The parser cuts the module path at the first /@, as goproxy's own router does. @ is illegal in module paths and / in versions, so a second /@v/ lands in the version, where module.UnescapeVersion refuses it. Every finding from the !3928 (closed) review (version unescaping, dot segments, empty module path, a second /@v/, malformed ! escapes, percent escapes) has a named test.

Dependencies

  • github.com/goproxy/goproxy v0.27.0. The standard library has no Go module proxy protocol implementation, and no existing glab dependency provides one. Writing it by hand would mean reimplementing version queries, pseudo-version resolution, the go mod download direct path, and checksum-database proxying. goproxy is only the backend behind glab's own gate; the gate makes every policy decision. It's wired in as middleware rather than as a custom Fetcher, because goproxy maps every Fetcher error to 404 or 500, and a 404 is what makes go fall through to another source. v0.27.0 caps upstream .mod/.zip sizes. The build footprint is goproxy, golang.org/x/mod and github.com/aofei/backoff; goproxy's cmd/ and S3 trees aren't imported.
  • golang.org/x/mod v0.42.0 (now direct). The gate decodes module paths and versions with module.UnescapePath/UnescapeVersion, exactly as cmd/go encodes them. It's pinned explicitly because go get of goproxy alone would keep an older version, and x/mod below v0.40.0 has GO-2026-6179, a checksum-database verification bypass reachable through goproxy. goproxy v0.27.0 itself requires v0.42.0.

govulncheck reports no vulnerabilities for the package.

Notes for the next MR

  • Switch the "golang" ecosystem literal to purl.TypeGolang once !4167 (merged) merges. Until then the REST checker rejects golang, and the gate fails closed.
  • Call Server.Stop before Backend.Close.
  • A stalled policy API hung the gate, because CachingChecker dropped the policy.CheckTimeout deadline and the API client has no timeout of its own. The MITM proxy on main hangs the same way. !4178 (merged) fixes it in CachingChecker for both, so this MR doesn't change check.
  • Server.record/Verdicts repeat the MITM proxy's verdict dedupe, and cilog.Append has a third copy. A shared verdict.Collector for both proxies is a follow-up after the Go MRs merge.

How has this been tested?

  • Package tests with -race and goleak. These cover the token and Host refusals, bounded Stop while a policy check or backend request hangs (including one wrapped in CachingChecker), the fetcher pins and overrides, the toolchain exemption, and every parser finding above. The tests for new behavior were written first and seen failing against the PoC code.
  • Tests added after a second review, each seen failing against a mutant that removes its guard: an error after Stop is not recorded as a verdict, the path.Clean refusal of dot segments behind the sumdb prefix and of a trailing slash, and the sanitizer's removal of format runes such as U+200B, which make go drop the whole block reason. The error-after-Stop path is a select race, so that test runs the check 100,000 times. It caught the mutant in 50 of 50 runs and takes 0.6s under -race.
  • A real go mod download against the server with a stub policy that blocks rsc.io/sampler: rsc.io/quote@v1.5.2 downloaded through the tokened GOPROXY URL with one zip checked, and rsc.io/sampler@v1.3.0 was refused with the firewall reason and recorded as blocked.
  • Code review covered correctness, project standards, testing, maintainability, security, reliability and adversarial lenses. Its findings were applied, apart from one consistency nit about hand-stamped verdict timestamps: dropping them would change the recorded time from decision time to log-write time.
Edited by Arpit Gogia

Merge request reports

Loading
Loading