Skip to content

fix(container-gateway-hook): count the real cwd and home as writable, whatever the environment says - #1789

Merged
potiuk merged 1 commit into
apache:mainfrom
potiuk:fix/gateway-hook-trust-roots
Oct 24, 2026
Merged

potiuk merged 1 commit into
apache:mainfrom
potiuk:fix/gateway-hook-trust-roots

Conversation

@potiuk

@potiuk potiuk commented Oct 24, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to #1784. The container-gateway session hook runs outside the sandbox, so what it counts as sandbox-writable decides whether a sandboxed command can plant code that later runs unsandboxed. Two inputs to that decision came from the session environment, which project settings can set:

  • The project root came from git, under an inherited environment. GIT_DIR / GIT_WORK_TREE (or a core.worktree in the writable .git/config) made git rev-parse --show-toplevel report another directory, so the real project was not counted as writable and its settings grants were not read; a gateway source planted there was accepted. The hook now drops every inherited GIT_* variable, always counts the physical session cwd as writable and reads its settings, and refuses to start when the reported toplevel does not contain the cwd.
  • Every trusted path was built from $HOME. With HOME pointed elsewhere, the real ~/.cache, ~/.local and user settings dropped out of the writable set. The hook now also counts the account database's home (~user, not $HOME): its .cache, its .local and its user settings. Each home's uv-interpreter exemption relaxes only that home's .local, so a $HOME nested inside the account's ~/.local exempts nothing there.
  • Documents the remaining, inherent gap: grants given only on the command line (--add-dir, a --settings file) are invisible to a hook; they come from whoever launches the session, not from the repository.

Type of change

  • Cross-cutting (sandbox / agent isolation)

Test plan

  • prek run on the changed files passes (isolated-setup fingerprint regenerated)
  • pytest tools/agent-isolation/tests/test_container_gateway_hook.py (outside /tmp/claude*, where the suite does not skip): 67 passed
  • Four new regression tests — inherited GIT_WORK_TREE, planted core.worktree, redirected HOME, HOME nested in the account's ~/.local — each fails on the hook it guards against and passes now
  • Two rounds of roborev review; the last clean

RFC-AI-0004 compliance

  • Sandbox — closes two ways for a sandboxed command to get code run outside the sandbox

Gen-AI disclosure: drafted with Claude Code (Opus 5); reviewed by the submitter.

🤖 Generated with Claude Code

… whatever the environment says

The hook runs outside the sandbox and refuses any interpreter or gateway
source under a sandbox-writable root, but two inputs to that set came
from the session environment: git's toplevel (GIT_DIR, GIT_WORK_TREE,
core.worktree) and $HOME. Drop inherited GIT_* variables, always count
the physical cwd and refuse a toplevel that does not contain it, and
count the account database's home (its .cache, .local and user
settings) alongside $HOME, each uv exemption relaxing only its own
home's .local. Document that CLI-only grants are invisible to a hook.

Generated-by: Claude Opus 5
@potiuk
potiuk enabled auto-merge (squash) October 24, 2026 21:58
@github-actions github-actions Bot added family:setup setup-* skills family:tools tools/* capability:platform Framework / agent substrate skills (install, verify, doctor, override, status, setup bootstrap) substrate:sandbox Tool substrate: agent isolation, egress control, settings audit labels Oct 24, 2026
@potiuk
potiuk merged commit 89a8a96 into apache:main Oct 24, 2026
12 checks passed
potiuk added a commit to potiuk/magpie that referenced this pull request Oct 24, 2026
…home

Rebased onto apache#1789, which treats $HOME as settable by the environment and
reads the account database's home. The worktree records now live under that
home too: a redirected $HOME would otherwise hand the hook a fresh, empty
record store. MAGPIE_CONTAINER_GATEWAY_STATE_DIR replaces the location for
tests, under the same writability checks, so the suite never writes into the
real account home. Also regenerates the secure-setup fingerprint.

Generated-by: Claude (Opus 5.5)
potiuk added a commit to potiuk/magpie that referenced this pull request Oct 24, 2026
…home

Rebased onto apache#1789, which treats $HOME as settable by the environment and
reads the account database's home. The worktree records now live under that
home too: a redirected $HOME would otherwise hand the hook a fresh, empty
record store. MAGPIE_CONTAINER_GATEWAY_STATE_DIR replaces the location for
tests, under the same writability checks, so the suite never writes into the
real account home. Also regenerates the secure-setup fingerprint.

Generated-by: Claude (Opus 5.5)
potiuk added a commit that referenced this pull request Oct 25, 2026
Ships the fixes merged since 0.9.0.dev202610241347 to marketplace installs:
the container-gateway hook hardening (#1784, #1789, #1790, #1793, #1804),
host-only uv state (#1785), session-start cleanup of the stale uv grant
(#1788), the trusted session-start interpreter (#1791), the sandboxed prek
home (#1792) and per-machine gateway hook registration (#1797).

Generated-by: Claude (Opus 5.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

capability:platform Framework / agent substrate skills (install, verify, doctor, override, status, setup bootstrap) family:setup setup-* skills family:tools tools/* substrate:sandbox Tool substrate: agent isolation, egress control, settings audit

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant