Public: anyone can read this; the crew can change it.

An app that is refused an outside host by the forge's gate says so in its own… #12185

opened this in answer to

Parked 18d 7h ago

This makes the forge's egress refusal unmistakable to app code and people, and gives apps a check that fails on an undeclared host. The part of (d) that makes the call succeed after Allow is not proven. tsc, scripts/gate.ts and the egress, contain, template and brief tests pass here.

Notes

opened this

This makes the forge's egress refusal unmistakable to app code and people, and gives apps a check that fails on an undeclared host. The part of (d) that makes the call succeed after Allow is not proven. tsc, scripts/gate.ts and the egress, contain, template and brief tests pass here. I did not run the whole suite or design-lint. I didn't call the keep_plan or estimate tools. They aren't in my tool list, so no plan is kept on the issue and no time is promised.

Most of this already existed from #10456. The first refusal was already an event, a "Blocked: host" line with Allow on the app's settings page, a notification, and part of the crew's brief. Allow already took effect with no redeploy and committed the host to forge.json. I left that as it was.

What changed

  • (b) Refusal wording. The gate now answers with status 403 Refused by this forge, header X-Forge-Egress: refused, a new X-Forge-Egress-Host: <host>, and body refused by this forge: <host> is not in this app's forge.json egress. This is in src/apps/egress.ts. Other 403s (such as "does not resolve") are unchanged. The old wording asserted in tests (contain, egress-upstream) is updated to the new one.
  • Log line. The forge's log now says app refused an outside host with the app and host, once per app and host per hour (cellHooks in src/apps/egress_refused.ts, wired in runtime.ts).
  • (b) App template. The bundle templates/app-template.json gains src/egress.ts, with refusedByForge, checkedFetch and the best-effort host scanner. It also gains src/egress.test.ts, and an AGENTS.md rule to declare hosts.
  • (a) Check that fails on an undeclared host. egress.test.ts runs in the app's own bun test. It fails with one line: src/x.ts calls host, which forge.json "egress" does not declare: add "host" to it. It finds literal http(s)/ws(s) hosts in files that call fetch, WebSocket or EventSource. It also reads hosts from env names ending URL, HOST, ENDPOINT or BASE.
  • (a) Builder instruction. The crew's brief (ownAppLines) tells a builder to add the host to egress in the same change. I appended it to the existing first line so existing positional tests hold.
  • (d) Test. A new walk in test/egress-refused.test.ts covers the refusal, the log line, the Blocked line and Allow.
  • Docs. docs/features/blocked-hosts.md has a new section.

Not proven

  • After Allow, the walk shows the gate no longer says "refused by this forge". It does not show a successful upstream call, because a loopback target is private and the sandbox can't reach an outside host.

What I chose not to do

  • No forge-side scan in the forge's own check. The forge repo's code names many hosts, and an app created from the old template wouldn't have the test. Those apps rely on the brief line. Changing the template alone doesn't update existing apps.
  • The status line is the fixed phrase "Refused by this forge"; the host is in the body and header, so no attacker-chosen text goes in the status line.

Try it

  • Make an app's code fetch an undeclared host. The call gets 403 Refused by this forge.
  • Open the app's settings page to see the Blocked line with Allow; Allow lets the next call pass with no redeploy.
  • Run bun test src/egress.test.ts in an app created from the template; it fails until the host is in forge.json egress.

Closes #12182

Show 19 earlier items

7 earlier comments
commented

I merged the latest main into the pull and pushed it (a66f472ae). I still don't know why the preview deploy failed, and I haven't confirmed a fix.

  • App boot: I started the app locally with bun run src/main.ts. It came up and /healthz answered 200. The "uncontained" and "agent sandbox not available" warnings in its log come from running inside this sandbox.
  • Preview: the #12185 preview answers ok with 200 on /healthz.
  • Checks: bun scripts/gate.ts and bun x tsc --noEmit both passed after the merge. I did not run any test files this time, and I haven't run the full suite.

I'm making no code change, because I can't find anything on this branch that fails. The pull's only change is still the week_reading entry in scripts/unread-tables-allow.json. If the deploy fails again, I need its log to go further.

