Skip to content

fix(updates): neutralize repo-local git exec config in the update check - #24808

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/updates-check-git-neutralize
Oct 29, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/updates-check-git-neutralize

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The update check never runs a program that the checkout's own git config or attributes name.

_check_git_checkout runs at boot, every 12 hours, and on the dashboard's Check button. It runs git fetch, rev-parse, rev-list, show and diff on the host with cwd=KIROCREW_PROJECT_DIR and no guards. On a source-checkout install that directory is a tree agents can write. A repo-local core.sshCommand, core.fsmonitor, core.hooksPath, diff.external, remote.<name>.uploadpack, or a .gitattributes diff driver with diff.<drv>.textconv therefore runs on the host, outside the sandbox. Reproduced on main for each of these, plus the same keys reached through include.path.

Why it matters

Every source-checkout install runs this check by itself. A program planted in .git/config runs as the gateway user with no sandbox, with no click needed.

Not a goal

  • The manual POST /api/update endpoint's own git calls (updates_apply.py), and the unattended apply's git reset --hard step. The unattended apply's FETCH is in scope and is fixed here (it shares the new helper); the reset is a separate step with its own preflight and is not touched.
  • Any change to what the check reports for a clean checkout.

What changed (motivation → approach → change)

Root cause: the check spawned a bare git with the inherited environment, while the unattended apply already had guards in update_governance.

  • _check_git_checkout now uses those shared guards. It resolves git with trusted_git_bin(), runs every call with git_command_env(), and refuses before any git call when repo_exec_config_reason() names a reason. A refusal is a failed check (git_read_failed), with a log line saying why.
  • The changelog git diff adds --no-textconv --no-ext-diff, and git show adds --no-textconv, so no attribute can send them to a driver.
  • The agent can rewrite .git/config in the window between the one-time preflight read and the fetch. A review won that race ~17% of the time, including with a config-defined hook.<name>.command (git 2.54+) that no -c pin or fetch flag closes (even a FETCH_HEAD-only fetch opens a ref transaction). The close is a new shared helper, fetch_and_pin_upstream in update_governance, used by BOTH the check and the unattended apply fetch: it fetches against a throwaway git dir the gateway owns (GIT_DIR there, so git reads its hook-free config) while objects land in the checkout's store, and returns the fetched commit OID both callers use directly. One fix for one bug class in two callers; this closes the apply-path variant too. It stays correct for real checkouts: object store, common git dir and fetch "have"s come from git layout probes (worktrees/submodules too, not just proj/.git); haves mean only the delta transfers; it fetches refs/heads/<branch> and verifies a commit (a same-named upstream tag cannot stand in); cwd=proj resolves a relative or ~ local remote against the checkout; it copies a shallow clone's boundary, inherits the object format (SHA-256) and forwards http.*.extraHeader auth through GIT_CONFIG_* env (which git never re-splits at =); and the scratch dir sits under the sandbox-masked crew scratch root so a same-UID agent cannot race a hook in. No ref in the checkout is written; the tracking ref stays as the last git fetch left it.
  • Rebased on fix(git): apply repo-exec neutralization to remaining host-side git callers #24822, which already refuses repo-set pack programs and isolates global config; this PR adds the pieces below on top.
  • git_command_env() sets GIT_ALLOW_PROTOCOL=file:git:ssh:http:https (no repo-named helper transport), GIT_PROXY_COMMAND="", and GIT_NO_LAZY_FETCH=1 (a partial clone's on-demand fetch would bypass the isolated fetch). The isolated fetch alone pins PATH to the trusted system dirs, since its git is absolute and other callers spawn a bare git.
  • repo_exec_config_reason refuses a commondir redirect (a .git/commondir beside a plain .git directory, or a resolved common dir that is not that .git): a sandboxed agent can plant .git/commondir even under a bind seal, redirecting git's config and hooks. Closes the Linux commondir gap from fix(sandbox): write-protect git control files in the gateway's checkout #24812; a linked worktree (.git a file) is unaffected.
  • count_divergence takes optional git= and env=, so the check runs it the same way.

Backwards compatibility

Breaking: repo_exec_config_reason now refuses a checkout whose config sets any remote.<name>.uploadpack or .receivepack, and the update check now refuses on that function's reasons. It also refuses remote-helper (<helper>::) remotes. Writer sweep on origin/main @ f3a7d42: no code in the repo writes these keys into the install checkout. A user who set them by hand gets a failed check with a log line that names the key, and kirocrew update is unchanged.

Reader: src/kiro_crew/platform/update_capability.py:_git_route -- entry: release -- a refused repo already reports no unattended git route; test_update_capability.py passes
Reader: src/kiro_crew/slack/gateway_runtime/update_apply.py:_auto_apply_update -- entry: release -- refuses the unattended apply with the existing log line, and its fetch now goes through the shared helper, resetting to the OID the helper returns; test_slack_gateway_update_apply.py / test_slack_gateway_update_reset.py pass
Reader: src/kiro_crew/dashboard/handlers/updates_check.py:_check_git_checkout -- entry: crew page -- new caller, compares against the OID the helper returns; test_update_check_git_exec_neutralized.py
Reader: src/kiro_crew/git_divergence.py:count_divergence -- entry: crew page -- new kwargs default to the old behaviour; test_git_divergence.py passes

Tests

test/test_update_check_git_exec_neutralized.py drives the real check against real git repos with a marker program:

  • A clean clone one commit behind still reports the update, version, distance and changelog line.

  • These must not run: core.fsmonitor, diff.external, core.hooksPath and default hooks, core.sshCommand, a .gitattributes textconv driver, include.path and includeIf, remote.origin/tracked-remote uploadpack, fetch.all, and a git placed on PATH.

  • Race tests: the refusal answers "clean" and the vector is planted anyway, for uploadpack (origin, tracked, fetch.all), core.gitProxy, remote.<n>.vcs, pwn:: URLs and textconv. With the fetch flags removed, the first four ran.

  • Race tests, for BOTH callers: with the exec-config preflight answered "clean" (the race won every time), a vector planted anyway must still not run — hook.<name>.command and core.hooksPath hooks most of all, which no pin or flag closes, plus uploadpack, core.gitProxy, remote-helper and textconv vectors. The apply path has the same marker test driving _auto_apply_update.

test_dashboard_updates_coverage.py's stand-in-git timeout/cancel tests now drive the shared helper directly (the fetch lives there), proving a hung fetch and its transport helper are killed and reaped.

Proof: PROVEN test/test_dashboard_updates_coverage.py::TestGitFetchTimeoutReapsTheHelper::test_a_cancelled_fetch_ends_git_and_its_helper, test/test_spawn_audit.py::test_benign_allowlist_has_no_stale_entries, test/test_update_check_git_exec_neutralized.py::test_a_pinned_fixed_key_program_does_not_run[core.fsmonitor], test/test_update_check_git_exec_neutralized.py::test_a_pinned_fixed_key_program_does_not_run[diff.external], test/test_update_check_git_exec_neutralized.py::test_repo_hooks_do_not_run (head 51fdf7e)

Manual verification

Reproduced each vector on main (the marker ran), then ran the same script on this branch (no marker; a clean checkout still reports succeeded with the changelog line). An independent reviewer that saw only the diff tried 23 vectors; the only break it found was the preflight-vs-fetch race, which the shared isolated-fetch helper closes (verified: a planted hook/core.hooksPath reference-transaction hook runs on a normal fetch but not through the helper, whose own git dir names no hook).

Follow-up

  • Scope-filtered credential forwarding: a checkout whose HTTPS credentials come only from a global helper chosen by includeIf "gitdir:..." loses them on the isolated fetch (the include no longer matches). The check fails loudly (git_fetch_failed); kirocrew update still works. Fix later by forwarding only system/global-scope credential.* (via git config --show-scope), never local/worktree. GPT finding overridden for head 61304bb on this basis.

Related Issues

Reported privately by an external researcher; no public issue.

Sibling sweep

Swept: git grep -nE 'create_subprocess_exec|subprocess.run' for every git fetch in the update seam, and git grep for the first-value-wins remote.origin.uploadpack pin
Sibling: src/kiro_crew/slack/gateway_runtime/update_apply.py -- changed here -- its fetch now uses the shared fetch_and_pin_upstream, closing the same race
Sibling: src/kiro_crew/dashboard/handlers/updates_check.py -- changed here -- its fetch now uses the shared fetch_and_pin_upstream
Sibling: src/kiro_crew/apps/builtins/md_notebook/git_ops.py -- tracked in #24845 -- a different surface (notebook git ops) with the same first-value-wins remote.origin.uploadpack pin, out of this PR's update-seam goal
Sibling: src/kiro_crew/apps/builtins/papyrus/backend/gitops.py -- tracked in #24845 -- same, in the papyrus git ops

Pattern harvest

Rule candidate: semgrep
Pattern: asyncio.create_subprocess_exec("git", ...) or subprocess.run(["git", ...]) in update/gateway code without env=git_command_env() and a trusted_git_bin() binary.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 51fdf7ed24f77835a81afcf0a9066dc4ff265a66 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 51fdf7ed24f77835a81afcf0a9066dc4ff265a66 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: one shared isolated-fetch helper fixes the hook race for both callers, and the one refusal it adds (repo-set pack programs, helper remotes) is listed as breaking and accepted.

Notes

  • The three env additions in git_command_env() (GIT_NO_LAZY_FETCH, GIT_ALLOW_PROTOCOL, GIT_PROXY_COMMAND) reach every caller that doesn't pass human_transport, not just the update seam. That includes cloud/source.py's git archive/check-attr, frontend.py, file_api/editor.py and cli_server_update.py's _git_env reset. On a partial-clone checkout, those reads now fail instead of fetching missing objects on demand. No supported install uses a partial clone, and a revert undoes this cleanly, but the claim "kirocrew update is unchanged" only holds for full clones.
  • The comment in updates_check.py says the helper pins the tip "into its tracking ref". fetch_and_pin_upstream deliberately writes no ref, and its name says "pin" too. The next reader will expect refs/remotes/<r>/<b> to move after a check. Make the comment, and ideally the name, say that only an OID is returned.

[DESIGN-REVIEWED] 51fdf7e

Description read

[DESCRIPTION-READ] 656cdd415de15e96ea17a32a626bcfee04e0467aa8426a908aeddec133db39fd

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 51fdf7ed24f77835a81afcf0a9066dc4ff265a66 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. Every item closes a host-exec route the description reproduced. Two comments and the helper's name describe a tracking-ref pin that the helper itself says it deliberately does not do.

Notes

  • Item 4 — oversized (naming): the helper's docstring says refreshing the tracking ref "was tried … so it is deliberately not done". Two comments say the opposite: updates_check.py says "the tip is pinned into its tracking ref, so the reads below resolve against it", and update_apply.py says "The helper also pins that tracking ref to this OID … for parity". Subtraction: delete both sentences and drop _and_pin from fetch_and_pin_upstream.

What this change ships

Inventory (9 items) — 8 justified

Intent: stop the source-checkout update check from running a program named by the checkout's own git config or attributes. FIX.

  1. The update check fails with git_read_failed when repo config names an exec program or redirects commondir — justified
  2. The update check runs the trusted absolute git under git_command_env(), not a bare git from PATH — justified
  3. The changelog diff and version read ignore .gitattributes textconv and external diff drivers — justified
  4. Fetching happens in a gateway-owned scratch git dir and returns an OID — oversized (name and comments claim a ref pin it doesn't do)
  5. The unattended apply's fetch also goes through that isolated helper, and the reset targets the returned OID — justified
  6. The update check no longer refreshes refs/remotes/<remote>/<branch> — justified
  7. git_command_env now restricts transports to built-in protocols, empties the git proxy, and disables lazy fetch for every caller — justified
  8. A .git/commondir beside a plain .git directory is refused for both the check and the apply — justified
  9. count_divergence takes a git= binary argument — justified

[FIRST-PRINCIPLES-REVIEWED] 51fdf7e

Description read

[DESCRIPTION-READ] 75e221849c2b6a4c9fe2452d0255218d4fc059575c0e4a1848210a43165fe67a

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 51fdf7ed24f77835a81afcf0a9066dc4ff265a66 — this comment is updated in place on each push.

Review details

No findings.

Notes:

  • update_apply.py:255 and the updates_check.py fetch comment both say the helper pins the tracking ref, but fetch_and_pin_upstream's docstring says no ref in proj is written; the comments are stale.

[OPUS-REVIEWED] 51fdf7e

Verdict parsed from the review's SHA-scoped output markers for commit 51fdf7ed24f77835a81afcf0a9066dc4ff265a66.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 51fdf7ed24f77835a81afcf0a9066dc4ff265a66 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 51fdf7ed24f77835a81afcf0a9066dc4ff265a66 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 51fdf7e

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 51fdf7ed24f77835a81afcf0a9066dc4ff265a66 false-positive: <reason, 20 to 500 characters>

@iamwhatever
iamwhatever force-pushed the fix/updates-check-git-neutralize branch from 5ef256b to 34f3bbc Compare October 27, 2026 09:03
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 27, 2026
@iamwhatever
iamwhatever force-pushed the fix/updates-check-git-neutralize branch from 34f3bbc to 4ccc23b Compare October 27, 2026 10:07
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 27, 2026
@iamwhatever
iamwhatever force-pushed the fix/updates-check-git-neutralize branch from 4ccc23b to 9b44835 Compare October 27, 2026 10:32
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 27, 2026
@iamwhatever
iamwhatever force-pushed the fix/updates-check-git-neutralize branch from 9b44835 to 3699155 Compare October 27, 2026 10:57
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 27, 2026
@iamwhatever
iamwhatever force-pushed the fix/updates-check-git-neutralize branch from 3699155 to e722b7c Compare October 27, 2026 11:45
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 27, 2026
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 27, 2026
@iamwhatever
iamwhatever force-pushed the fix/updates-check-git-neutralize branch from b436b4c to 61304bb Compare October 27, 2026 12:48
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 27, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 27, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

/ai-review override gpt 61304bb false-positive: withheld credentials not exposed; fetch fails loudly (git_fetch_failed), only a checkout whose HTTPS auth comes solely from a conditional global include, recoverable via kirocrew update — the unbounded-harm fence misclassifies a niche visible regression

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@iamwhatever recorded a false-positive release (class false-positive) for the gpt AI finding on 61304bba316444365181b3b4dbb4daa922d7fb52.

withheld credentials not exposed; fetch fails loudly (git_fetch_failed), only a checkout whose HTTPS auth comes solely from a conditional global include, recoverable via kirocrew update — the unbounded-harm fence misclassifies a niche visible regression

This decision applies only to this commit. A new push requires a new judgment.

@iamwhatever
iamwhatever force-pushed the fix/updates-check-git-neutralize branch from 61304bb to 06caa8e Compare October 28, 2026 16:30
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 28, 2026
@iamwhatever
iamwhatever force-pushed the fix/updates-check-git-neutralize branch from 06caa8e to 3c47073 Compare October 28, 2026 17:05
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 28, 2026
@iamwhatever
iamwhatever force-pushed the fix/updates-check-git-neutralize branch from 3c47073 to 51fdf7e Compare October 28, 2026 17:43
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 28, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved on behalf of the watch holder (bolichen). Design and First Principles pass on this head (or skipped for docs only), UX skipped or pass, all checks green, no conflict, no open change request.

@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) October 29, 2026 00:46
@KiroCrewCaptain
KiroCrewCaptain merged commit 8966631 into main Oct 29, 2026
152 of 169 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/updates-check-git-neutralize branch October 29, 2026 00:47
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 29, 2026
@buluoray

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew Auto-Pipeline [operator: buluoray]: Review findings still true on main after this merged are tracked in 25508: the update check now drops the user's credential helper (updates_check.py:504 uses git_command_env() without human_transport), so helper-authenticated private HTTPS remotes fail every check; and update_governance.py is 1,766 lines.

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