Skip to content

fix(server): OS-trust egress helper for all external fetches, bare fetch banned - #2835

Merged
benjaminshafii merged 1 commit into
devfrom
fix/server-os-trust-egress
Jul 16, 2026
Merged

benjaminshafii merged 1 commit into
devfrom
fix/server-os-trust-egress

Conversation

@benjaminshafii

Copy link
Copy Markdown
Member

Summary

Root-cause fix #3 from the corporate-TLS field incident (follow-up to #2823, which fixed one call site). The server had ~15 external egress points on bare undici fetch — every one of them fails behind enterprise TLS interception while Electron/engine succeed, producing the same false-negative ghost class. This PR centralizes egress and bans regressions.

  • New apps/server/src/server-fetch.ts: externalFetch (Electron net.fetch when embedded → Chromium stack, OS trust store; global fetch standalone/tests) and loopbackFetch (documented alias for 127.0.0.1 / managed engine traffic, where CA trust is irrelevant and SSE/proxy streaming perf matters)
  • Migrated: cloud MCP probes, remote workspace discovery, GitHub skill-hub + plugin bundles, OpenAI image gen, Google Workspace/token broker, voice broker, Realtime secrets, runtime-control URL → externalFetch; session/SSE engine proxy, instance dispose, engine MCP register/disconnect → loopbackFetch (full file:line inventory in the commit-adjacent notes below)
  • Toy UI's embedded browser-side script strings switched to window.fetch (they execute in the browser, not the server)
  • Guard: no-bare-fetch.test.ts recursively fails on any bare fetch( in apps/server/src (excluding tests, server-fetch.ts, and src/opencode-plugins/ — plugin bundles run inside the Bun engine, which trusts the OS store, and must not import electron)
Call-site inventory

externalFetch: cloud-mcp-health.ts:1074,1170 · routes/workspaces.ts:137 · skill-hub.ts:36,50,234 · claude-plugin-bundle.ts:101,113 · extensions/openai-image-generation.ts:116 · extensions/google-workspace.ts:512,1116,1254 · server.ts:475,519,3040

loopbackFetch: server.ts:1038 (async session command proxy) · server.ts:1047 (hot OpenCode proxy/SSE) · server.ts:3198 (instance dispose) · server.ts:3367 (runtime MCP registration) · server.ts:4040 (MCP disconnect)

Validation

  • pnpm --filter openwork-server exec bun test src/no-bare-fetch.test.ts — 1 pass / 0 fail
  • pnpm --filter openwork-server test — 451 pass / 0 fail (existing tests stub globalThis.fetch; externalFetch falls back to it outside Electron, so stubs keep working — verified by the green suite)
  • pnpm --filter openwork-server typecheck — clean
  • rg --pcre2 '(?<![.\\w])fetch\\s*\\(' over migrated scope — no hits outside exclusions

Not run: live enterprise-TLS e2e (Electron-embedded net.fetch path behind a MITM CA) — that's the daytona-windows-cert sandbox; recommended as the release-gate follow-up for this class.

Note: touches cloud-mcp-health.ts alongside the parallel engine-attested-health PR (different regions; second-to-merge takes a trivial rebase).

…tch banned

Every bare Node fetch in the server (undici) bypasses the OS certificate
store, so on enterprise machines with TLS interception any external
call fails with a generic 'fetch failed' while Electron and the engine
succeed (field incident class). One shared helper now routes egress:
externalFetch prefers Electron net.fetch (Chromium stack, OS trust)
when embedded and falls back to global fetch standalone; loopbackFetch
documents engine/127.0.0.1 traffic where CA trust is irrelevant and
streaming performance matters. All server call sites migrated; a guard
test fails the build on new bare fetch call sites. Engine-side plugin
bundles (src/opencode-plugins) are deliberately out of scope — they run
inside Bun, which trusts the OS store.
@vercel

vercel Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openwork-app Ready Ready Preview, Comment Jul 16, 2026 4:46am
openwork-den Ready Ready Preview, Comment Jul 16, 2026 4:46am
openwork-den-worker-proxy Ready Ready Preview, Comment Jul 16, 2026 4:46am
openwork-landing Ready Ready Preview, Comment, Open in v0 Jul 16, 2026 4:46am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
openwork-diagnostics Skipped Skipped Jul 16, 2026 4:46am

@benjaminshafii

Copy link
Copy Markdown
Member Author

fraimz — ✅ PASSED

1 passed · 0 failed · 0 skipped — run 2026-07-16T10-27-00-370Z

Full frame proof with validated screenshots: evals/results/2026-07-16T10-27-00-370Z/fraimz.html (re-run: pnpm fraimz --flow windows-enterprise-ca-rootcause)

✅ windows-enterprise-ca-rootcause — Windows packaged app uses OS trust and engine-attested Cloud MCP readiness

Internal demo

  1. The packaged Windows app reproduces CA trust on/off/on with a restored final state

    🎙 We start with the repeatable control: the same packaged app can prove when the corporate CA is trusted, when it is removed, and when it is restored. The evidence stays focused on the root-cause signals, not secret material or process details.

    • ✅ control artifact ok is true
    • ✅ control artifact recorded an Electron Windows user agent
    • ✅ repro CA count in the Windows system store is greater than zero
    • ✅ repro CA count in default roots is zero
    • ✅ phase A rootCount is 1
    • ✅ phase A healthy request returns 400 openwork_workspace_not_found
    • ✅ phase A broken request returns 502 cert authority invalid
    • ✅ phase C rootCount is 1
    • ✅ phase C healthy request returns 400 openwork_workspace_not_found
    • ✅ phase C broken request returns 502 cert authority invalid
    • ✅ phase B rootCount is 0
    • ✅ phase B formerly healthy request returns 502 cert authority invalid
    • ✅ final state restored exactly one root
    • ✅ final state reports CDP ready
  2. The installed Electron app reports a running OpenWork server and healthy managed OpenCode loopback

    🎙 Next we confirm the real installed app is the one under test. Its Electron bridge reports a running OpenWork server, the expected workspace, a healthy managed OpenCode engine, and a live server-connected event stream.

    • ✅ renderer user agent is Electron on Windows
    • ✅ OpenWork server is running and has a base URL
    • ✅ /workspaces contains ws_c0107cd3f4f6
    • ✅ proxied /workspace/.../opencode/global/health returns HTTP 200
    • ✅ proxied OpenCode health is healthy version 1.17.11
    • ✅ /opencode/event returns a text/event-stream
    • ✅ /opencode/event yields a server.connected frame
  3. Default Cloud MCP health and Connect state stay ready without touching the fixture

    🎙 The default Connect health check now trusts the engine attestation without opening a direct network probe. Fixture counts stay still while the health and Connect state both report ready and usable.

    • ✅ fixture task is running and listening before reconcile
    • ✅ reconcile returns HTTP 200
    • ✅ reconcile health phase is ready
    • ✅ reconcile health is usable
    • ✅ reconcile health engine status is connected
    • ✅ reconcile performs the direct readiness probe
    • ✅ reconcile desired and applied revisions match
    • ✅ default Cloud MCP health returns HTTP 200
    • ✅ default health phase is ready
    • ✅ default health is usable
    • ✅ default health engine status is connected
    • ✅ default health firstFailure is null
    • ✅ default health desired and applied revisions match
    • ✅ default health leaves direct.checked false
    • ✅ /experimental/connect/state returns HTTP 200
    • ✅ Connect state reports Cloud MCP present
    • ✅ Connect state cloudHealth phase is ready
    • ✅ Connect state cloudHealth is usable
    • ✅ Connect state cloudHealth engine status is connected
    • ✅ Connect state cloudHealth firstFailure is null
    • ✅ Connect state cloudHealth desired and applied revisions match
    • ✅ Connect state cloudHealth leaves direct.checked false
    • ✅ fixture JSON-RPC method counts are unchanged by default health and Connect state
  4. health?probe=1 performs exactly one MCP initialize/initialized/tools-list handshake

    🎙 When the reviewer asks for an explicit probe, the direct MCP handshake happens exactly once. The OS-trusted path lists both cloud tools and the fixture count advances by initialize, initialized notification, and tools/list.

    • ✅ probe Cloud MCP health returns HTTP 200
    • ✅ probe health phase is ready
    • ✅ probe health is usable
    • ✅ probe health engine status is connected
    • ✅ probe health firstFailure is null
    • ✅ probe health desired and applied revisions match
    • ✅ probe health sets direct.checked true
    • ✅ direct tools/list includes search_capabilities
    • ✅ direct tools/list includes execute_capability
    • ✅ probe health has no direct failure
    • ✅ fixture method delta for initialize is exactly 1
    • ✅ fixture method delta for notifications/initialized is exactly 1
    • ✅ fixture method delta for tools/list is exactly 1
  5. A direct probe outage reports probe_unreachable without overriding engine-connected readiness

    🎙 If that diagnostic probe cannot reach the fixture, the app still reports the engine truth as ready and usable. The direct failure is clearly diagnostic, and the flow restarts the fixture before it exits.

    • ✅ fixture listener is down after stopping only the scheduled task
    • ✅ probe failure health still returns HTTP 200
    • ✅ probe failure health phase is ready
    • ✅ probe failure health is usable
    • ✅ probe failure health engine status is connected
    • ✅ probe failure health firstFailure is null
    • ✅ probe failure health desired and applied revisions match
    • ✅ probe failure leaves direct.checked false
    • ✅ probe failure code is probe_unreachable
    • ✅ probe failure reports no missing direct tools
    • ✅ fixture listener is restored
    • ✅ fixture scheduled task is running after restart
  6. The installed packaged steering smoke keeps engine-ready truth authoritative across all cases

    🎙 Finally we verify packaged steering consumes the same engine truth. Ready, auth-needed, thrown, unknown, and missing-entry cases choose the expected guidance without unnecessary server fetches.

    • ✅ packaged steering smoke result ok is true
    • ✅ all five packaged steering cases are present
    • ✅ connected ready case has zero server fetches and no repair guidance
    • ✅ needs_auth case gives sign-in guidance with zero server fetches
    • ✅ thrown case stays neutral with zero server fetches
    • ✅ unknown case stays neutral with zero server fetches
    • ✅ missing entry case performs exactly one fallback
    • ✅ result includes an installed bundle hash or an installed resources artifact path
    • ✅ installed bundle hash is present
    • ✅ Script frame 1 narrated: "We start with the repeatable control: the same packaged app can prove when the corporate"
    • ✅ Script frame 2 narrated: "Next we confirm the real installed app is the one under test. Its Electron bridge report"
    • ✅ Script frame 3 narrated: "The default Connect health check now trusts the engine attestation without opening a dir"
    • ✅ Script frame 4 narrated: "When the reviewer asks for an explicit probe, the direct MCP handshake happens exactly o"
    • ✅ Script frame 5 narrated: "If that diagnostic probe cannot reach the fixture, the app still reports the engine trut"
    • ✅ Script frame 6 narrated: "Finally we verify packaged steering consumes the same engine truth. Ready, auth-needed, "

@benjaminshafii
benjaminshafii merged commit 0004662 into dev Jul 16, 2026
6 checks passed
@benjaminshafii

Copy link
Copy Markdown
Member Author

fraimz — ✅ PASSED

1 passed · 0 failed · 0 skipped — run 2026-07-16T16-10-49-607Z

Full frame proof with validated screenshots: evals/results/2026-07-16T16-10-49-607Z/fraimz.html (re-run: pnpm fraimz --flow windows-enterprise-ca-error-state)

✅ windows-enterprise-ca-error-state — Windows enterprise CA error state: old build fabricates outage, fixed build trusts engine truth

Internal demo

  1. The old build reports cloud_tools_missing even though the engine and Schannel endpoint are healthy

    🎙 We begin on the same machine before the fix: the engine is connected and Schannel can list the tools, but OpenWork reports a fabricated Cloud tools outage. This frame captures the exact contradiction that caused the model-facing error state.

    • ✅ pre-fix artifact user agent contains OpenWork/0.17.29
    • ✅ engine openwork-cloud status is connected
    • ✅ direct Schannel tools/list contrast returned HTTP 200
    • ✅ direct Schannel tools/list includes both expected tools
    • ✅ pre-fix default health phase is cloud_tools_missing
    • ✅ pre-fix default health is not usable
    • ✅ pre-fix first failure is cloud_tools_missing
    • ✅ pre-fix direct error contains fetch failed
    • ✅ pre-fix delivery appliedRevision is null
    • ✅ connect/state cloudHealth also reports cloud_tools_missing
  2. The old steering converts the fabricated outage into repair/refusal guidance

    🎙 The old steering then turns that fabricated outage into user-facing refusal guidance. The model is told the Cloud connection is not ready and to send the user to Repair and test.

    • ✅ pre-fix instruction says the connection is not ready
    • ✅ pre-fix instruction sends the user to Repair and test
    • ✅ pre-fix instruction names cloud_tools_missing
  3. The fixed build reports ready by default and the live app agrees

    🎙 Now the fixed build runs on the same machine, same corporate CA, and same endpoint without reconciling a new config. Default health trusts the engine, the fixture stays untouched, and the live app reports the same ready state.

    • ✅ fixed artifact user agent contains OpenWork/0.17.30
    • ✅ fixed artifact did not perform reconcile
    • ✅ fixed default health phase is ready
    • ✅ fixed default health is usable
    • ✅ fixed default health engine status is connected
    • ✅ fixed default health does not run a direct probe
    • ✅ fixed default health firstFailure is null
    • ✅ fixed default health desired and applied revisions match
    • ✅ fixed default-health fixture delta is zero
    • ✅ both before and fixed exe SHA256 prefixes are recorded
    • ✅ live fixed app default health request returns HTTP 200
    • ✅ live fixed app reports ready usable engine-connected default health
  4. The fixed build probes only on demand and steers the model toward Cloud tools

    🎙 Finally, the fixed build still supports an explicit diagnostic probe on demand. The probe performs one handshake, Connect remains ready, and steering tells the model to use the Cloud tools instead of refusing.

    • ✅ fixed explicit probe sets direct.checked true
    • ✅ fixed explicit probe includes both direct tools
    • ✅ fixed explicit probe delta is exactly one initialize, initialized notification, and tools/list
    • ✅ fixed connect/state remains ready and usable
    • ✅ fixed steering reports ready Cloud tooling
    • ✅ fixed steering fetchCount is zero
    • ✅ fixed steering omits not-ready and Repair and test guidance
    • ✅ Script frame 1 narrated: "We begin on the same machine before the fix: the engine is connected and Schannel can li"
    • ✅ Script frame 2 narrated: "The old steering then turns that fabricated outage into user-facing refusal guidance. Th"
    • ✅ Script frame 3 narrated: "Now the fixed build runs on the same machine, same corporate CA, and same endpoint witho"
    • ✅ Script frame 4 narrated: "Finally, the fixed build still supports an explicit diagnostic probe on demand. The prob"

This branch was successfully deployed

4 active and 1 inactive deployments
Preview – openwork-den-worker-proxy — 0281c3f9 Deployed Jul 16, 2026 by vercel[bot]
Preview – openwork-landing — 0281c3f9 Deployed Jul 16, 2026 by vercel[bot]
Preview – openwork-den — 0281c3f9 Deployed Jul 16, 2026 by vercel[bot]
Preview – openwork-app — 0281c3f9 Deployed Jul 16, 2026 by vercel[bot]
Preview – openwork-diagnostics — 0281c3f9 Deployed Jul 16, 2026 by vercel[bot]
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