Skip to content

guardrails: persisted-alias lookup drops --git-dir/--work-tree, missing a non-canonical commit (shared gap with main) #1501

Closed

Description

@kyle-sexton

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

Activity

  1. added
    needs-triage
    area: security
    on Jul 26, 2026
  2. added theissue type on Jul 26, 2026
  3. kyle-sexton commented on Jul 26, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage.

    Triage: verified — human-gated

    General claim: confirmed real by direct code read. effective_dir() in block-noncanonical-commit.sh composes its base directory only from HOOK_CWD/CLAUDE_PROJECT_DIR plus any -C present in the current segment's own words:

    local base="${HOOK_CWD:-${CLAUDE_PROJECT_DIR:-.}}" …
    if [[ "$arg" == "-C" ]] && …
    

    It never reads --git-dir or --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 a through check_segment() step by step: alias.a=b is set via inline -c, so a resolves through the inline-alias branch (hook::git_alias_expansion matching HOOK_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/-c from the argv entirely (only git itself survives the ${w[@]:0:gi+1} slice) and sets HOOK_NO_ALIAS=1, which skips the persisted-lookup branch altogether for the recursive b frame. So in this specific repro, git config --get alias.b never 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-tree in the config --get call 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> a where <repo> has alias.a = commit --allow-empty -m bypass set directly (no b indirection). 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 -c present, alias_rc from hook::git_alias_expansion is 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-tree replay 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 --get call) 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 the config --get call. 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 not priority: critical absent 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-by edge 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.json has no config.role_labels entry, so the canonical human-gated role resolves to its documented default (needs-human).

    Outcome: labels normalized off priority: needs-triage; applying priority: high + needs-human. area: security retained. Type was already native Bug.

  4. added
    needs-human
    and removed
    needs-triage
    on Jul 26, 2026
  5. added 2 commits that reference this issue on Aug 12, 2026
    7801121
    2d9fcbb
  6. kyle-sexton commented on Aug 12, 2026

    @kyle-sexton
    MemberAuthor

    Drain: tracked by open PR #2461 fix(guardrails): replay locating globals on persisted-alias lookup (no duplicate opened).

  7. added a commit that references this issue on Aug 12, 2026
    4de8d2b
  8. added 2 commits that reference this issue on Aug 12, 2026
    5672f20
    75ffa1a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: securityneeds-human

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions