Repository navigation
fix(git): keep agent-writable global git config out of host-side git - #24824
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level blocker: every Notes
[DESIGN-REVIEWED] e4b4a5d Description read[DESCRIPTION-READ] 5b9fb3141788cb8437313a96eb2b8aacf3973f20bd96bbf738abb7a412b5eff4 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The home-config isolation is backed by a new test that fails on base, and each rider follows from it. Two premises are inherited. Notes
What this change shipsInventory (8 items) — 6 justifiedIntent: stop a sandboxed agent from making the gateway's host-side git run a program it planted in the user's global or system git config or attributes files. FIX.
[FIRST-PRINCIPLES-REVIEWED] e4b4a5d Description read[DESCRIPTION-READ] 9d2b83274d7c0daaaf51c789fe094e680808c097b1ea5461ff773cb4d692ee1c That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
d970e18 to
9162627
Compare
9162627 to
695ff2e
Compare
695ff2e to
6304dfe
Compare
6304dfe to
1c06811
Compare
A sandboxed agent can write ~/.gitconfig, the XDG git config and attributes files, and a user-writable system gitconfig. Host-side git read them for every repository, and a repo-named driver there (filter.<x>.smudge plus a global attributes line) ran a program on the update's reset --hard. git_command_env now points GIT_CONFIG_GLOBAL at the null device, drops the system files on POSIX (GIT_CONFIG_NOSYSTEM, GIT_ATTR_NOSYSTEM), pins core.attributesFile, and forwards only the system/global safe.directory values. resolve_remote_url now takes the env the update fetch runs with, and each caller passes one variable to both the source-pin check and the fetch, so the pin judges the URL that fetch will connect to.
1c06811 to
e4b4a5d
Compare
buluoray
left a comment
There was a problem hiding this comment.
Approving e4b4a5d.
I ran the new module and every update-path suite it touches against real git 2.50.1 (426 passed), and mutated the attributes pin, GIT_CONFIG_GLOBAL, GIT_CONFIG_NOSYSTEM, the --includes read and the fetch_env plumbing one at a time; each turns named tests red. The env is built from a copy, so the user's own git outside the gateway is untouched, credential.helper/core.sshCommand were already pinned off on the gateway path so no new auth loss there, and safe.directory survives in git's order. The per-path source pin (one variable for the check and the fetch) is the right shape. Windows was checked against source only: GIT_CONFIG_GLOBAL=os.devnull matches what code_fingerprint.py and the registry pipeline already do there, and keeping the system file is a reasonable call.
Non-blocking follow-ups:
- Coordination with #24822: that PR introduces
git_command_env(human_transport=True)so a human-started update keeps the operator's credential helper andcore.sshCommand. With this isolation applied unconditionally, those settings are never read from~/.gitconfigor the system file (Apple git'sosxkeychainlives in the system file), sohuman_transportbecomes inert and a private-remotekirocrew update/ dashboard update would fail. Whichever PR lands second should decide whetherhuman_transportalso keeps those two keys (e.g. by reading them the waysafe.directoryis read and forwarding them as command-line config) and should switch the CLI/dashboardfetch_envfromNoneto the env their fetch then actually runs with. - Until #24822 lands, the CLI
reset --hardand the dashboardmergestill run with the inherited env, so the goal sentence holds only forgit_command_envcallers. The PR says so; worth keeping in mind for the merge order. - Test redundancy: every filter-driver exploit test plants a global attributes file, so removing
GIT_CONFIG_GLOBALleaves them all green (thecore.attributesFilepin alone defeats them). A case that arms a globalfilter.<x>.smudgefrom repository attributes (.git/info/attributes) would pinGIT_CONFIG_GLOBAL's exec-blocking role independently. Same fortest_inherited_system_configandGIT_CONFIG_NOSYSTEM. - Backwards compatibility could also list the operator's own
url.<x>.insteadOfamong the settings the gateway auto-update no longer sees (the governance spec covers it, the PR body list does not).
Problem / Motivation
Goal: A sandboxed agent cannot make the gateway's own git run a program by editing the user's global or system git config or attributes files.
A sandboxed agent runs as the gateway's user. The sandbox does not mask
~/.gitconfig,$XDG_CONFIG_HOME/git/config,~/.config/git/attributes, or a Homebrew$(prefix)/etc/gitconfig. The file-tool write gate does not refuse them either. Host-side git reads those files for every repository.The fixed-key pins in
git_neutralizer_envalready beat a plantedcore.fsmonitororcore.sshCommand. They cannot reach a repo-NAMED driver. Measured on main with git 2.47:[filter "evil"] smudge = <script>in~/.gitconfigplus* filter=evilin~/.config/git/attributesruns the script on the update path'sgit reset --hard, withgit_command_env()in force.repo_exec_config_reasondoes not catch it, because it only probes the repository's own scopes.url.<x>.insteadOf,include.path,http.proxy/http.sslCAInfoand the multi-valuedcore.gitProxyin global config reach the fetch the same way.Why it matters
Every user who runs the gateway's git update path is exposed. A prompt-injected agent writes two files in its own home, and the gateway runs the agent's program as the user, outside the sandbox. Sibling PRs close the repository-local half: #24808 (update check) and #24812 (sandbox seals on
.git). This PR closes the global/system half for every caller ofgit_command_env.Not a goal
dashboard/handlers/updates_check.py. fix(updates): neutralize repo-local git exec config in the update check #24808 owns it.git_command_env. The host-git sweep PR does that.~/.gitconfigand~/.config/git/*(see the trade-off below).What changed (motivation → approach → change)
Root cause:
git_command_env()built a clean env for host git but still let git read the user's global and system files. Those files sit where the agent can write.Change, in
platform/update_governance.py, plus one call site inslack/gateway_runtime/update_apply.py. A new_git_home_config_isolation_env(env)is folded intogit_command_env():GIT_CONFIG_GLOBAL=<null device>. This replaces both~/.gitconfigand the XDG config file, so the whole global include chain is gone. It also overrides an inheritedGIT_CONFIG_GLOBAL.GIT_CONFIG_NOSYSTEM=1drops the system config, which a Homebrew install leaves user-writable.core.attributesFile=<null device>, appended after the existingGIT_CONFIG_*pins so no index moves. Git's default attributes path ($XDG_CONFIG_HOME/git/attributes) does not come from config, so dropping global config alone does not drop it. Without the pin, a global attributes line can still arm a driver the repository defines.GIT_ATTR_NOSYSTEM=1drops the system attributes file.safe.directoryis the one key carried over. Git honours it only from system, global and command-line config, so dropping those files would make every update git call fail with "dubious ownership" on a checkout owned by another user (for example, a container running as root over a bind-mounted clone)._protected_safe_directories()reads the values withgit config --system/--global --includes -z --get-all safe.directory(followinginclude.path, as git does) and appends them as command-line config, in git's order. The read runs nothing, and the value is a path, not a program. An agent that plantssafe.directory=*gains nothing it did not have before this PR. A failed read forwards nothing, so git refuses the checkout.The
safe.directoryread is reused for 60 s per set of variables that move those files (HOME,XDG_CONFIG_HOME,GIT_CONFIG_GLOBAL, ...). Everygit_command_env()call lands there, and some run on the gateway's event loop.Source pin: each path judges the URL its own fetch connects to.
resolve_remote_url(proj, fetch_env=...)now takes the environment the update fetch runs with (a required keyword), and resolves the branch, its tracked remote andls-remote --get-urlunder exactly that env. Each caller keeps ONE variable and passes it to both the pin check and the fetch, so they cannot drift. The gateway auto-update (slack/gateway_runtime/update_apply.py) and the route check that decides it (platform/update_capability.py) passgit_command_env(), so an agent-planted globalurl.<x>.insteadOfcan neither redirect that fetch nor dress up an unapproved origin for its pin.kirocrew update(cli_server_update.py) and the dashboard update (dashboard/handlers/updates_apply.py) passNone: their fetch inherits the process env (now passed asenv=from the same variable) and applies the operator's own rewrite, and the pin judges that rewritten URL, as before. A URL a fetch will not use is never judged.update_blocked_reasonis unchanged.docs/system-specs/modules/governance.mddescribes the per-path rule.slack/gateway_runtime/update_apply.py:_auto_apply_updatebuilds_git_envinsubprocess_executor()rather than inline, becausegit_command_env()may now run the shortsafe.directoryread and that function runs on the gateway's event loop. The function's other git work already runs there the same way.Per OS: on Linux and macOS the system files are dropped too (
GIT_CONFIG_NOSYSTEM,GIT_ATTR_NOSYSTEM). On Windows they are kept. Git for Windows stores what it needs there (http.sslBackend/http.sslCAInfo,core.autocrlf,core.longpaths) underProgram Files, which a standard install leaves admin-only. Global config is dropped on every OS.git_neutralizer_env()itself is unchanged.Trade-off: host-side isolation (this PR) vs a sandbox seal.
~/.gitconfig,~/.config/git/attributes) would have to be created in the user's home. A seal covers a NAME, so a dotfile manager's symlinked~/.gitconfigtarget, and everyinclude.pathtarget, stay writable through their other names. An inheritedGIT_CONFIG_GLOBALcan point anywhere. The sandbox also leaves the rest of$HOMEwritable,~/.bashrcincluded. Sealing two git files would not make home a write boundary, and it would widen the overlap with fix(sandbox): write-protect git control files in the gateway's checkout #24812's launcher and planner changes.git_command_env. The sweep PR moves the remaining host callers onto it.Conflict note: #24808 adds lines in the same function, right after
env.update(git_neutralizer_env()). This PR adds one line there too. Whichever lands second gets a trivial textual conflict; both changes should be kept.Adversarial review (a fresh subagent that saw only the diff, ran real git 2.47): the change holds against global, XDG, include, symlink, inherited-env, system and attributes plants. It also holds against a repo-local
core.attributesFile, because the command-scope pin outranks it. Residuals it named, none added by this PR:GIT_CONFIG_GLOBAL, and older than 2.31 ignoresGIT_CONFIG_COUNT. Every existing pin ingit_neutralizer_envalready relies on 2.31+. No minimum git version is enforced today; a version gate would be a separate change.GIT_CONFIG_PARAMETERSoutranks the pins. It comes from the gateway's own environment, which the agent cannot set. The same was true before this PR.GIT_TEMPLATE_DIRmatters only forinit/clone. Nogit_command_envcaller runs either.~/.ssh/config(read by ssh, not git) and an agent-writablePATHentry are outside git config. fix(updates): neutralize repo-local git exec config in the update check #24808 pinsPATH.Backwards compatibility
Compatible: every caller of
git_command_envon main runs fetch,ls-remote,rev-parse,status,diff,config --get,merge --ff-onlyandreset --hard. None of those needs a commit identity.The diff takes away the user's global and system git settings for these calls:
Reader: src/kiro_crew/platform/update_governance.py:_git_probe -- release -- probes read repository scopes only; test_governance_updates.py passes
Reader: src/kiro_crew/slack/gateway_runtime/update_apply.py:_git_env -- release -- fetch/status/reset need no global key;
statusalready ignores untracked lines; test_slack_gateway_update_apply.py passesReader: src/kiro_crew/slack/gateway.py:git_command_env -- release -- same update-path commands; test_gateway_restart_uses_respawn_executable.py passes
Settings a user keeps in global config that these calls no longer see:
http.proxy/http.sslCAInfo: a proxy still works throughhttps_proxy, which git reads from the environment. A CA bundle set only in gitconfig no longer applies. That is intended, because an agent could plant one.safe.directoryis kept (see above).core.excludesFile: the default~/.config/git/ignoreis still read. The gateway's dirty check already skips untracked lines.user.name/user.email: no caller commits. A future caller that commits must pass identity explicitly (the tests show how).Tests
test/test_git_command_env_home_config.py. Every exploit test first proves the plant FIRES under a plain env, then proves it does not fire undergit_command_env():core.fsmonitorongit status.core.sshCommandonls-remote ssh://….filter.<x>.smudgeplus global attributes, onreset --hard. This is the gap on main.$XDG_CONFIG_HOME/git/configplus attributes, with no~/.gitconfig.~/.gitconfigwhoseinclude.pathnames a planted file.~/.gitconfig.GIT_CONFIG_GLOBALnaming a planted file.GIT_CONFIG_SYSTEMnaming a planted file (the user-writable system file).core.attributesFilepin on its own.os.environleft untouched, and a commit with explicit identity still working.safe.directory: global values are forwarded in order, including one behindinclude.path(fails without--includes). A checkout git sees as another user's (via git'sGIT_TEST_ASSUME_DIFFERENT_OWNERknob) fails without the value and opens with it. Forwarding that key does not reopen a filter driver planted in the same file.safe.directoryread is reused inside its window.git@good.example:*) passes on the CLI and dashboard path; a rewrite onto an unpinned host is refused on the CLI and dashboard path; the same agent-planted rewrite cannot redirect the gateway's isolated fetch; a planted reverse rewrite cannot dress up an evil origin for the gateway; a homebranch.<name>.remoteis judged on the dashboard path. Four of these fail iffetch_envis ignored.GIT_CONFIG_NOSYSTEM/GIT_ATTR_NOSYSTEM; Windows does not (fails if the arm is removed). Both drop global config.test/spawn_audit_helpers.pyallowlists the new read-onlygit configspawn,_read_protected_safe_directories, with its reason.test_governance_updates.py,test_dashboard_updates_coverage_apply.py,test_gateway_restart_uses_respawn_executable.py,test_cli_server_more_coverage.py: calls and stand-ins take the newfetch_envkeyword.Proof: PROVEN test/test_git_command_env_home_config.py::TestPlantedGlobalConfigDoesNotRun::test_global_filter_driver_with_global_attributes, test_xdg_config_and_attributes, test_include_path_chain, test_inherited_git_config_global, test_inherited_system_config (head e4b4a5d)
The fsmonitor, sshCommand and symlink tests still pass with the fix reverted, because the existing fixed-key pins already cover them. They stay as regression markers.
Also run:
test_governance_updates.py,test_file_line_cap.py,test_ratchet_scope.py,test_slack_gateway_update_apply.py,test_update_check_install_aware_auto_apply.py,test_gateway_restart_uses_respawn_executable.py. Every test file that references the update path, plustest_spawn_audit.pyandtest_git_maintenance_ratchet.py, was run: 6261 passed, 26 skipped.Manual verification
N/A. The tests run real git against planted files in a fake
$HOME, which is the manual check.Inputs considered, and how each was handled:
~/.gitconfigGIT_CONFIG_GLOBAL~/.gitconfigGIT_CONFIG_GLOBAL$XDG_CONFIG_HOME/git/configGIT_CONFIG_GLOBALinclude.path/includeIfchain from globalGIT_CONFIG_GLOBALinclude.path)GIT_CONFIG_GLOBAL/etc/gitconfig, Homebrew prefixGIT_CONFIG_NOSYSTEMGIT_CONFIG_SYSTEM)~/.config/git/attributescore.attributesFilepingitattributesGIT_ATTR_NOSYSTEM~/.config/git/ignoreGIT_CONFIG_PARAMETERS/GIT_SSH_COMMANDin the gateway envBase-red, not from this PR:
test/test_crew_log_fullscan_guard.py::test_a_warm_session_read_that_earns_a_savepoint_reads_only_the_gapfails XPASS(strict) on the base commit without this diff. Its fix is open as #24774.Related Issues
Refs #24808, #24812
Sibling sweep
Swept: git grep -n "GIT_CONFIG_GLOBAL|git_command_env" -- src/
Sibling: src/kiro_crew/code_fingerprint.py -- not affected -- already sets GIT_CONFIG_GLOBAL to the null device and GIT_CONFIG_NOSYSTEM
Sibling: src/kiro_crew/apps/registry_pipeline/subprocess_env.py -- not affected -- already sets GIT_CONFIG_GLOBAL to the null device and GIT_CONFIG_NOSYSTEM
Sibling: src/kiro_crew/apps/builtins/auto_improvement/backend/clone_setup.py -- not affected -- its _git_env already isolates global and system config
Sibling: src/kiro_crew/apps/builtins/design_critique/backend/routes.py -- not affected -- already points GIT_CONFIG_GLOBAL at the null device for its clone
Sibling: src/kiro_crew/dashboard/handlers/updates_check.py -- tracked in #24808
Sibling: src/kiro_crew/cli_server_update.py -- tracked in the host-git sweep PR, which moves it onto git_command_env
Pattern harvest
Rule candidate: review-prompt
Pattern: host-side git env that pins config keys but still reads GIT_CONFIG_GLOBAL / system config from an agent-writable home
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.