Repository navigation
Description
Problem
block-noncanonical-commit's persisted-alias lookup runs git config --get alias.<name> without replaying the invocation's locating globals, so when --git-dir / --work-tree select the repository, the guard queries the wrong one, finds no alias, and allows a non-canonical commit that real git performs.
Present on origin/main and on the #1085 branch alike — this is a shared gap, not a regression. Filing separately from the design issue so it can be closed on its own if someone wants the narrow fix.
Reproduction (real-git ground truth, not exit codes alone)
setup:
<repo> git config alias.b 'commit --allow-empty -m bypass'
<non-repo> an ordinary empty directory
$ cd <non-repo>
$ git --git-dir=<repo>/.git --work-tree=<repo> -c alias.a=b a
Measured, branch vs origin/main's guard:
real want branch main
R8-2 persisted lookup drops globals commits 2 0 FAIL 0 FAIL
Real git resolves a → b → commit --allow-empty -m bypass in <repo> and the non-canonical commit lands. Both guards return 0.
git -h lists both options as invocation globals before <command>:
git [--git-dir=<path>] [--work-tree=<path>] ... <command>.
Why it survived the identity fix
The #1085 branch taught the identity probe to replay the locating globals (git -C <dir> --git-dir=X --work-tree=Y rev-parse --show-toplevel), which fixed a separate false positive. The persisted-alias lookup was not given the same treatment, so:
rev-parse --show-toplevel→ replays the globals ✔config --get alias.<name>→ does not ✘
That asymmetry is the bug. It also suggests the per-call-site approach is the wrong shape: any future probe that answers a repository question inherits the same requirement.
Fix direction
Replay the locating globals in the config --get query and include them in its cache key — the lookup is memoized per (directory, subcommand), and the same directory under a different --git-dir is a different question, so a key that ignores them returns the wrong cached answer even after the replay is added.
Prefer a single chokepoint that every repository-answering git probe goes through, rather than replaying at each call site. collect_locating_globals on the #1085 branch already produces the replay array from an invocation prefix using the sibling guard's locating set (--git-dir, --work-tree, --namespace; -C deliberately excluded because it is folded into the composed base) and could serve as that seam.
Scope note
The broader placement problem — resolution asked at the outer invocation when the nested one determines the repository — is tracked separately, with this reproduction as part of its specification. The narrow fix here is worth doing regardless of how that design lands, since it closes a live bypass in shipped code.
Related
- The fail-closed placement design issue (this reproduction is one of its two specification cases).
- guardrails: block-noncanonical-commit analyzes the wrong repository when a
!alias body relocates the process (cd) #1486 —cdrelocation gap, same family. - guardrails: block-dangerous-git resolves lease hash-width for the wrong repository across a
!alias hop #1469 —block-dangerous-git'srepo_oid_width(), another wrong-repository-across-a-!-hop instance.
Activity
fix(guardrails): drop the outer fail-closed; identity is best-availab…
kyle-sexton commentedon Jul 26, 2026
This was generated by AI during triage.
Triage: verified — human-gated
General claim: confirmed real by direct code read.
effective_dir()inblock-noncanonical-commit.shcomposes its base directory only fromHOOK_CWD/CLAUDE_PROJECT_DIRplus any-Cpresent in the current segment's own words:It never reads
--git-diror--work-tree. The persisted-alias probe (git -C "$(effective_dir "${w[@]}")" config --get "alias.$sub") is the only call site that resolves a persisted alias, and it inherits that gap unconditionally. The general claim in the title and body is accurate.Correction: the issue's own reproduction does not exercise the line it names. Traced
git --git-dir=<repo>/.git --work-tree=<repo> -c alias.a=b athroughcheck_segment()step by step:alias.a=bis set via inline-c, soaresolves through the inline-alias branch (hook::git_alias_expansionmatchingHOOK_GIT_CONFIG_VALUES), not the persisted-lookup branch this issue targets. That branch's recursive call —check_segment "${w[@]:0:gi+1}" ${expw[@]+"${expw[@]}"} "${w[@]:sub_idx+1}"— drops--git-dir/--work-tree/-cfrom the argv entirely (onlygititself survives the${w[@]:0:gi+1}slice) and setsHOOK_NO_ALIAS=1, which skips the persisted-lookup branch altogether for the recursivebframe. So in this specific repro,git config --get alias.bnever runs at all — the miss happens one step earlier, in the recursive-call construction, which is the same defect #1500 documents in its own R8-2 analysis (posted there in more detail).The narrow fix this issue proposes — replay
--git-dir/--work-treein theconfig --getcall and include them in its cache key — is real and would close a simpler, directly-reachable instance: a non-chained persisted alias reached without an intervening inline-c, e.g.git --git-dir=<repo>/.git --work-tree=<repo> awhere<repo>hasalias.a = commit --allow-empty -m bypassset directly (nobindirection). I did not execute this against a live fixture (no repo mutation authorized for this triage pass), but it follows directly from the code as read: with no inline-cpresent,alias_rcfromhook::git_alias_expansionis 1 (not found), so control reaches the persisted-lookup branch on the first frame — no recursive-call truncation involved — where the missing--git-dir/--work-treereplay is the sole cause of the miss.Net: the fix as scoped is real but incomplete against the issue's own demonstrated repro. Applying only the named fix (replay globals in the one
config --getcall) would not close R8-2 as reproduced in this issue or in #1500, because that exact repro's failure point is the recursive-call argv truncation one level up, not theconfig --getcall. A fix that touches only the named line risks landing as a merged PR that looks complete (the named defect is real, the named line changes) while leaving the demonstrated bypass open — a bad outcome for a security guard, and not something an autonomous agent following the brief as literally scoped would be positioned to catch.Why human-gated, not autonomous-eligible. Two reasons: (1) closing the gap this issue actually demonstrates requires the same recursive-argv-preservation work #1500 is human-gating as an open design question, not a one-line change; (2) even the narrower, directly-reachable instance this fix would close is worth scoping alongside that design decision rather than in isolation, per this issue's own scope note ("the narrow fix here is worth doing regardless of how that design lands") — a human should decide whether to land it standalone now (with the corrected, narrower verification bar noted above) or fold it into #1500's chokepoint work.
Priority. Setting
priority: high, consistent with #1469/#1486/#1495/#1500: a confirmed, shared (main-and-branch) gap in guard coverage, not merely theoretical, but notpriority: criticalabsent an active/observed exploit.Cluster note. Fifth member of the same-root-cause cluster (#1469, #1486, #1495, #1500, #1501); full synthesis and recommendation posted on #1495 (prioritized for its crash/fail-open severity) and cross-referenced on #1500 (the design-carrier candidate). No
blocked-byedge added here: this issue explicitly scopes itself as independently worth doing regardless of the #1500 decision, and the correction above (a narrower but still real fix exists) supports treating it that way rather than as a hard dependent.Role-label note:
.work-item-tracker.jsonhas noconfig.role_labelsentry, so the canonical human-gated role resolves to its documented default (needs-human).Outcome: labels normalized off
priority: needs-triage; applyingpriority: high+needs-human.area: securityretained. Type was already nativeBug.fix(guardrails): replay locating globals on persisted-alias lookup
merge: integrate main (#2456) into persisted-alias locating-globals fix
kyle-sexton commentedon Aug 12, 2026
Drain: tracked by open PR #2461 fix(guardrails): replay locating globals on persisted-alias lookup (no duplicate opened).
fix(guardrails): replay locating globals on persisted-alias lookup
fix(guardrails): replay locating globals on persisted-alias lookup
fix(guardrails): replay locating globals on persisted-alias lookup (#…