Repository navigation
Description
Problem
block-noncanonical-commit does not evaluate shell relocation, so a persisted or inline ! shell-alias body that moves the process is analyzed against the invoking repository rather than the destination. Real git resolves the destination's aliases, so an alias defined only there is never seen.
This is the compound-cd residual the guard file has always documented. It is not theoretical — it is a demonstrated fail-open.
Reproduction (verified against ground truth, not just exit codes)
outer repo: git config alias.a '!cd child && git a'
child repo: git config alias.a 'commit --allow-empty -m bypass'
$ git a # from the outer repo
hook exit: 0 <- allowed
real git: child commit count 0 -> 1 <- the non-canonical commit LANDED
A second shape matters just as much, because it rules out the obvious narrow fix:
outer repo: git config alias.a '!cd child && git b'
child repo: git config alias.b 'commit --allow-empty -m bypass' # b exists ONLY here
Here no cycle is hit anywhere. The guard reparses git b, resolves b against the outer repository, finds nothing, and allows. So gating the shell-alias cycle-skip (the first suggestion this drew) closes one instance and leaves the class open.
Why it is deferred rather than fixed
The mechanism the guard now uses for directories is correct — it asks git (git -C <dir> rev-parse --show-toplevel) instead of modelling paths, which closed two earlier bypass classes. Asking git cannot close this one: git is never told about the cd. The ! body is shell, and evaluating shell relocation is a different and unbounded problem.
Two candidate fixes were priced and both rejected for this PR:
- Fail closed on any relocating
!body. Closes the class with no modelling, but blocks legitimate aliases —alias.st = !cd .. && git statusworks today, would start blocking, and a user cannot distinguish it from a real threat. Trading a working alias for a gap that needs a relocating!alias plus a commit-capable alias in the destination is the wrong trade. - Follow the
cd. Attempted and reverted — see below.
Prior attempt: f3c221d024 (reverted)
A working implementation exists in reverted commit f3c221d024 ("follow a cd inside a shell-alias body"). It applied cd as a per-segment side effect in segment order through the existing tokenizer, followed a single literal operand, and failed closed on anything computed. It fixed both reproductions above and kept canonical-behind-cd allowed.
It was reverted within the hour because four findings landed against the machinery it added:
| Finding | Shape |
|---|---|
Preserve control flow before applying alias-body cd |
!false && cd child; git b — the cd is unreachable, but it was applied anyway |
Recognize wrapped cd builtins |
command cd child / builtin cd child not classified |
| Restore the directory after subshell segments | !(cd child; true); git b — a subshell cd mutated the global base |
| Replay explicit repository globals | --git-dir/--work-tree not replayed, so a valid canonical commit was refused |
Read as a set, those are not four bugs — they are the first four items of shell semantics: reachability, wrapper forms, scope, and global replay. Quoting, eval, $(…), trap, and set -e are next. Following a cd correctly means implementing a shell interpreter inside a static guard.
Two of them were regressions relative to main. Measured with real-git ground truth, branch vs origin/main's guard:
real want branch main
F1 unreachable cd (false &&) commits 2 0 FAIL 2 ok
F4 cd inside a subshell commits 2 0 FAIL 2 ok
F3 --git-dir/--work-tree canonical no-op 0 2 FAIL 0 ok
Moving the base on an unreachable or subshell-scoped cd sent the guard to the child, where the alias was harmless, so it allowed — while main, which never moves the base, resolved the outer alias and blocked correctly. F3 blocked a valid canonical commit.
f3c221d024 and that findings table are the most useful artifacts here: they are a map of what a real fix must handle, and evidence that a partial implementation is worse than a documented gap.
Fix direction, if picked up
Do not half-interpret shell. Either:
- Fail closed on any relocating
!body, accepting the false-positive cost and giving users a per-alias opt-out so a legitimate!cd .. && git statusstays usable; or - Interpret the body properly — reachability, subshell scope, wrapper builtins, quoting, and global replay — which is a real shell-subset evaluator and should be scoped and tested as such, not grown incrementally inside a guard.
Option 1 is much cheaper and is the honest version of "we cannot see where this runs". Option 2 should not start without the four findings above as its acceptance criteria.
Whichever is chosen, note that repo_identity currently composes only -C; F3 shows it must also replay --git-dir and --work-tree before failing closed, or it refuses valid work. That part is small and worth doing independently of the cd decision.
Related
- guardrails: block-dangerous-git resolves lease hash-width for the wrong repository across a
!alias hop #1469 —block-dangerous-git'srepo_oid_width()resolves the lease hash-width for the wrong repository across a!alias hop. Same family: the guard cannot see which repository a command will run in. - The sibling compound-
cdresidual already documented inblock-dangerous-git.sh(lease_expect_is_immutable/repo_oid_widthcomments): "a compoundcd <elsewhere> && git push …pushes from a directory no option names, so the probe cannot see it."
All three are instances of one boundary: this guard family does static matching over the literal command string and deliberately does not evaluate shell. A fix should address the boundary, not one guard at a time.
Activity
Revert "fix(guardrails): follow a `cd` inside a shell-alias body"
kyle-sexton commentedon Jul 26, 2026
This was generated by AI during triage.
Triage: verified — human-gated
Core defect: confirmed real. Read
effective_dir()inplugins/guardrails/hooks/block-noncanonical-commit.shdirectly: it composes its base directory only fromHOOK_CWD(orCLAUDE_PROJECT_DIR) plus any-C/--git-dirthe current segment's own words carry. There is no recognition of acdbuiltin anywhere in the file, and no state carried across the segmentshook::bash_parse_segmentsproduces that would let acdin an earlier segment of a reparsed!alias body affect where a later segment's git invocation is checked against. That confirms the issue's central claim: the guard has no shell-relocation awareness, so a!alias body thatcds elsewhere is still evaluated against the invoking repository.Prior-attempt claim: confirmed real, and confirmed accurate.
git cat-file -t f3c221d024resolves — the commit exists (f3c221d0 "fix(guardrails): follow acdinside a shell-alias body"), and it was reverted an hour later by66c8eb1f. The revert commit message matches the issue's four-findings table and the real-git-vs-branch-vs-main regression numbers essentially verbatim (F1 unreachablecd, F3--git-dir/--work-treereplay, F4 subshell scoping all reproduced in the revert's own commit body). The issue is not dramatizing this history — it's an accurate account of a real, measured regression.Correction to the issue body. The "Why it is deferred rather than fixed" section states the guard "now" resolves directories by asking git —
git -C <dir> rev-parse --show-toplevel— "instead of modelling paths." I grepped the full currentblock-noncanonical-commit.shfor--show-toplevel: it does not appear anywhere in the file, at any point in its history (confirmed the same in #1469's triage for this file). The only git-asking call in the file isgit -C "$repo" rev-parse --absolute-git-dirinsidesequencer_in_progress(), used to locate the git dir for an in-progress-merge check — unrelated to canonical-repository resolution.effective_dir()itself is pure string composition, never git-resolved. Separately, the issue's block-dangerous-git.sh fix-direction note ("repo_identitycurrently composes only-C") also doesn't match current code — no function namedrepo_identityexists inblock-dangerous-git.shtoday (its analogous helper iscollect_git_locating_opts). Neither correction changes the verified core defect — both are narrative/reference inaccuracies, not the finding itself — but they're the same kind of error #1469's triage already caught in this issue's sibling: citing a resolution mechanism that isn't actually in the codebase. Flagging so an implementer doesn't go looking for code that isn't there.Same family as #1469, cross-referenced explicitly as requested. Both issues are the same underlying trust boundary — "the guard cannot see which repository a command will actually run in once a
!shell-alias body crosses a repository boundary":!alias hop #1469:block-dangerous-git.sh'srepo_oid_width()resolves lease hash-width against the wrong repository across a!hop.!alias body relocates the process (cd) #1486 (this issue):block-noncanonical-commit.shresolves canonical-commit policy against the wrong repository across a!hop that includes acd.Distinct guard, distinct mechanism (hash-width cache key vs. no relocation tracking at all), same root cause class, same "guard does static matching over the literal command string and deliberately does not evaluate shell" boundary the issue's own "Related" section names. #1469 was triaged verified/human-gated/
priority: highearlier this session, including the same kind of "cited mechanism doesn't exist" correction — treating this one the same way for consistency.Why human-gated, not autonomous-eligible. The issue's own "Fix direction" section poses a genuinely open design fork, not a well-grounded default with a reversible alternative:
!body — cheap, but breaks legitimate aliases (!cd .. && git status) with no way for a user to tell a false positive from a real threat apart without a new per-alias opt-out mechanism that doesn't exist yet.f3c221d024) that shipped two measured regressions againstmainbefore being reverted.Neither option is a safe default to pick blind: option 1 has a real UX/false-positive cost that needs a maintainer's product call, and option 2 has already demonstrated that a partial implementation is worse than the documented gap. This is open design-space + a track record of a failed automated attempt, squarely the human-gated branch of the routing test — the same call already made for #1469.
Priority:
priority: high(above the assessed defaultpriority: medium) — significant impact: a demonstrated, verified guard bypass (real commits landing per the issue's ground-truth repro), not merely theoretical. Notcritical: no active/observed in-the-wild exploit, and it requires a specific setup (a persisted or inline relocating!alias plus a commit-capable alias/config in the destination repository) rather than being trivially universal. Consistent with thepriority: highalready applied to #1469 for the same reasoning.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.kyle-sexton commentedon Aug 13, 2026
Frontier disposition (drain session)
Ruling: Close as not planned for this drain wave.
Shell-alias
cdrelocation analyzing the invoking repo instead of the destination is the documented compound-cdresidual. Carrier #1500 owns the unified fix; #1495 owns the crash variant. This filing does not need a third parallel slot.Re-open trigger: #1500 closes without covering alias-body relocation analysis.
fix(guardrails): repo-context chokepoint for block-noncanonical-commit (