Repository navigation
fix(pages): refuse a build whose gateway serves another network - #679
Conversation
The Pages build bakes PAGES_GATEWAY_URL into every public repository's HTTPS clone row and share link, and a forge-gateway resolves owner/name on its own network. Flipping PAGES_NETWORK to mainnet while the variable still names the testnet gateway would ship clone lines that fetch testnet's repository of the same name. The build now reads the gateway's /readyz (which names its network) and fails on a mismatch. An unreachable gateway, or one that does not say, only warns, so a gateway outage does not block a deploy. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 30 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
PastaPastaPasta
left a comment
There was a problem hiding this comment.
Verdict: approve
I reviewed head 0d876a2 against services/forge-gateway/src/server.rs (readyz), forge-web/lib/constants.ts (resolveNetworks) and forge-web/lib/gateway.ts.
Correctness
- The response shape matches.
readyz(server.rs:1850) always emits"network": upstream.network(), which isNetwork::key()(upstream.rs:242, forge-core network.rs:74):testnet,mainnetordevnet-<name>, with the name's case kept.buildNetworkKey(check-gateway-network.mjs:18) lowercases only the kind and keeps the devnet name as given, sodevnet-Sakuramatches on both sides. The fallback rules (devnet name with no network means devnet; neither means testnet) matchresolveNetworks. - A degraded gateway returns 503 with the same JSON. The script reads the body whatever the status (mjs:31-32), so a degraded gateway on the wrong network still fails the build, and a test covers that.
- No URL, or a blank one, skips without a request. Trailing slashes are stripped. Non-JSON bodies, network errors and the 15 s
AbortSignal.timeoutall land in the catch and only warn. A missing or non-stringnetworkwarns.process.exit(1)under Actions'bash -efails the step beforepnpm build. - Current testnet deploy: I ran
curl https://git-forge.dashhq.org/readyzjust now. It returns 200application/jsonwith"network":"testnet", and the workflow's defaultPAGES_NETWORKgivestestnet, so the check passes. The script runs after the empty-varunsetloop, so an unsetPAGES_GATEWAY_URLreaches the skip path.
Warn-only path
This is a sensible choice. The dangerous case is a mainnet build that still points at the live testnet gateway, and a reachable gateway is exactly when the check can read its network and fail the build. If the gateway is down, its clone lines fail anyway. In the browser, verifyGateway still flags a manifest from another network (gateway.ts:180). The ::warning:: annotation keeps the skipped check visible.
Tests
CI's web job ran scripts/check-gateway-network.test.ts, 6 tests, all passing. The failure case is really covered: a mainnet build with a testnet gateway and a trailing slash returns error with the expected message, and so does the degraded 503 case.
Nits (none blocking)
- pages.yml:101: if Cloudflare in front of the gateway ever challenges runner traffic, it returns HTML, and the guard quietly becomes a warning on every deploy. After the first deploy following merge, check that the log line reads
check-gateway-network: the gateway … serves testnet, not a warning. - check-gateway-network.test.ts:7: the URL assertion inside
answeringthrows insidefetchImpl, and the script's catch turns that into a warning. In the last case, which expectswarningfromanswering({ status: 'ok' }), a wrong URL would therefore still pass. - check-gateway-network.mjs:26: the script doesn't apply
gatewayConfig's rules (gateway.ts:24): http(s) only, no query, fragment or credentials. So it probes values the app ignores. At worst that gives a warning, so this is cosmetic. - No test for a mismatch between two devnets (
devnet-agateway,devnet-bbuild) or for the timeout path. Both follow from the code as written.
🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta.
Problem
The Pages build bakes
PAGES_GATEWAY_URLinto every public repository's HTTPS clone row and share link, and a forge-gateway resolvesowner/nameon its own network. TodayPAGES_GATEWAY_URL=https://git-forge.dashhq.orgis a testnet gateway (/readyz→"network":"testnet"). IfPAGES_NETWORKis flipped tomainnetfor the launch and the gateway variable is left as it is, the mainnet site hands outgit clone https://git-forge.dashhq.org/alice/project.gitlines that fetch testnet's alice/project. DPNS names are per network, so that can be a different owner's code, and copy-paste users never see the in-page verify check.Found by the mainnet-readiness audit (2026-11-24).
Fix
forge-web/scripts/check-gateway-network.mjsruns in the Pages build step beforepnpm build. It reads the gateway's/readyzand compares itsnetworkwith the build's network key, resolved the same way aslib/constants.ts:::error::, and the deploy failsnetworkfield →::warning::only, so a gateway outage does not block a deployThe docs note in
docs/hosting/forge-gateway.mdsays this.Tested (boat sandbox)
vitest run scripts/52 passed (6 new);pnpm typecheckclean;pnpm lint:copyclean; pages.yml parsesNEXT_PUBLIC_NETWORK=mainnet NEXT_PUBLIC_GATEWAY_URL=https://git-forge.dashhq.org→::error::the gateway https://git-forge.dashhq.org serves testnet, but this build is for mainnet…, exit 1. The testnet build passes (exit 0); an unreachable gateway warns (exit 0).pnpm test, 3 failures are unrelated:lib/merge/xdiff.parity.test.tsneeds a newer git than the sandbox's 2.43 (merge-file --diff-algorithm).🤖 Generated with Claude Code