Skip to content

fix: harden the sandbox, git restore, file tools and project trust - #29

Merged
jonatanaxe merged 28 commits into
mainfrom
fix/security-hardening
Oct 22, 2026
Merged

jonatanaxe merged 28 commits into
mainfrom
fix/security-hardening

Conversation

@jonatanaxe

Copy link
Copy Markdown
Member

Hardens the bash sandbox, the git restore, the file tools, project trust, the providers, the MCP server, the totems and the installers. Every fix comes with a test that fails without it; the suite passes on Linux, and go vet passes for Linux, macOS, Windows and arm64. Each commit builds and passes the tests on its own.

Fixes #24.

Bash sandbox (Linux)

  • A seccomp filter lets socket() make only TCP and UDP over IPv4/IPv6, Unix, netlink and AF_ALG sockets. MPTCP, which Landlock's TCP rules do not cover, reached a server on the internet from a closed sandbox; it now fails with EPROTONOSUPPORT (programs fall back to TCP). SCTP, ICMP, raw and packet sockets are refused, UDP too when no port is open (Landlock ABI v9 does not filter it), and so are io_uring_setup, netlink sock_diag, ptrace, process_vm_readv/writev and pidfd_getfd. An architecture the filter does not know counts as no sandbox.
  • Each command runs in its own user and PID namespace, so nothing it starts outlives it, setsid included; the process group is the fallback where user namespaces are forbidden. ouija doctor shows which.
  • The chat warns when the default sandbox cannot be enforced.

Git restore (#24)

  • Covers config.worktree, commondir, info/attributes, submodules, linked worktrees, .git swapped for a pointer, an existing core.hooksPath (husky), hook-manager configs (pre-commit, lefthook), work-tree files the config includes, nested repositories (depth 8, plus node_modules/<pkg>), and repositories the command creates.
  • The config parser follows git's grammar and is checked against git config --list on generated files; an unreadable config is put back whole.
  • Directories the user keeps under .git/hooks are no longer deleted.

File tools and approvals

  • Opens, writes and deletes go through an os.Root and the opened file is checked again, so a symlink swapped in after the check is not followed. FIFOs, hard links to protected files and writes to .git metadata are refused.
  • The approval prompt shows the resolved path, uncut, and a symlink's target; approvals are keyed on the physical path. Paths and bash commands with control or invisible characters are refused before any prompt.
  • More project secret files are protected (app/etc/env.php, auth.json, wp-config.php, *.pem, *.key, terraform.tfvars, …), with case folding on every OS.
  • Line reads, glob ** patterns and edit_file sizes are bounded.

Config and trust

  • A config that sets a key twice is refused: the review and the parse could see different values.
  • ouija trust shows every effect in full, reveals invisible characters, and asks before recording the trust (--yes for scripts). Untrusted files cannot set totem dimensions, model suggestions, more passes, a longer stream timeout or a larger context. Discovery skips configs other users own and stops at the home directory.

Providers, MCP, totems, installers

  • Redirects to another host are refused (they would carry x-api-key); bodies, stream lines, whole replies and model-list pages are capped. Debug logs and traces are written 0600.
  • The MCP server refuses tool calls from / or the home directory, also when HOME is unset.
  • doc pins UTF-8 and strips charset declarations, control bytes and favicon links (a charset trick could hide a meta refresh); review neutralises git filter drivers, which ran outside the sandbox.
  • The installers verify provenance against the release workflow on refs/heads/main, install stable releases by default, and the Windows one asks before changing PATH. The release checks run in a job without write access.

Docs

Every page was checked against the code and updated.

Not covered

  • macOS (Seatbelt) and Windows were compiled and vetted, not run. install.ps1 was not run (pwsh unavailable); install.sh passed sh -n.
  • Accepted risks stay documented: network filtering is by port, not domain; build and editor files in the project (Makefile, package.json) are writable and run later outside the sandbox; repositories nested deeper than 8 directories are not checked.

…pprovals

Open, write and delete through an os.Root on the project and check the opened file again, so a symlink swapped in after the check is not followed. Refuse FIFOs, hard links to protected files, writes to .git metadata and paths with control or invisible characters. Key approvals on the physical path and show it, symlink target included. Bound line reads, glob ** patterns and edit_file sizes, and protect common project secret files.
… the git restore

A seccomp filter lets sockets make only TCP and UDP (MPTCP, SCTP, ICMP, raw and packet refused, UDP too with no port open), refuses io_uring and reading other processes. Each command runs in its own user and PID namespace, with a process group as the fallback, so nothing it starts outlives it. The git restore now covers config.worktree, commondir, submodules, worktrees, a core.hooksPath, hook-manager configs, included configs and nested repositories, with a parser checked against git.
A key set twice could show the review one value and apply another. ouija trust now shows every effect in full, reveals invisible characters, and asks before it records the trust. Untrusted files cannot set totem dimensions, model suggestions, more passes, a longer stream timeout or a larger context. Discovery skips configs other users own and stops at the home directory.
… private

The approval prompt names the file that will be written, uncut. The editor flow writes through the sandbox, picker items are cleaned, and the debug log moves to the user cache directory with mode 0600.
A redirect to another host would carry x-api-key along. Bodies, stream lines, whole replies and model-list pages are capped. Trace files are written 0600.
Started from / or the home directory, a totem could read the whole home. Tool calls are refused there too, also when HOME is unset.
The doc HTML declares UTF-8 first and drops other charset declarations, control bytes and favicon links, so a charset trick cannot hide a meta refresh. review overrides every configured filter driver, which git ran outside the sandbox. task and sticker write through SafeWriteFile.
Verify the attestation against the release workflow on refs/heads/main, say when only the checksum was checked, and install the latest stable release unless asked for a pre-release. The Windows installer asks before it changes PATH.
make check ran in the job holding id-token and contents write. A private repository now warns that provenance is not signed.
Describe the seccomp filter, PID namespaces, the wider git restore, os.Root opens, the approval target, trust review changes, provider caps and the installer provenance checks, and fix pages that had drifted from the code.
…e restore

Issue #24 reported the restore deleting directories inside .git/hooks. The test fails on the code before this branch and passes now.
The seccomp filter refuses UDP with no port open, so only a sandbox with an open port sends UDP on ABI v9.
Tag characters (U+E0000–E007F) and the other format characters are invisible in the approval prompt but read by the model; they are refused before any prompt, like the bidi and zero-width ones.
A non-blocking write open of a FIFO with no reader fails with ENXIO, which macOS words differently from Linux; it is now refused as a file that is not regular.
On macOS /home is a link to /System/Volumes/Data/home, which looked deep enough once resolved when no home folder is known.
staticcheck ST1018 flags format characters written literally in string and rune literals.
A review of every page against the code found stale check orders, approval options, file locations, limits and environment variables, an example that did not compile, and a missing OUIJA_SANDBOX_POLICY entry.
Discovery compared paths as text, so a Windows short name (RUNNER~1) or a symlinked home walked past the home directory. Directories are now compared as files.
The restore removed the hooks directory git init had just made, and a confined git init raised two notices. A new directory runs nothing, and a confined command's ordinary git changes no longer raise the git guard notice (the restore already put back what runs).
With no port open, npm view spent 70 seconds retrying a registry it could never reach before it failed. npm_config_fetch_retries=0 and PIP_RETRIES=0 make it fail at once; a value the user set is kept.
A read of a missing file showed as a success in the trace.
An absolute path was joined onto the root: reading the project's own file by it found nothing, and writing it created a stray <root>/home/... tree while reporting the absolute path. Inside the project it now names the file; outside it is refused like ../ with a hint to use a relative path.
… image alike

The install command and its GIF sat below the explanation and the diagram; they now follow the demo, and the explanation moves under its own heading. Every screenshot and GIF is centred at 800 pixels, in the README and in the install guide.
The demo had no window frame while the install GIF had one; both now share the title bar, dots and border. Frames and timing are unchanged.
The four README screenshots were captured by hand: each had its own size, one an empty band, and one showed a task dimension that does not exist. make screens renders them from the chat model at one terminal size, in the install GIF's window frame, and captures them with headless Chrome, so they match each other and the current version.
… bar

The images now bring their own window frame; the site's wrapper drew a second one.
@jonatanaxe
jonatanaxe merged commit 74fd59e into main Oct 22, 2026
8 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.

Linux sandbox: the git restore after a confined command can be bypassed

1 participant