Skip to content

fix(sandbox): harden the git tool, which runs on the host, when a command consumer is on (#748) - #873

Merged
ajianaz merged 9 commits into
developfrom
fix/vcs-tool-sandbox-hardening
Nov 16, 2026
Merged

ajianaz merged 9 commits into
developfrom
fix/vcs-tool-sandbox-hardening

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

The git tool (status, diff, add, commit; Risk::Write through the Approver) runs on the host, outside the command sandbox, and is how a model commits when .git is read-only in the sandbox. It was not hardened. This PR hardens it when a command consumer is on (no new tool, no writable .git, no git = "write" option) and points the model and the owner at it. Refs #748.

Why

The tool runs on the HOST and git executes what the repository config, hooks, attributes, environment and PATH name. With the consumers on, a sandboxed command cannot write .git in a repository that existed at launch (#849), but: the owner's config can name core.hooksPath scripts inside the writable workspace or a core.fsmonitor command; in a workspace with no repository a sandboxed command can git init and plant a hook, a filter.x.clean, a gpg.program, a bare layout or a nested repository; and a tole process started by a sandboxed command inherits an environment and PATH that name config files and programs. A start-up snapshot of "the repository that existed" was tried and dropped: the tool is rebuilt per serve session, cron run, resume and child, so a repository planted in an earlier session looks like the owner's. The rule: with any command consumer on, no host-side code execution is reachable from state a sandboxed command can write, whenever and by whomever the repository was created.

Changes

  • integrations/git.rs, invocation: ALWAYS -c core.fsmonitor=false. With any command consumer on (Consumer::ALL, cron included): -c core.hooksPath=/dev/null and --no-verify on commit (no hook runs for a commit made through the tool, the owner's own pre-commit and commit-msg included; a human's own git commit still runs them); a FIXED git binary and PATH (git is looked up in /usr/local/bin, /usr/bin, /bin and /opt/homebrew/bin only, never under the workdir, the temp dir, $HOME or the account home; that list is also the PATH git's helpers get; no git there is a refusal naming the directories; an embedder with git elsewhere uses an absolute GitTool::with_bin; the CLI has no setting, so the owner links git into a trusted directory); no inherited descriptor above stderr (close-on-exec, Linux 5.11+); an ALLOWLIST environment instead of the tole process's (locale, TZ, TERM, HOME from the account's passwd entry and never $HOME, GIT_CONFIG_NOSYSTEM=1, GIT_TERMINAL_PROMPT=0; GIT_AUTHOR_*, GIT_COMMITTER_*, USER, LOGNAME, TMPDIR and everything else are dropped, so identity comes only from config or the passwd entry); --no-ext-diff --no-textconv on diff; --ignore-submodules=all on status and diff. With no consumer on the tool behaves as before apart from core.fsmonitor.
  • integrations/git.rs, per-call vet (vet_repository, fail closed, no snapshot): before every op git rev-parse (same hardened options) says which git directory git really uses. The tool refuses unless it is a plain .git DIRECTORY at the work tree root, not bare, with the common dir equal to it (a bare layout including a bare ancestor, a linked worktree, a submodule gitdir file and a separate git dir are refused). Then git config --file <gitdir>/config --list -z (no includes followed, nothing executed) is checked against an ALLOWLIST of inert keys (inert_key): any other key (filter.*, include.*, alias.*, core.fsmonitor, core.hooksPath, core.sshCommand, core.worktree, gpg.*, credential.*, extensions.*, unknown keys) makes the tool refuse, naming the key and the way out. add is also refused while the index holds a submodule entry.
  • sandbox.rs: check_grant also refuses a grant that holds the passwd home, as it does for $HOME, so ~/.gitconfig is never sandbox-writable. paths.rs: account_home() (None on non-unix hosts; the command sandbox is Linux only).
  • run_command.rs, jobs.rs, sandbox/command.rs: summaries and one tole doctor line say git writes fail inside the sandbox, that the git tool is the way out, that hooks are off for its commits, and when it refuses.
  • Docs: design note section 9.3, threat model, CHANGELOG, module doc. tole-core stays platform-agnostic; no new Risk, no new tool; the Destructive enforcement layers are untouched.
  • Residuals (documented): a still-running sandboxed process (a job_start from an earlier turn, a long command) that writes the config between the vet and the spawn can get that SAME call to execute it, because the spawned git re-reads .git/config after the vet (later calls refuse; the window is narrow and there is no cheap fix for wildcard keys); a sandbox-written .gitattributes or .git/info/attributes with * filter=lfs triggers the OWNER's global filter.lfs.* command; gc.autodetach can leave a detached git maintenance run --auto that outlives the vet; an owner (global) include.path into the workspace is not vetted; a program the owner's global config names is looked up in the fixed PATH, and a process run with another $HOME uses the account's global config; GIT_CONFIG_NOSYSTEM=1 drops /etc/gitconfig and can cause "dubious ownership" or a missing identity.

Callers and impact (grep, each checked): GitTool::execute is the only place the tool spawns git; GitTool::new().in_dir(..) is how tool_roster.rs registers it; GitTool has no struct-literal users outside git.rs (the new fields are private; with_env and with_bin are additive public API); command_line and the approval describe string are unchanged; check_grant applies to every grant (command consumers, MCP server profiles, cron). Behaviour change with a consumer on: no hook runs for the tool's commits; the tool refuses a non-plain layout, a config with a non-inert key, or a host without git in the trusted directories; a workspace that holds the passwd home is refused. Tests to rerun: integrations::git unit tests, git_tool_hardening, git_tool_default, command_tests, command_sandbox*, layering.

Testing

  • git_tool_hardening (consumers on): an owner repository with inert config works and no hook runs; a repository planted before a freshly built tool is refused; bare layout in an ancestor, a bare workdir and a linked worktree are refused; each key that names a program or a file is refused and its marker never fires; a nested repository with a hostile filter never runs. git_tool_default (no consumer): the tool does not refuse and fsmonitor never runs. Unit tests: exact invocation() argv, inert_key allow and deny lists, the environment allowlist, a check_grant test for the passwd home, an inherited-descriptor test.
  • Fail-first: with each hardening neutered by hand the matching test fired its marker or failed, then passed once restored. a_hostile_process_environment_never_reaches_git runs the production GitTool::new() path in a child process under hostile GIT_CONFIG_*, HOME and XDG_CONFIG_HOME (no set_var in the test process; a no-hostile-env control round must see add and commit succeed). a_hostile_path_never_supplies_the_git_binary puts fake git and sh on hostile absolute PATH entries inside the workdir and a temp dir: no marker, the real git commits.
  • Gates on the final head: cargo fmt --all; cargo clippy --workspace --all-targets -- -D warnings (default and --no-default-features); cargo clippy -p tole-core; cargo check -p tole-core --no-default-features --tests; cargo test --workspace and cargo test -p tole-core (default and --no-default-features --features shell-tools) with TOLE_REQUIRE_BWRAP=1: green. CI: all checks green, Cora Review "No issues found" on the final head. The one Test failure seen on this head was tui_steers_queues_and_returns_the_queue_on_cancel, a known flaky TUI test; the failed job was re-run and passed.
  • Review history: four independent agent reviews and two real Cora findings (the vet reads one file while git also takes config from the process environment; the inherited PATH resolves git) shaped this PR; each is fixed with a fail-first test. cora is not installed here, so scripts/review-local.sh was not run; the CI Cora Review is the gate.

…mand consumer is on (#748)

Always pass -c core.fsmonitor=false. With a command consumer on also pin
core.hooksPath to the read-only <repo>/.git/hooks of a real .git directory
(/dev/null otherwise), set GIT_CONFIG_NOSYSTEM=1 and pass --no-ext-diff
--no-textconv to diff, so a core.hooksPath into the writable workspace
(husky style) and a core.fsmonitor command no longer run on the host through
the tool, while the owner's installed hooks still do. The run_command and
job_start summaries and tole doctor tell the model that git writes fail in the
sandbox and to use the git tool.
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

…sted at start-up, and say what the hardening does not cover (#748)

With a command consumer on, the tool trusts only a real .git directory that
enclosed its workdir when it was built (a snapshot, re-checked per call against
a swap) and refuses a bare-repository workdir, so a repository a sandboxed
command created (hook, filter, gpg.program, .gitattributes) never runs on the
host. Docs state the residuals: owner hooks run workspace content, an owner
include.path into the workspace, GIT_CONFIG_NOSYSTEM side effects. The doctor
line no longer claims hooks are pinned in the refused case. The fixture no
longer calls set_var from threads.
…trusting a start-up snapshot (#748)

With a command consumer on, the git tool now pins core.hooksPath=/dev/null
and --no-verify, sets GIT_CONFIG_NOSYSTEM=1, passes --ignore-submodules=all
to status and diff, and before every op asks git which git directory it
uses. It refuses anything but a plain .git directory at the work tree root
(not bare, not a linked worktree, submodule gitdir file or separate git dir),
then reads that config without running anything and refuses any key outside
an allowlist of inert ones. add is refused while the index holds a submodule
entry. The start-up snapshot is removed.
The spawned git re-reads .git/config after the vet, so a still-running
sandboxed process that writes it in that window can get the in-flight call
to execute planted content; later calls refuse. Also document that a
sandbox-written .gitattributes can trigger the owner's global filter.lfs
command on attacker-influenced input, and that gc.autodetach can leave a
detached maintenance run that outlives the vet. Comments and docs only.
for k in [
"GIT_DIR",
"GIT_WORK_TREE",
"GIT_COMMON_DIR",
…nd consumer is on (#748)

The vet reads one file, <gitdir>/config, but git also takes config and
programs from the process environment: GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM,
GIT_CONFIG, GIT_CONFIG_COUNT/KEY_n/VALUE_n, GIT_CONFIG_PARAMETERS, HOME and
XDG_CONFIG_HOME, GIT_EXEC_PATH, GIT_ATTR_SOURCE, LD_PRELOAD and more. A tole
started by a sandboxed command inherits whatever that command set, so the
host-side tool could run a filter or program the vet never saw.

With a consumer on, git now gets only PATH (absolute entries), locale, TZ,
TERM, the temp dir, HOME from the account's passwd entry and
GIT_CONFIG_NOSYSTEM / GIT_TERMINAL_PROMPT=0. Behaviour with no consumer is
unchanged. Tests run the production GitTool::new() path in a child process
under each hostile variable; none may fire a marker.
…ptors, when a command consumer is on (#748)

A tole started by a sandboxed command inherits that command's PATH, and the
host-side tool resolved `git` (and the sh, gpg, ssh and git-* helpers git
spawns) against it, so a planted program in a writable directory ran with no
vet involved.

With a consumer on, git is now looked up only in /usr/local/bin, /usr/bin,
/bin and /opt/homebrew/bin (never under the workdir, the temp dir or a home),
that list is also the PATH git gets, and no git there is a clear refusal. An
embedder with git elsewhere sets an absolute GitTool::with_bin. Also: no file
descriptor above stderr is inherited, GIT_AUTHOR_*, GIT_COMMITTER_*, USER,
LOGNAME and TMPDIR are no longer passed, the passwd home is None on non-unix
hosts, and a sandbox grant that holds the account's passwd home is refused
like $HOME (the git tool reads its global config there).
@ajianaz
ajianaz merged commit d246f15 into develop Nov 16, 2026
37 of 38 checks passed
@ajianaz
ajianaz deleted the fix/vcs-tool-sandbox-hardening branch November 20, 2026 08:39
ajianaz added a commit that referenced this pull request Dec 2, 2026
…26-12-02) (#808) (#1389)

The Open work by area table of docs/epics.md carried its 2026-11-15 stamp: closed issues were still listed as open, the container section predated the first nightly publish, and Track F was absent. The table is rewritten from a one-by-one re-check of the tracker on 2026-12-02: closed items moved out, the container row records the daily green nightly and the public GHCR package (anonymous pull verified, plus a local arm64 build and smoke run of the committed Dockerfile), Track F carries its model-first slices and the F1 gate that is next. The owner-decision list keeps only the decisions still open and records the decided ones. Stale passages elsewhere in the file were corrected in the same change: epic #941 and #949 states, #781/#812/#583/#600/#601/#873/#878 closed, the sandbox default flip shipped in 0.12.0, and the E4 remaining-order line rewritten to what remains parked or deferred (#875, the #748 cgroup limits). Refs #808.
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.

3 participants