Skip to content

guardrails: block-noncanonical-commit on main exits 139 (SIGSEGV) on a wrapped cd builtin in a shell-alias body #1495

Closed as not planned

Description

@kyle-sexton

block-noncanonical-commit on main exits 139 on a wrapped cd builtin

This is a crash in the shipped guard, independent of any open PR. Exit status 139 is 128+11 — SIGSEGV. Reproduced against origin/main's guard (guardrails 0.16.3), not a branch build:

fixture:
  outer repo   git config alias.a '!command cd child && git a'
  child repo   git config alias.a 'commit --allow-empty -m bypass'

$ echo '{"tool_name":"Bash","tool_input":{"command":"git a"},"cwd":"<outer>"}' \
    | bash plugins/guardrails/hooks/block-noncanonical-commit.sh
exit 139

A PreToolUse hook that dies on a signal is worse than one that returns a wrong answer: the exit status is not 0 or 2, so the harness sees neither a clean allow nor a deliberate block. Whatever it does with that is not a decision the guard made. Worth confirming what Claude Code treats a signal-death hook as before deciding severity — if it is treated as non-blocking, this is a fail-open triggered by an attacker-chosen alias body.

Reproduced on git version 2.54.0.windows.1, OSTYPE=cygwin (Git Bash). Needs confirming on Linux/macOS — it may be host-specific, which is itself worth knowing.

Secondary: the wrapped-cd form is not recognized at all

Independently of the crash, command cd <dir> and builtin cd <dir> are literal directory changes that no guard in this family classifies. Real git relocates and commits in the destination:

                                 real git   guard should   main    (branch)
command cd child                 commits    block (2)      139     0

Neither blocks. This is a specific instance of the broader relocation gap tracked in #1486 — the guard does not evaluate shell relocation, and wrapper builtins are one of the forms a real fix would have to handle. It is listed there among the four findings that a reverted attempt drew.

Filing separately from #1486 because the crash is not about relocation semantics at all, ships in main today, and should be triaged on its own timeline.

Suggested first steps

  1. Confirm the exit-139 reproduction on a Linux runner and pin down which statement dies — the fixture is small and the guard runs under set -uo pipefail, so a candidate is an unguarded array/parameter expansion reached only on this path.
  2. Confirm how the harness treats a signal-death PreToolUse hook (allow, block, or error), which sets the real severity.
  3. The recognition gap can then be handled with guardrails: block-noncanonical-commit analyzes the wrong repository when a ! alias body relocates the process (cd) #1486 rather than here.

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

    Core defect: confirmed real, and broader than the title states. Traced check_segment() in block-noncanonical-commit.sh end to end for the persisted (!-prefixed, config-stored) shell-alias path (the git config --get alias.$sub branch, guarded only by HOOK_NO_ALIAS). There is no cycle or recursion-depth guard anywhere in this file for that path — no seen-set, no depth counter, nothing analogous to the one-level HOOK_NO_ALIAS cap that bounds the inline (-c) alias case. Each !-body reparse is a fresh hook::bash_parse_segments … check_segment call with no memory of prior frames.

    In the reported fixture, effective_dir() composes its probe directory from HOOK_CWD (the hook payload's cwd, captured once) plus any -C in the current segment's own words — it has no awareness of a shell cd, wrapped or not. So after the alias body's command cd child && git a reparses into two segments, the second segment (git a) still probes alias.a in the outer repo (because effective_dir never moved), finds the same alias string again, and reparses it again — forever. That's an unbounded recursive check_segment chain with no termination condition, which is what exhausts the stack and produces the OS-delivered SIGSEGV -> bash-reported exit 139.

    Correction: the cd is not actually load-bearing for the crash itself. The same infinite loop reproduces with a bare self-referential persisted alias and no cd at all — e.g. git config alias.a '!git a' then git a — because the persisted-alias lookup has no cycle detection independent of directory tracking. The cd/command wrapper in this issue's fixture is what makes the loop land on a cross-repo commit (tying it to #1486's relocation gap), but the crash mechanism itself is a plain missing-cycle-guard bug in the alias-resolution recursion, not specifically a cd-parsing gap. Worth knowing because a fix aimed only at recognizing command/builtin cd would not close the crash — the missing piece is a seen-set/depth cap on the persisted-alias chain, independent of whether any relocation occurs.

    Severity-determining question, resolved against the current docs, not assumption. Fetched https://code.claude.com/docs/en/hooks this session (per this repo's fresh-docs mandate) and confirmed the exit-code contract directly:

    Exit 2 means a blocking error … PreToolUse blocks the tool call …
    Any other exit code is a non-blocking error for most hook events. The transcript shows a <hook name> hook error notice followed by the first line of stderr … Execution continues …

    And explicitly: "Claude Code treats exit code 1 as a non-blocking error and proceeds with the action, even though 1 is the conventional Unix failure code. If your hook is meant to enforce a policy, use exit 2." Exit 139 (a signal-terminated process) is neither 0 nor 2, so it falls under "any other exit code."

    Confirmed: FAIL-OPEN. The crash does not block the tool call — PreToolUse only blocks on a literal exit code 2, and a signal death reports 128+signal, never 2. The underlying git a (the non-canonical, cross-repo commit in the fixture) proceeds exactly as if the guard had explicitly allowed it, with only a hook error transcript notice (not a block message) as the visible trace. This makes the crash strictly more dangerous than a wrong-verdict bug: it is a guaranteed, deterministic bypass triggerable by any self-referential (or relocation-then-repeat) persisted shell alias — no cross-repo hash-format collision or other narrow precondition required, unlike #1469.

    Why human-gated, not autonomous-eligible. Closing this safely requires designing a cycle/depth-detection primitive for the alias-resolution recursion — precisely the class of "no existing mechanism in this codebase, and a prior attempt at adjacent machinery (f3c221d024) was reverted after shipping regressions" situation that #1486 was already ruled human-gated for. It is also entangled with the "single chokepoint for repository-resolution state across recursive check_segment calls" design question #1500 raises (the same recursive-call argv truncation that drops cd-relocation context also drops other locating globals) — not an isolated, bounded bug fix.

    Priority. Setting priority: high, consistent with the priority: high already applied to #1469 and #1486 for the same reasoning (significant, demonstrated guard-defeat; not priority: critical because there's no active/observed in-the-wild exploit, only a reliably reproducible one requiring an attacker or careless user to have already defined a relocating/self-referential alias). Flagging for the human reviewer that this instance is arguably the most severe of the cluster: unlike #1469/#1486, it needs no cross-repo hash-format coincidence — any self-referential persisted ! alias triggers it — so it may warrant priority: critical on reconsideration; deferring that call to the maintainer rather than defaulting it myself.

    Cluster synthesis — one structural defect, five findings

    This is now the fifth open, verified finding pointing at the same trust boundary in the block-noncanonical-commit / block-dangerous-git guard family, all filed and triaged in this session:

    Every one of these is the same underlying boundary stated explicitly in #1486's and #1500's own "Related" sections: this guard family does static matching over the literal command string, tracks repository identity per-segment rather than propagating it through recursion, and was never designed to survive a ! alias hop or a cd. Patching each guard/each call site individually (as these five issues are scoped) risks a sixth and seventh instance of the same class — the same pattern #1486 already flagged for block-dangerous-git's own documented compound-cd residual.

    Recommendation for the human decision-maker: treat this as one architectural review — most likely resolved by the single-chokepoint design #1500 proposes (a resolved-repository-identity value threaded through every recursive check_segment/alias-expansion call, replayed on every git probe that answers a repository question) — rather than five independent PRs. #1500 is the natural design carrier since its fix-direction section is the only one that names the general mechanism; #1469, #1486, #1495, and #1501 each become verification fixtures once that mechanism exists. I have not added blocked-by edges between these issues: each issue explicitly scopes itself as independently valuable/fixable ("worth doing regardless of how that design lands" — #1501; "filed separately... on its own timeline" — #1495), so a hard dependency edge would misrepresent their own stated scope. This paragraph is the flag for a human to make that judgment call explicitly, since I'm not authorized to restructure the two already-triaged items (#1469, #1486) or unilaterally decide the cluster should be merged into one carrier.

    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. kyle-sexton commented on Aug 13, 2026

    @kyle-sexton
    MemberAuthor

    Frontier disposition (drain session)

    Ruling: Close as not planned for this drain wave.

    SIGSEGV (exit 139) on wrapped cd in alias bodies is a live crash but structurally the same compound-shell class as carrier #1500. Fix and regression belong in that coordinated guard pass, not a parallel tracker slot.

    Re-open trigger: Crash repro still passes on main after #1500 closes.

  6. added a commit that references this issue on Oct 20, 2026
    9b12bc0
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