Repository navigation
fix(dev-fleet): harden every git read, and resolve the base branch per repository - #13348
Conversation
First Principles Review (Fable 5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS Two new functions ship generalized for callers that don't exist, and the declared-breaking rebase refusal rests on one unverified transport claim. Not justified as shipped
What this change shipsInventory (10 items) — 6 justifiedIntent: FIX — five defects in Dev Fleet's git reads (config-named exec, read-that-writes, unknown status as success, token in URL derivations, hardcoded
[FIRST-PRINCIPLES-REVIEWED] 1b56d95 Description read[DESCRIPTION-READ] 21f11d16de4cd4618df1ff466133c08a23175e0db4002e8481298bfce1b96607 That sha256 names the PR description this verdict read. Recompute it with |
Design Review (Fable 5) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS Guessed-tier remotes seed the shared Watch
[DESIGN-REVIEWED] 1b56d95 Description read[DESCRIPTION-READ] 4fa23ed7c8e998e61b793624b8f8a850db2825325bd5987c82592c328f83fb16 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 |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 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 Review — ✅ no blocking findingsReviewed Review detailsNo blocker; three added prose statements in the base-branch resolver contradict the code beside them. FINDING — src/kiro_crew/apps/builtins/dev_fleet/repository.py:578 — FINDING — src/kiro_crew/apps/builtins/dev_fleet/repository.py:751 — the second pass's comment (and the spec sentence "only a match earns the positive (paired with that remote)") claims a comparison the code never makes: FINDING — src/kiro_crew/apps/builtins/dev_fleet/repository.py:785 — tier 2 returns its remote with the comment "the remote is carried for shape only … the remote is never acted on here", but [OPUS-REVIEWED] 1b56d95 Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
a4a169b to
6988563
Compare
|
Both blocking findings on the previous head are FIXED, not deferred. Verified against the code before acting, and each fix is mutation-verified by a new pin. F1 -- read-only adoption retained write paths. Confirmed on both halves. The index-write half: The gateway half: F2 -- first remote could select the wrong rebase base. Confirmed. Exactly one remote is now consulted: Also on this head: the six inclusive-language violations are down to one line that needs the literal branch name, carrying the sanctioned same-line marker; The branch is rebased onto |
6988563 to
a12c42b
Compare
|
Head F2 (upheld) -- read-only denials bypass SEL auditing. Correct, and correct on its own terms: F1 (flagged) -- sensitive repositories bypass the path-access gate. Fixed rather than argued, even though the adjudication flagged the reachability: the conjunction it names (a path that is both a real git checkout and a gate-sensitive leaf, named in write-protected config) is not something the code should depend on remaining empty. The 28 shard failures were mine, and the fix is a different spelling of the same guarantee.
One unrelated red on the previous head is worth recording rather than acting on: |
a12c42b to
0d9fec8
Compare
|
Head Event-loop block (GPT F3 upheld, Opus BLOCKING 1). Correct and mine. I read the Protected linked worktree bypasses the gate (GPT F2, fenced-upheld). Correct, and the ordering is as described: Repo-local executable git filters (GPT F1, fenced-upheld). Correct: Make Live's 409 bypasses SEL (GPT F4, fenced-upheld). Correct: last round I audited the backend middleware's denial and not the gateway's, and the gateway's returns before the route reaches The read-only latch killed the reopen-on-changed-config self-heal (Opus BLOCKING 2). Correct, and the sharpest of the six. A read-only adoption sets A resolver stall latched as "protected location" (Opus FINDING). Correct.
Also this round: rebased onto |
0d9fec8 to
76834a5
Compare
e045df6 to
db63cae
Compare
db63cae to
7b1aba5
Compare
7b1aba5 to
a702d94
Compare
69633a2 to
4e358d3
Compare
|
/ai-review override gpt acf2e04: F1: Sync's gate (worktree_ops.py:1741) refuses unless the checkout's HEAD equals BASE_BRANCH, and tier-3 sets BASE_BRANCH to that checked-out branch, so the guessed base can only --ff-only (worktree_ops.py:1884) the branch already checked out -- nothing is rewritten or lost. The _BASE_BRANCH_POSITIVE gate buys nothing over that equality gate and disables Pull+Build on every checkout with no published remote HEAD, so per this PR's option-C ruling it adds a guard without removing a hazard. |
Human judgment recorded@chenmingwei23 marked the gpt AI finding as false positive, not applicable, or explicitly accepted for
This decision applies only to this commit. A new push requires a new judgment. |
…r repository Four fixes that each stand on their own. The foreign read-only checkout mode this branch previously carried is GONE: its hazard class was the clearance's vetted bytes never binding to what git actually parses, and three review rounds found that same invariant at a new site each time. Removing the mode removes the class. The parts below never depended on it. 1) Signature verification could exec a program the repository names. `.git/config` is agent-writable, which is the premise `core.fsmonitor` and `core.hooksPath` are already pinned on. `[log] showSignature=true` makes every `git log` verify what it prints, and verification EXECS `gpg.program`. All four spellings are pinned, because `gpg.<format>.program` selects per format and `gpg.openpgp.program` is a synonym that OVERRIDES the bare key -- pinning one leaves the other as an unpinned way to name the same exec. The trigger is pinned beside the programs: `true` is a value, and this is a place not to depend on one. 2) A read wrote to the repository. `git status` refreshes the index's stat cache and saves it back under `index.lock`, so a command that is a read to its caller is a write to the repository. Every fleet render runs one per row, so the fleet contended with the operator's own git for the lock on the ordinary path. `GIT_OPTIONAL_LOCKS=0` on the env chokepoint rather than `--no-optional-locks` per call site, so the argv keeps naming just its subcommand and a read added later inherits it. 3) An unknown exit status was reported as success. `proc.returncode or 0` mapped None to 0, and 0 is what every caller here reads as "that worked": a row would report a clean tree, and a mutation's caller would go on to the next step, on the strength of an exit status nobody ever saw. None is reachable after `communicate` returns on a child the loop has not reaped yet. 4) A remote URL's query rode into an href and into child argv. PRE-EXISTING on main, with three derivation sites. `git remote set-url` accepts a query and smart-HTTP honours it, so an operator's own remote can hold `?access_token=...` -- a PAT in the URL is a common way to make unattended https pushes work. Every pattern here anchors on `$`, so a retained query keeps `.git` from stripping AND rides into the result. Measured on main: `https://h/o/r.git?access_token=X` produced the href `https://h/o/r.git?access_token=X` and the `gh --repo` value `o/r.git?access_token=X`. `runtime.remote_url_locator` is the one home of the rule, in the module both importers share, because `fleet_state` imports `repository` and the reverse is a cycle -- a rule that cannot be shared gets copied, which is how three sites each ended up with their own suffix pattern. 5) The base branch was the literal `main`. Resolved per repository instead: `origin`'s published HEAD, else a conventional candidate that exists, else the checked-out branch. Only `origin` is consulted -- `git remote` lists alphabetically, so listing order lets a fork outvote it, and `_upstream_remote` falls back to `origin`, so the pair could disagree and a rebase would target a base the upstream never published. Ordered before `_upstream_remote`, which reads `branch.<base>.remote` and so cannot run first. The tiers are not equal, and the difference is recorded rather than re-derived per consumer: the first two are the repository STATING its default, the last is a guess. A wrong base costs a caption on a read and a worktree's commits on a rebase, which returns ok with no rollback once the replay is clean -- so rebase refuses on a guess, before the fetch, and the refusal clears itself on the next resolution. Every tier's answer passes an argv guard: a leading `-` reads as an option, and `..` is the range separator every consumer interpolates around. Tests: 12 mutations, 12 caught, each asserting it matched exactly one site and each run required to report an explicit pass/fail count, behind a positive control that refuses to score anything unless the selectors are green on the unmutated tree (~/oss/.kc-13348-mutations.py). Two count assertions that had been retyped now derive from the pinned set, so adding a pin cannot fail them for a reason that is not a defect. Four rebase tests and one redaction test now state the base branch, because the new gate sits before their fetch -- one of them had been passing on a global leaked from another test, which this also fixes.
bolichen97
left a comment
There was a problem hiding this comment.
Reviewed on behalf of the maintainers (sweep 2026-09-30): readiness passed, required checks green on 1b56d95, no blocking review threads. 493 behind main but merge-tree is clean and the PR's 5 test files pass on the merged tree (838 passed). The gpg-program / showSignature pin, optional-locks, returncode and URL-token strip are bypass/leak fixes; the rebase refusal on an unadvertised default branch is a correctness guard against an irreversible wrong-base rewrite, not a new security gate. Approving and merging.
Problem / Motivation
Goal: Dev Fleet's git reads stop executing programs the repository names, stop writing to the repository, stop reporting an unknown exit status as success, stop leaking a token from a remote URL, and target the repository's own default branch instead of the literal
main.Five defects, each reachable on the ordinary path against the operator's own checkout:
.git/configis agent-writable — the same premisecore.fsmonitorandcore.hooksPathare already pinned on.[log] showSignature=truemakes everygit logverify what it prints, and verification execsgpg.program. Nothing pinned it.git statusrefreshes the index's stat cache and saves it back underindex.lock, so a command that is a read to its caller is a write to the repository. Every fleet render runs one per row.proc.returncode or 0mapsNoneto0, and0is what every caller here reads as "that worked".git remote set-urlaccepts a query and smart-HTTP honours it, so an operator's own remote can hold?access_token=…— a PAT in the URL is a common way to make unattended https pushes work. Three derivation sites each anchored their pattern on$.main. A repository whose default ismasterortrunkgot the wrong row caption, the wrong ahead/behind reading, and the wrong rebase target.Why it matters
The first four are silent. A
git logthat execs an attacker-named program, a fleet render that takes the index lock out from under the operator's own git, a failed command reported as success, and a personal access token rendered into an issue link and passed as agh --repoargument all look like nothing happening.The token one is the sharpest, because the value is measured rather than argued. On
main,https://h/o/r.git?access_token=Xproduces the hrefhttps://h/o/r.git?access_token=Xand thegh --repovalueo/r.git?access_token=X. That link is rendered in the dashboard.The base branch one is loud and costly. On a repository whose default is not
main, Rebase targetedorigin/main: it either fails the fetch, or — worse — finds a same-named stranger branch and rewrites the worktree's commits onto it, returningokwith no rollback path once the replay is clean.Not a goal
_build_pendingreturned unknown only insideexcept RepoReadOnly, so without the mode the state is unreachable.http_apilines 198 and 227, andworktree_ops._auto_prune_reaper). They are onmainand are not this change's; pulling them in would widen the diff past what it is about.is_owner_repo_shape. Once the foreign mode is gone the only remote that reachesgh --repois the operator's own, so an argv-shape guard there is hardening this PR does not need.What changed (motivation → approach → change)
Symptom → root cause → change, one chain each.
Signature exec. The vector is a config key naming a program, which is the class
_GIT_ENV_NEUTRALIZERSalready exists to pin. All four spellings are pinned, becausegpg.<format>.programselects per format andgpg.openpgp.programis a synonym that overrides the bare key — pinning one leaves the other as an unpinned way to name the same exec. The triggerlog.showSignatureis pinned beside them:trueis a value, and this is a place not to depend on one. Pinned as env rather than a per-call-site flag, so alogread added later inherits it — and an earlier attempt at the flag form broke 28 shard tests whose stubs match the argv they expect.Read that writes.
GIT_OPTIONAL_LOCKS=0on the same chokepoint. The porcelain answer is identical and a real mutation still takes the locks it requires.Unknown status.
proc.returncode if proc.returncode is not None else -1.Noneis reachable aftercommunicatereturns on a child the loop has not reaped yet, so this is not a theoretical branch.URL query. Cut the query before any pattern anchored on
$— a retained?…sits between a trailing.gitand the end of the string, so the suffix the pattern means to strip survives and the token rides into the result.runtime.remote_url_locatoris the one home of the rule, in the module both importers share, becausefleet_stateimportsrepositoryand the reverse would be a cycle. A rule that cannot be shared gets copied, which is exactly how three sites each ended up with their own pattern; all three now call the one rule.Base branch. Resolved per repository:
origin's publishedHEAD, else a conventional candidate that exists, else the checked-out branch. Onlyoriginis consulted —git remotelists alphabetically, so listing order lets a fork outvote it, and_upstream_remotefalls back toorigin, so the pair could disagree and a rebase would target a base the upstream never published. Ordered before_upstream_remote, which readsbranch.<base>.remoteand so cannot run first.The tiers are not equal, and the difference is recorded once rather than re-derived per consumer. The first two are the repository stating its default; the last is a guess, and its trigger is ordinary — a dev box's checkout sits on a feature branch. Being wrong costs a caption on a read and a worktree's commits on a rebase, so Rebase refuses on a guess before the fetch, and the refusal clears itself on the next resolution. Every tier's answer passes an argv guard: a leading
-reads as an option, and..is the range separator every consumer interpolates around.Backwards compatibility
Breaking, in one narrow and deliberate way:
/apps/dev-fleet/api/rebasenow REFUSES on a repository that states no default branch, where before it proceeded againstorigin/main. Writer sweep onorigin/main@a83d2258a27a937bc740fcebd1fee894a2dbf250— the gate lives inworktree_ops._rebase_locked, whose only callers areworktree_ops._rebase(the route) and the tests updated here; there is no other entry point, and no caller inspects the error string. The refused case is the one that previously either failed the fetch or rewrote commits onto a stranger's branch, so nothing that worked before stops working.Otherwise compatible. The neutralizer set grew from 4 to 9 config pairs; the only reader of that count is
_load_trusted_credential_helpers, which already derives its own starting index from it rather than from a literal.Tests
~/oss/.kc-13348-mutations.py, not committed). Each substitution asserts it matched exactly one site; each run is refused unless its output carries an explicit pass/fail count; a positive control refuses to score anything unless every selector is green on the unmutated tree. Mutations: remove the optional-locks pin, flipshowSignatureback on, rename thegpg.openpgpsynonym so it goes unpinned, understateGIT_CONFIG_COUNT, restoreor 0, neuter the locator, skip it at each of the two derivation sites, drop the argv guard from the last base tier, let listing order pick the remote, report a guessed base as stated, remove the rebase gate.test_a_config_that_is_not_a_regular_file...and friends from earlier rounds are gone with the mode. New coverage locks in: the argv guard over ten branch names, each base tier and its probe order, stated-vs-guessed, the rebase gate refusing before the fetch, an unresolved checkout spawning no git at all, the locator over six URL shapes, no derivation carrying a query, and an unreaped child scoring-1.black(viascripts/check_black_formatting.py, real scope),isort,flake8,mypyall exit 0.Manual verification
N/A — unit coverage sufficient. Every change is in git argv/env construction, exit-status mapping, or string derivation, and each is pinned by a test plus a mutation that reddens it. The two
test_trusted_bin_*failures seen locally are environmental (aghshim on the dev box'sPATH) and fail identically on pristinemain.Related Issues
Filed separately from this diff: #14818 (the
SAST (Semgrep)lane measures 9–14 minutes against atimeout-minutes: 15cap and cancelled twice at 15m03s / 15m04s while this PR was in review — trunk health, not this change).Pattern harvest
Rule candidate:
semgrepPattern: a suffix/identity regex anchored on
$applied to a URL that may carry?/#, so the query both defeats the anchored strip and rides into the derived value.Secondary pattern, no rule proposed: the same rule copied to three call sites because the module that needed it could not import the module that owned it. The fix was to move the rule to the module both already import, rather than to keep the copies in sync.