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
.ziprequest is parsed into a module path and version and checked against the project's Dependency Firewall policy. A blocked zip gets a403with atext/plainreason thatgoprints, 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:
gobefore 1.27 on macOS, andgit, reject the MITM CA unless it's installed withsudo.
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/goproxyv0.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, thego mod downloaddirect 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 customFetcher, because goproxy maps everyFetchererror to 404 or 500, and a 404 is what makesgofall through to another source. v0.27.0 caps upstream.mod/.zipsizes. The build footprint is goproxy,golang.org/x/modandgithub.com/aofei/backoff; goproxy'scmd/and S3 trees aren't imported.golang.org/x/modv0.42.0 (now direct). The gate decodes module paths and versions withmodule.UnescapePath/UnescapeVersion, exactly ascmd/goencodes them. It's pinned explicitly becausego getof 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 topurl.TypeGolangonce !4167 (merged) merges. Until then the REST checker rejectsgolang, and the gate fails closed. - Call
Server.StopbeforeBackend.Close. - A stalled policy API hung the gate, because
CachingCheckerdropped thepolicy.CheckTimeoutdeadline and the API client has no timeout of its own. The MITM proxy onmainhangs the same way. !4178 (merged) fixes it inCachingCheckerfor both, so this MR doesn't changecheck. Server.record/Verdictsrepeat the MITM proxy's verdict dedupe, andcilog.Appendhas a third copy. A sharedverdict.Collectorfor both proxies is a follow-up after the Go MRs merge.
How has this been tested?
- Package tests with
-raceandgoleak. These cover the token andHostrefusals, boundedStopwhile a policy check or backend request hangs (including one wrapped inCachingChecker), 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
Stopis not recorded as a verdict, thepath.Cleanrefusal 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 makegodrop the whole block reason. The error-after-Stoppath 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 downloadagainst the server with a stub policy that blocksrsc.io/sampler:rsc.io/quote@v1.5.2downloaded through the tokenedGOPROXYURL with one zip checked, andrsc.io/sampler@v1.3.0was 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.