Skip to content

Harden the tool gate, trust and MCP; turn the bash sandbox on by default - #22

Merged
jonatanaxe merged 12 commits into
mainfrom
fix/tool-gate-audit
Oct 22, 2026
Merged

jonatanaxe merged 12 commits into
mainfrom
fix/tool-gate-audit

Conversation

@jonatanaxe

Copy link
Copy Markdown
Member

Three security audit rounds over the tool gate, project trust, the MCP server and the installers, plus a sandbox redesign based on what Codex, Claude Code (sandbox-runtime), Cursor and Gemini CLI do. Every fix has a test that fails without it.

Bash sandbox, now on by default where the OS can enforce it (Landlock on Linux, Seatbelt on macOS):

  • writes only to the project, a private temp dir and a private build cache; the user's real caches stay read-only (a writable one let a confined command plant code that runs later outside the sandbox);
  • reads only system directories, the project and the toolchain parts of the home directory, never the credentials next to them;
  • network closed, DNS included (Landlock v10 filters UDP); any listed TCP port also opens DNS;
  • what a confined command leaves for git to run (hooks, core.fsmonitor, ! aliases, filters…) is put back after it;
  • macOS profile modelled on Codex's: minimal mach services and sysctls, no LaunchServices or Apple events (open, osascript), no Docker socket, no other terminals' ttys, .git hooks/config read-only and .git not movable;
  • a command may run outside the sandbox only after the user approves that exact command ("unsandboxed": true); never without an approval UI, and allowUnsandboxed: false removes it.

Tool gate and protected paths: approved escapes, shadowed built-in names, approval keys, path checks, doom-loop resets, directory deletes, NUL bytes; more credential files, platform name folding (case, trailing dots, 8.3 names), hard links; credentials in env values.

Trust and config: symlinked configs from outside the project, rules, raised budgets and provider/model switches need ouija trust; no relative global config; chat saves keep the project's own sandbox.

MCP: bounded messages, at most 8 concurrent calls, duplicate ids refused, stricter resources/read.

Installers: absolute install dir without shell metacharacters.

Not covered yet, and documented: network allowlisting by domain (it is by TCP port), and on Linux .git stays writable during a command (put back after it). The macOS and Windows parts are verified by this PR's CI only.

… gate

Fixes from three audit rounds, each with a test that fails without it:

- Tool gate: an approved escape no longer leads to a protected target, an
  extra tool cannot reuse a built-in name, session approvals cover every
  argument of non-file tools, the checked path is the one the tools touch,
  cached approvals no longer reset the doom-loop counter, deleting a
  directory keeps protected files, and a bash command with a NUL byte is
  refused (it let an ordinary approval spell the escape's key).
- Protected paths: more credential files (git, gh, cargo, maven, gradle,
  Hugging Face, uv, terraform, vault, rclone, keyrings, npmrc, SSH keys by
  name, tfstate), .git/config and .git/hooks, /proc and /sys; names are
  matched the way macOS and Windows open them (case folding, trailing dots,
  8.3 short names); hard links to credential files are refused.
- bash environment: credentials are also recognised by their value
  (provider key formats, a password in a URL or DSN), whatever the name.
- Undo refuses a file that a symlink now points elsewhere.
- Sandbox: on by default where the OS can enforce it (Landlock on Linux,
  Seatbelt on macOS, modelled on Codex's profile), with a private temp dir
  and a private build cache; only the toolchain parts of the home directory
  are readable; DNS opens with any TCP port (Landlock v10 filters UDP);
  what a confined command leaves for git to run is put back; a command may
  run outside the sandbox only after the user approves that exact command.
- A discovered config whose real file is outside its directory is refused
  (a symlink borrowed another project's trust or overwrote the global
  config), and the global config is never rewritten as a project config.
- rules, a budget above the defaults, and a provider or model other than
  the user's own now need `ouija trust`; `ouija trust` shows them and the
  sandbox paths and network a config opens.
- Without an absolute config directory there is no global config: it used
  to be a relative path a cloned repository could ship.
- Chat saves keep the project's own sandbox section, not the merged one.
- The global sandbox setting can turn the default sandbox off, and a
  project may forbid the unsandboxed escape but never allow it over the
  global; doctor reports the default sandbox.
…urces/read

Messages over 4 MiB get a parse error and the stream continues; at most 8 calls run at once; a request reusing a running id is refused (ids compared by exact value); resources/read requires the ouija://project/ scheme, serves nothing when the root is /, the home folder or above it, reports relative paths only and stays silent once cancelled; the install backup no longer follows a planted symlink.
…cters

The folder is written into the shell rc file: a relative one put the current directory on PATH, and $, backticks, quotes or backslashes ran as code in every new shell. install.ps1 requires an absolute -InstallDir too.
Security, config schema, configure, CLI, environment and MCP pages, the README and the site now cover the bash sandbox on by default (and what it reads, writes and leaves out), the approved unsandboxed escape, the new trust-only keys, the protected paths and the MCP server's limits.
First CI run on those systems: macOS now refuses to run open, osascript and osacompile at all (osascript ran a local script), and on Windows the config directory is normalized like the checked path, so an 8.3 short name in it (C:\Users\RUNNER~1) no longer hides ouija's global config from the protected-path check. The tests now expect macOS's cache dir and its stricter git rules.
Every free model in the list was gone from OpenRouter; the list now has current ones with tool support, led by openrouter/free, which routes to whatever free model is up. The docs' examples use openrouter/free so they stop going stale.
…ocumented

internal/doccheck already checked the links; it now also walks the config structs' JSON keys, the CLI's command table with the registered totems, and every OUIJA_* variable the code reads, and requires each in docs/reference. A new one can no longer ship without its docs.
A page-by-page audit against the code: the trust-only keys, the full protected-path list, a safe sandbox example (the old one made the real Go cache writable), the private temp and cache, the git restore, the order of checks with the NUL refusal and the unsandboxed step, the built-in tools and their parameters, MCP limits, the env filter, the doctor checks, exit output order, the totems in the CLI reference and on the site, the installers' options and the dependencies. Claims the code did not back (a provider fallback) are gone.
@jonatanaxe
jonatanaxe merged commit 29b7a94 into main Oct 22, 2026
8 checks passed
@jonatanaxe
jonatanaxe deleted the fix/tool-gate-audit branch October 22, 2026 00:21
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