Repository navigation
fix: 🐛 Refuse sbx pull patches for what git runs and reads - #891
evaline-ju wants to merge 4 commits into
Conversation
Signed-off-by: Evaline Ju <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
pdettori
left a comment
There was a problem hiding this comment.
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']))) { |
There was a problem hiding this comment.
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 [ |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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-regexpparsing matches git 2.47'sorigin\0key\nvalue\0record format, and include paths are resolved relative to the including file, so a missing include becomes a candidate;core.hooksPathis read with--type=pathand 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 applyrefuses any path beyond a symlink ("affected file '…' is beyond a symbolic link", verified with git 2.47.3) while the read side is resolved; gitReadsfails closed with aPushErrorwhen 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:
- must-fix — rebase. The branch is 22 commits behind main and
mergeable_stateisdirty:docs/sbx/user-guide.mdconflicts with #884's docs restructure (git merge-treeagainst main156530f7). The 17 green checks above ran against the pre-merge base, so CI needs a re-run after the rebase. - 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 ` + |
There was a problem hiding this comment.
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".
Summary
sbx pull --applyis updated to refuse a patch that writes thecore.hooksPathdirectory, 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
git commit -s).make lintand the tests for the touched packages pass.docs/page, with the right maturity label (seedocs/CONTRIBUTING-DOCS.md).make check-linkspasses if any Markdown changed. - N/Adocs/specs/README.mdordocs/adrs/README.md. - N/A