A fresh start: pull #12185's branch torque/12182-an-app-that-is-refused-an-outside-host-b lives in another fork, which the crew cannot push to, so this work began from main and does not carry that branch's commits.

commented

Still red on current main: the runs list is bare rows, not a boxed card (#9727). Fix it and push.

commented

The branch was behind main, so I merged origin/main into it and pushed. I never saw the preview's failure log, so I can't say what failed, and I never reproduced it.

On the merged tree:

  • bun scripts/gate.ts and bun x tsc --noEmit pass.
  • The app boots and /healthz answers ok.
  • The egress, template, contain and brief tests all pass (308 pass, 0 fail).
  • scripts/fast.ts named 8 test files for this change, and they pass.

I did not run the full suite or design-lint. If the preview fails again, the forge's check log will show the real cause.

What the pull contains

  • The gate refuses an undeclared host with 403 Refused by this forge, an X-Forge-Egress: refused header, and a new X-Forge-Egress-Host header. The body names the host.
  • The forge log gets one app refused an outside host line per app and host per hour.
  • The app template gains src/egress.ts, src/egress.test.ts and an AGENTS.md rule. A builder's bun test fails with a one-line message when code calls a host that forge.json egress doesn't declare.
  • The crew brief tells a builder to add the host to egress in the same change.

Not done

  • Allow succeeding on a call that was refused is still not proven.
  • I left the existing "Blocked: host" line and the Allow button as they were.

To try it

  • Open the #12185 preview.
  • Run bun test test/egress-refused.test.ts test/contain.test.ts.

A fresh start: pull #12185's branch torque/12182-an-app-that-is-refused-an-outside-host-b lives in another fork, which the crew cannot push to, so this work began from main and does not carry that branch's commits.

commented

Still red on current main: the runs list is bare rows, not a boxed card (#9727). Fix it and push.

commented

Locally, nothing is failing on the current branch, so I made no change and pushed nothing.

The failure on record is a check run against the older head d628e9bc, from before my last push. It reported 11 failing tests, including "the runs list is bare rows", "every table a migration creates is read by code", and the landing-page ssh test. Those tests live in test/runs-state-filter.test.ts, test/studio-runs.test.ts, test/unread-tables.test.ts and test/ssh-site.test.ts. They pass on the current head e6fe8bd97. That head already includes the merge of origin/main, and gate.ts and tsc are clean on it. The preview's /healthz returns 200.

I couldn't see a check result for e6fe8bd97, so I can't confirm it is green. If the forge's check on that head fails, send me its log and I'll fix what it names.

A fresh start: pull #12185's branch torque/12182-an-app-that-is-refused-an-outside-host-b lives in another fork, which the crew cannot push to, so this work began from main and does not carry that branch's commits.

commented

I merged main into the branch and pushed it. The merge ran with no conflicts, and no conflict markers remain in templates/app-template.json.

  • Checks: bun x tsc --noEmit and bun scripts/gate.ts showed no errors. scripts/fast.ts named 8 test files, and all 115 tests in them pass. I did not run the full suite; the forge runs it on the push.
  • Push: the branch now sits at 4d0effa3b, and the forge will redeploy the preview and run its check against it.

The PR description is unchanged. The merge added no code of my own.

A fresh start: pull #12185's branch torque/12182-an-app-that-is-refused-an-outside-host-b lives in another fork, which the crew cannot push to, so this work began from main and does not carry that branch's commits.

commented

main is already merged into the branch, and there was nothing new to merge or push.

I fetched again. The branch contains origin/main at d7f840c18 and matches its remote branch. The merge reports "Already up to date" and no files are in conflict, so I found nothing to resolve in templates/app-template.json.

I did not re-run the tests. The earlier merge to 4d0effa3b passed tsc, gate.ts and the 8 test files fast.ts named. If the forge still reports a conflict, it may be judging an older state of the branch, so I'd check that it picked up my last push.

A fresh start: pull #12185's branch torque/12182-an-app-that-is-refused-an-outside-host-b lives in another fork, which the crew cannot push to, so this work began from main and does not carry that branch's commits.

commented

Closed by the crew: main moved under it and 2 attempts to bring the branch up to date failed. Conflicting files: templates/app-template.json.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs