Skip to content

fix(pages): refuse a build whose gateway serves another network - #679

Merged
PastaPastaPasta merged 1 commit into
masterfrom
fix/pages-gateway-network
Nov 24, 2026
Merged

PastaPastaPasta merged 1 commit into
masterfrom
fix/pages-gateway-network

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Owner

Problem

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. Today PAGES_GATEWAY_URL=https://git-forge.dashhq.org is a testnet gateway (/readyz → "network":"testnet"). If PAGES_NETWORK is flipped to mainnet for the launch and the gateway variable is left as it is, the mainnet site hands out git clone https://git-forge.dashhq.org/alice/project.git lines 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.mjs runs in the Pages build step before pnpm build. It reads the gateway's /readyz and compares its network with the build's network key, resolved the same way as lib/constants.ts:

  • mismatch → ::error::, and the deploy fails
  • unreachable, or no network field → ::warning:: only, so a gateway outage does not block a deploy
  • no gateway configured → skipped

The docs note in docs/hosting/forge-gateway.md says this.

Tested (boat sandbox)

  • vitest run scripts/ 52 passed (6 new); pnpm typecheck clean; pnpm lint:copy clean; pages.yml parses
  • Live: NEXT_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).
  • In the full pnpm test, 3 failures are unrelated: lib/merge/xdiff.parity.test.ts needs a newer git than the sandbox's 2.43 (merge-file --diff-algorithm).

🤖 Generated with Claude Code

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]>
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You'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.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a8351176-e0b2-471d-8cef-d82c5df266a5
Commits

Reviewing files that changed from the base of the PR and between b5917e6 and 0d876a2.

Files selected for processing: 4

  • .github/workflows/pages.yml
  • docs/hosting/forge-gateway.md
  • forge-web/scripts/check-gateway-network.mjs
  • forge-web/scripts/check-gateway-network.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@PastaPastaPasta PastaPastaPasta left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 is Network::key() (upstream.rs:242, forge-core network.rs:74): testnet, mainnet or devnet-<name>, with the name's case kept. buildNetworkKey (check-gateway-network.mjs:18) lowercases only the kind and keeps the devnet name as given, so devnet-Sakura matches on both sides. The fallback rules (devnet name with no network means devnet; neither means testnet) match resolveNetworks.
  • 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.timeout all land in the catch and only warn. A missing or non-string network warns. process.exit(1) under Actions' bash -e fails the step before pnpm build.
  • Current testnet deploy: I ran curl https://git-forge.dashhq.org/readyz just now. It returns 200 application/json with "network":"testnet", and the workflow's default PAGES_NETWORK gives testnet, so the check passes. The script runs after the empty-var unset loop, so an unset PAGES_GATEWAY_URL reaches 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)

  1. 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.
  2. check-gateway-network.test.ts:7: the URL assertion inside answering throws inside fetchImpl, and the script's catch turns that into a warning. In the last case, which expects warning from answering({ status: 'ok' }), a wrong URL would therefore still pass.
  3. 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.
  4. No test for a mismatch between two devnets (devnet-a gateway, devnet-b build) or for the timeout path. Both follow from the code as written.

🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta.

@PastaPastaPasta
PastaPastaPasta merged commit 515059f into master Nov 24, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant