Skip to content

fix: 🐛 Refuse sbx pull patches for what git runs and reads - #891

Closed
evaline-ju wants to merge 4 commits into
rossoctl:mainfrom
evaline-ju:sbx-hook
Closed

evaline-ju wants to merge 4 commits into
rossoctl:mainfrom
evaline-ju:sbx-hook

Conversation

@evaline-ju

Copy link
Copy Markdown
Contributor

Summary

sbx pull --apply is updated to refuse a patch that writes the core.hooksPath directory, a git directory not named .git, or a config file git reads or includes, so sandbox output can't run code on the host at the next commit. Paths are resolved through symlinks, dangling ones included, and come from git itself rather than hardcoded names.

Fixes #890

Assisted-By: Claude Code

Checklist

  • Commits are signed off (git commit -s).
  • make lint and the tests for the touched packages pass.
  • Docs: changed behavior, flags or environment variables are reflected in the relevant README or
    docs/ page, with the right maturity label (see docs/CONTRIBUTING-DOCS.md).
  • Docs: make check-links passes if any Markdown changed. - N/A
  • A new spec or ADR is registered in docs/specs/README.md or docs/adrs/README.md. - N/A

@evaline-ju
evaline-ju requested a review from pdettori as a code owner November 18, 2026 16:47
@evaline-ju
evaline-ju marked this pull request as draft November 18, 2026 16:58
@pdettori
pdettori marked this pull request as ready for review November 18, 2026 18:45
@pdettori pdettori added the ready-for-ai-review Request automated AI code review from clawgenti label Nov 18, 2026

@pdettori pdettori left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Summary

This is a careful fix for #890. core.hooksPath, a git directory not named .git, and config files (including missing and nested includes and includeIf) all come from git itself and are resolved through symlinks, dangling links included. I ran the suite on the PR head (147/147 pass) and probed it: nested includes and a non-matching includeIf are correctly refused. The one gap (inline #1) is global/XDG config files that don't exist yet, which a pull can create when the work tree is $HOME.

Author: evaline-ju (MEMBER — maintainer)
Areas reviewed: TypeScript (mocactl pull guard and tests), Go test (vmpool), docs
Agent/IDE config (.claude/.vscode): none
Commits: 4. The 3 real commits are signed off; the merge commit isn't, and DCO passes.
CI status: all checks pass

Assisted-By: Claude Code

if (hooks !== '') add(resolve(root, hooks), 'the hooks directory core.hooksPath names');
const dirs = await text(['rev-parse', '--absolute-git-dir', '--git-common-dir']);
for (const d of dirs.split('\n').filter(Boolean)) add(resolve(root, d), 'the git directory');
for (const { file } of entries(await text(['config', '--list', '--show-origin', '-z']))) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

must-fix — Global and XDG config files that don't exist yet aren't protected. git config --list --show-origin only reports files that exist, so ~/.gitconfig, $XDG_CONFIG_HOME/git/config (or ~/.config/git/config), GIT_CONFIG_GLOBAL and the system config are never candidates until they're present.

That matters in the bare-dotfiles setup #890 names, where the work tree is $HOME. I reproduced it against applyPatch with HOME=<root> and no global/XDG config: a patch creating .config/git/config is applied, and so is one creating .gitconfig. I checked that git then reads core.hooksPath from the created file (HOME=$d git -C $d config --show-origin --get core.hooksPath → file:$d/.config/git/config). This is the same reasoning the PR already uses for "a missing include too".

Suggested fix: always add git's fixed config locations as candidates, whether or not they exist (GIT_CONFIG_GLOBAL or ~/.gitconfig, ${XDG_CONFIG_HOME:-~/.config}/git/config, GIT_CONFIG_SYSTEM or the system path). They are normally outside the tree, so inTree drops them and this adds no false positives. Add a test alongside "a global config".

}

// What else git reads from the tree that could run commands: its directory and config files.
for (const [what, set, p] of [

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit — The git-dir/config cases only test refusals, and "a global config" writes the parent cfg, not cfg/global itself. One "applies" case for a sibling (for example cfg2/x, or .dfx/a next to .df) would guard the prefix match against over-blocking, the way the core.hooksPath cases do.

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Author: evaline-ju (MEMBER — maintainer)
Areas reviewed: TypeScript (mocactl pull --apply guard and its tests), the docs it touches, and the Go test merged in from #892
Agent/IDE config (.claude/.vscode): none
Commits: 4 — the 3 real commits are signed off; the merge commit 353504f7 is not, and DCO passes
CI status: 17/17 green at this head

The guard itself checks out. I verified independently:

  • git config --list --show-origin -z / --get-regexp parsing matches git 2.47's origin\0key\nvalue\0 record format, and include paths are resolved relative to the including file, so a missing include becomes a candidate;
  • core.hooksPath is read with --type=path and resolved against the worktree root (githooks(5)), through symlinks and dangling links; relative, absolute, .. and symlinked values are in the tests;
  • the patch side is compared as written rather than resolved, but that is not a bypass: git apply refuses any path beyond a symlink ("affected file '…' is beyond a symbolic link", verified with git 2.47.3) while the read side is resolved;
  • gitReads fails closed with a PushError when git cannot report its configuration.

The one gap I had not found is pdettori's inline #1: global/XDG config files that do not exist yet are unprotected, which matters when the work tree is $HOME. It is real and must be fixed; I am not repeating it inline.

Two items on top of that review:

  1. must-fix — rebase. The branch is 22 commits behind main and mergeable_state is dirty: docs/sbx/user-guide.md conflicts with #884's docs restructure (git merge-tree against main 156530f7). The 17 green checks above ran against the pre-merge base, so CI needs a re-run after the rebase.
  2. nit — the refusal message still describes everything as "agent configuration or hooks" although the guard now also refuses git config files and the git directory (inline).

The merge commit also brings #892's test-only parkedIn commit into this diff (pdettori's nit #2); landing #892 first and rebasing would leave this PR with the pull guard alone.

Assisted-By: Claude Code

if (config.length) {
throw new PushError(
`the patch writes ${list(config.map((p) => `${p} (${agentConfigWhy(p)})`))}: local ` +
`the patch writes ${list(config.map((p) => `${p} (${why(p)})`))}: local ` +

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit — the sentence right after this line still says "local agent configuration or hooks, which could run commands on this machine", but this branch now also refuses git config files and the git directory itself, which are neither agent configuration nor hooks. The per-path parenthetical (a git config file, the git directory) is accurate; suggest widening the explanation to something like "local agent configuration, hooks, or what git reads to run them".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sbx pull --apply can write files that make git run code on the host

3 participants