Skip to content

fix(runtime): harden shell boundaries and make CI reliable - #252

Merged
CrazyBoyM merged 8 commits into
mainfrom
fix/sandbox-shell-boundaries-20261029
Oct 29, 2026
Merged

CrazyBoyM merged 8 commits into
mainfrom
fix/sandbox-shell-boundaries-20261029

Conversation

@CrazyBoyM

@CrazyBoyM CrazyBoyM commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Paths containing spaces, quotes, command substitutions, or socat separators can break sandbox proxying or become shell syntax. This PR keeps data literal across the shell, Git, socat and desktop-launcher boundaries, fixes the macOS Git SSH regression in #251, and repairs CI so its results reflect completed, isolated tests.

Includes both original commits from @ZX1aoF in #251, preserving attribution. This replacement PR also addresses the related defects found during the command-construction audit.

Runtime changes

Boundary Problem Result
macOS environment → shell → Git #251 preserves old outer double quotes in GIT_SSH_COMMAND; Git treats the whole command as one executable name. Environment entries contain raw values. The macOS export adapter alone applies POSIX quoting, preserving the intended SSH command and ProxyCommand argument.
Linux proxy sockets Shell quoting alone does not escape socat's independent address grammar. Encode socat separators/grouping characters for both host listeners and sandbox connectors; POSIX-quote the operand when crossing a shell.
Temporary directories Hard-coded Linux mount; blank Windows fallbacks; stripped roots and POSIX literal backslashes; host-dependent simulated Windows path handling. Mount the resolved directory, skip blank fallbacks, preserve roots/literal characters, and use the selected platform's path implementation.
Editor/file/browser launchers spawn(command, args, { shell: true }) reserializes filenames as shell code. Windows start adds another parser. POSIX positional parameters, direct Unix opener argv, and quoted Windows environment slots with delayed expansion disabled preserve literal filenames.
Conversation permission updates Updating a plan-mode conversation while its UI provider is unmounted leaves the plan flag enabled. Synchronize plan state in the conversation state setter; verify the state before remounting the UI.

Configured editor commands remain trusted shell syntax. The audit also checked foreground/background/promotable runtime paths, process adapters, hooks, MCP helpers, ripgrep and clipboard launchers.

CI and test corrections

  • Keep native macOS and Windows shell/sandbox/editor/CLI regressions and production builds on all three operating systems. Run formatting, architecture checks, TypeScript and the full suite once on Linux.
  • Run independent validation steps after another step fails; preserve each failure. Install Linux bubblewrap/socat and require the network integration prerequisites in CI.
  • Replace dynamic imports of every test into one process with fresh processes and temporary configuration directories per file. A child that exits zero before Bun's completion summary fails the parent runner; a fixture verifies this.
  • Configure existing Commander subcommands to throw on help exits, so CLI help cannot terminate the suite early. Make the pre-commit hook stop on its first failed check.
  • Repair stale fixtures rather than removing permission coverage: explicitly choose cautious mode when testing prompts, create required settings/plan files, exercise disk discovery outside the mode that disables it, inspect the actual renderer wrapper, and check Git ignore behavior.
  • Preserve workspace ripgrep package files and symlinks during fixture cleanup. No tests are deleted.
  • Capture intermediate Ink frames in the interaction-test harness. Ink normally buffers CI output until unmount; the failure was reproduced with CI=true GITHUB_ACTIONS=true and all 24 interaction tests passed after the fixture correction.

Dependency audit policy

The previous full audit blocked all three jobs on 9 pre-existing high advisories in the unchanged main-branch dependency graph, skipping other validation. CI now blocks newly introduced high/critical package + installed version + advisory combinations against the trusted event base commit. Both lockfiles are compared using the same advisory set. Registry errors, malformed responses and unsupported lock records fail closed; policy fixtures cover new vulnerable versions, scoped/prerelease versions, and invalid inputs.

The 9 existing advisories remain unresolved and are listed in the job summary. No dependencies or lockfiles are changed. bun run security:audit remains the full blocking audit for release validation; in particular, the Zod major-version migration is not disguised by importing its still-vulnerable v3 compatibility code.

Validation

  • Bun 1.3.6 locked install, formatting, architecture checks, TypeScript and production build passed locally.
  • Isolated local suite: 806 passed, 14 skipped, 0 failed across 227 test files. Native-only and restricted-socket cases remain explicit skips locally.
  • Real Git with a fake SSH executable, sh/bash round trips, nested seccomp arguments, Linux mounts/argv, Windows path semantics and editor filenames are covered.
  • Real socat 1.7.4.4 address-parser round trips passed; an earlier additional check exercised 207 deterministic adversarial filenames. No external SSH service is used.
  • Final CI run 40885684848 passed on the exact head 6066ddae8ef734b0f8fec28293f60805137eca77: Ubuntu, macOS and Windows all green, including production builds on all three platforms.
  • Linux full suite: 809 passed, 13 skipped, 0 failed across 227 workspace test files. Linux network bridge prerequisites were required, so the proxy integrations could not silently skip.
  • Native macOS sandbox-exec and Windows cmd/.cmd/start regressions executed successfully. Dependency comparison reported 9 existing high/critical findings, 0 newly introduced.

References: Git SSH environment semantics, Node child-process shell argument warning, Bash quoting.

vanJker and others added 4 commits October 19, 2026 11:32
The win32 fallback in resolveSandboxTmpDir used a literal with doubled
backslashes, so it resolved to C://Windows//Temp instead of
C:/Windows/Temp. Add unit tests for the win32 branch, which had no
coverage before (TEMP precedence over TMP/USERPROFILE, and the
no-env fallback).
buildMacosSandboxExecCommand joins assignments into "export KEY=VALUE".
Temp dirs under macOS user homes can contain spaces (e.g.
/Users/John Doe/...), so an unquoted value is split by the shell and the
variable ends up truncated. Quote the value with POSIX single-quote
escaping. The Linux bwrap path is untouched: it parses key=value and
passes them as separate argv entries.
…daries

Keep sandbox environment entries raw and encode values at each POSIX,
cmd.exe, and socat boundary. Preserve target-platform temporary path
semantics and mount the configured Linux sandbox temp directory.

Cover actual Git SSH invocation, metacharacter filenames, nested seccomp
commands, proxy addresses, and native platform launchers with regressions.
Apply Commander help/exit overrides to existing subcommands so help tests
cannot terminate the full suite with a misleading successful exit.

Stop pre-commit immediately when formatting fails. Exercise that behavior
with executable hook tests and run focused platform regressions before the
independent, still-required dependency security audit in the CI matrix.
@CrazyBoyM
CrazyBoyM marked this pull request as ready for review October 29, 2026 01:34
@CrazyBoyM CrazyBoyM changed the title fix(runtime): harden sandbox and launcher argument boundaries fix(runtime): harden shell boundaries and make CI reliable Oct 29, 2026
@CrazyBoyM
CrazyBoyM merged commit ed1cfe1 into main Oct 29, 2026
3 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.

2 participants