Skip to content

fix(server): enforce workspace scope on opencode proxy - #4189

Merged
benjaminshafii merged 4 commits into
devfrom
thin/proxy-scope-hardening
Aug 28, 2026
Merged

benjaminshafii merged 4 commits into
devfrom
thin/proxy-scope-hardening

Conversation

@benjaminshafii

Copy link
Copy Markdown
Member

Stack

Stacked on #4188. Review only commit 6ac38cbb / the diff against thin/server-phase1.

Why

Before migrating trusted consumers from OpenWork session wrappers to the native opencode SDK/proxy, the workspace-mounted proxy must guarantee that callers cannot override its directory scope. Previously, /workspace/:id/opencode/* preserved a caller-supplied x-opencode-directory header and directory query parameter.

What changed

  • Added one pure scopeWorkspaceOpencodeRequest boundary.
  • Workspace mounts now remove all caller-supplied directory query values and overwrite them with the resolved workspace directory.
  • Workspace mounts now remove/overwrite x-opencode-directory (case-insensitive via Headers).
  • Workspaces without a resolvable engine directory strip caller-supplied directory scope entirely.
  • The same sanitized query is used for:
    • regular proxy reads/writes
    • fire-and-forget session commands
    • engine event streams
    • aggregate status/pending reads
    • rollover fallback reads
  • Exposed existing path normalization for direct tests; Windows extended-length prefixes and non-Windows preservation are covered.

This intentionally does not change unmounted global /opencode/* behavior.

Verification

  • Targeted proxy/read-model tests: 23 pass / 0 fail
  • Isolated extension-preview rerun: 17 pass / 0 fail (the first full-suite run hit its existing 5s timeout once; isolated run finished in 3.65s)
  • pnpm --filter openwork-server typecheck — pass
  • pnpm --filter openwork-server build — pass
  • pnpm --filter @openwork/app typecheck — pass
  • pnpm install --frozen-lockfile --prefer-offline — pass
  • Full local server suite: 756 pass / 8 skip / 2 fail / 1 error. One failure/error is the existing local bun 1.3.5 node:sqlite limitation already baseline-verified in refactor(server): remove ~4k LOC of dead legacy surface from openwork-server #4188; the second was the unrelated extension-preview 5s timeout, which passed 17/17 on immediate isolated rerun.

Security assertions added

  • duplicate foreign directory query values are replaced with exactly one workspace value
  • foreign directory headers are overwritten
  • unrelated query parameters survive
  • no-directory workspaces cannot forward caller directory scope
  • non-ASCII directory header/query behavior
  • Windows extended-length path normalization
  • end-to-end mounted proxy escape attempt

Deletes server surface with zero production callers, verified by
repo-wide caller sweeps:

- blueprint session seeding (+ direct opencode-DB writes) — the UI
  caller was removed earlier; drops the better-sqlite3 native dep
- workspace import preview/apply routes — desktop imports archives via
  workspace-archive.mjs; the renderer client methods were never called
- POST /workspace/:id/extensions/export — no callers
- legacy /experimental/google-workspace/* routes — superseded by
  /experimental/extensions/call (gating test now probes that path)
- one-time legacy config migrations: /runtime-config/migrate route +
  helpers, the legacy-config-sweep boot sweep, and the
  Settings > Advanced migrate action (config source inspection stays)
- file-session read-batch/write-batch/renew/catalog-events routes — no
  callers anywhere (den-gateway test hits a mock upstream, still green)

Kept intact: OpenWork Connect MCP (managed MCP, connect state and
catalogs, cloud MCP health) and cloud provider injection / managed
provider auth.

openwork-server suite: 751 pass / 8 skip / 1 fail / 1 error — the same
single pre-existing env failure as clean origin/dev (bun 1.3.5 lacks
node:sqlite for workspace-kv-store.node.test.ts); zero new failures.
Server and app typechecks pass.
@vercel

vercel Bot commented Aug 28, 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 Aug 28, 2026 5:59pm
openwork-den Ready Ready Preview Aug 28, 2026 5:59pm
openwork-diagnostics Ready Ready Preview Aug 28, 2026 5:59pm
openwork-landing Ready Ready Preview, v0 Aug 28, 2026 5:59pm

@diff-warden diff-warden Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (850d48b72772259b184c3163a56764db100713cc). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run

@benjaminshafii
benjaminshafii merged commit 153cc76 into dev Aug 28, 2026
19 checks passed

This branch was successfully deployed

4 active deployments
Preview – openwork-landing — 850d48b7 Deployed Aug 28, 2026 by vercel[bot]
Preview – openwork-den — 850d48b7 Deployed Aug 28, 2026 by vercel[bot]
Preview – openwork-app — 850d48b7 Deployed Aug 28, 2026 by vercel[bot]
Preview – openwork-diagnostics — 850d48b7 Deployed Aug 28, 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