Skip to content

fix(hooks): turn off config-driven commands on the git ignore checks hooks run - #17104

Merged
kyle-sexton merged 2 commits into
mainfrom
fix/16959-git-overrides
Nov 18, 2026
Merged

kyle-sexton merged 2 commits into
mainfrom
fix/16959-git-overrides

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Refs: #16959

Summary

git check-ignore reads the index, which starts the command a repository's core.fsmonitor
names. The git ignore checks that hooks run now go through one shared helper,
hook::git_untrusted in lib/hook-utils.sh. It passes the overrides PR #16954 uses
(--no-pager -c core.fsmonitor=false -c core.hooksPath=/dev/null), which outrank the repository's
config and its includes.

Fix

The changed hooks, which run in every session that has these plugins:

  • hook::file_is_gitignored in lib/hook-utils.sh and its 22 synced copies. The format hooks
    and the other carriers call it through hook::gitignored_out_of_scope.
  • guardrails secret-pattern-detection: spd_gitignored, which runs only with
    secret_pattern_detection_skip_gitignored on (off by default).
  • guardrails hardcoded-path-check: its ignore check against CLAUDE_PROJECT_DIR.

No other git call changes. block-main-checkout-edit already passes these overrides through its
own mce::git_exec. A patch changelog fragment was added for each of the 22 plugins that carry
hook-utils.sh.

Verification

  • Each changed check has a test: core.fsmonitor is planted in a fixture repository. A plain
    git check-ignore is shown to run it, then the hook's check runs, returns the right answer, and
    the marker file stays absent.
  • bash lib/hook-utils.test.sh: PASS=714 FAIL=0. Its fixture writes the planted hook's path in
    cygpath -m form where cygpath exists. The same fix made the fixture fire under Git for Windows
    on PR ci(guardrails): run the main-checkout edit guard's suite in Windows CI #17073, where the bash-form path in an include file did not.
  • bash plugins/guardrails/hooks/secret-pattern-detection.test.sh: PASS=315 FAIL=0.
  • bash plugins/guardrails/hooks/hardcoded-path-check.test.sh: PASS=173 FAIL=0.
  • scripts/sync-shared-copies.sh synced the copies; check-changelog-fragments.sh --check
    passes; shellcheck -x is clean; the pre-push check-affected passed.
  • Left out: the other plugins' hook suites. They call the helper only through
    hook::file_is_gitignored, which lib/hook-utils.test.sh covers, and CI runs them.

Not delivered

  • The issue's first Done-when line asks for every git call a hook makes against a repository it did
    not create. This PR covers the git ignore checks, as the issue title says. Other hook git calls
    that read the index are unchanged.
  • lib/resolve-convention-pattern.sh (and its guardrails copy, run by block-convention-violation)
    is unchanged. It is POSIX sh, so it cannot use the bash helper, and its git ls-files calls
    read the index before its check-ignore does. Changing only its ignore check would not stop a
    planted fsmonitor.

Related

🤖 Generated with Claude Code

https://claude.ai/code/session_01VcupokBnD3fgV5DKj7GeJA

kyle-sexton and others added 2 commits November 18, 2026 01:24
…hooks run

A git check-ignore reads the index, which starts the command a repository's
core.fsmonitor names. The new hook::git_untrusted helper in lib/hook-utils.sh
runs git with --no-pager -c core.fsmonitor=false -c core.hooksPath=/dev/null,
which outrank the repository's config and its includes. Three ignore checks
now go through it:

- hook::file_is_gitignored (lib/hook-utils.sh and its 22 synced copies),
  which the format hooks call through hook::gitignored_out_of_scope;
- spd_gitignored in guardrails' secret-pattern-detection
  (secret_pattern_detection_skip_gitignored, off by default);
- hardcoded-path-check's ignore check against CLAUDE_PROJECT_DIR.

Each suite plants core.fsmonitor in a fixture repository, shows plain
git check-ignore runs it, and shows the hook's check does not.

lib/resolve-convention-pattern.sh is unchanged: it is POSIX sh, so it cannot
use the helper, and its git ls-files calls read the index before its ignore
check does.

Refs: #16959

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VcupokBnD3fgV5DKj7GeJA
The include file written by printf held the bash-form /tmp path, which the
shell converts only in arguments, and the include overrides the converted
value in .git/config, so Git for Windows could not run the planted hook and
the fixture's proof would fail there. The include now names the hook in
cygpath -m form where cygpath exists, as the block-main-checkout-edit suite
does.

Refs: #16959

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01VcupokBnD3fgV5DKj7GeJA
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 18, 2026 09:39
@kyle-sexton

Copy link
Copy Markdown
Member Author

Owned by the hub session Plugin Presets; it watches checks and review threads and merges.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T09:43:28.560768Z b21b957 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

claude-security-review reviewed b21b957290b2c3b64cc3af6ced59f14c30413ca2: read 50 of 50 changed file(s); 0 finding(s), 0 as inline comments.

Security review: no security issues found

This change makes hooks safer. It adds hook::git_untrusted in lib/hook-utils.sh and its 22 synced copies. The helper runs git --no-pager -c core.fsmonitor=false -c core.hooksPath=/dev/null "$@", and the git ignore checks now go through it:

  • hook::file_is_gitignored in lib/hook-utils.sh and its copies.
  • spd_gitignored in guardrails secret-pattern-detection.sh.
  • The CLAUDE_PROJECT_DIR ignore check in guardrails hardcoded-path-check.sh.

What I checked:

  • The overrides work. Settings passed with -c on the command line outrank repository config and its include.path files, so a repository's planted core.fsmonitor can no longer start a command when the index is read. The new tests plant the value both directly and through an include file. Each test first shows that a plain git check-ignore runs the planted command, so the fixture really fires.
  • The helper is defined where it is called. Both guardrails hooks source hook-utils.sh and exit 70 if that fails (hardcoded-path-check.sh#L49, secret-pattern-detection.sh#L58). The call can't fail with "command not found", which would wrongly read as "not ignored".
  • Nothing is weakened. No ignore-check answer, environment scrubbing, guard or allowlist is loosened, and no instruction surface, manifest, workflow, token or trust control changes. The 22 changelog fragments are prose only.
  • Identical copies. The 22 hook-utils.sh copies all sit at hook or script library paths. plugins/repo-hygiene/skills/clean/scripts/hook-utils.sh is the only one outside a hooks/ directory, and it is the same sourced library. No copy's location changes what its content does.

Two gaps the PR description already states, neither added by this diff:

  • Other hook git calls that read the index still don't use the overrides.
  • lib/resolve-convention-pattern.sh is unchanged.

The review was not blocking only: this lane had not reviewed an earlier head.

critical-findings: 0

@github-actions

Copy link
Copy Markdown
Contributor

claude-review reviewed b21b957290b2c3b64cc3af6ced59f14c30413ca2: read 50 of 50 changed file(s); 0 finding(s), 0 as inline comments.

Code review: PR #17104, no findings

The PR adds one shared helper, hook::git_untrusted, in lib/hook-utils.sh and its 22 synced copies. The helper runs git --no-pager -c core.fsmonitor=false -c core.hooksPath=/dev/null "$@". Three git ignore checks now go through it:

  • hook::file_is_gitignored
  • spd_gitignored in secret-pattern-detection.sh
  • the CLAUDE_PROJECT_DIR ignore check in hardcoded-path-check.sh

What I checked:

  • The helper is defined in both guardrails hooks. Both source hook-utils.sh before they call it (hardcoded-path-check.sh:49, secret-pattern-detection.sh:58), so it cannot be missing at run time. If it were missing, the call would return 127 and the file would read as "not ignored".
  • Behaviour is unchanged apart from the overrides. The arguments and the 2>/dev/null stay the same. The helper only adds -c overrides, and those outrank the repository's config and its includes.
  • The tests prove the fix. Each new test plants core.fsmonitor, checks the hook's answer and that the marker file stays absent, then runs a plain git check-ignore to show the planted fixture really fires. That last step stops a fixture that never fires from passing by accident.
    • In secret-pattern-detection.test.sh, the target $SPE_GB/.work/x.md with the token still reaches the ignore-skip path. Without the skip it exits 2 (line 1365), so exit 0 can only come from the skip. The test unsets core.fsmonitor afterwards.
    • In hardcoded-path-check.test.sh, git add .gitignore first creates an index so the planted fsmonitor can fire. Nothing later in that test uses GITREPO, so the leftover config has no effect.
    • assert_file_absent, ok and bad come from guardrails-test-helpers.sh, which both test files source.
  • Copies. The 21 copies of hook-utils.sh and of the changelog fragment have the same content as the first path. The repo-hygiene/skills/clean/scripts/hook-utils.sh copy is a library a script sources, so its path does not change what the content does.
  • Changelog fragments. Each of the 22 plugins gets a bump: patch fragment under Security. A patch bump fits a fix that adds no new interface.
  • Test results. The pass counts in the PR body come from the author; I did not run the tests myself.

Closing issue: the PR says Refs: #16959 and closes no issue, so there were no acceptance criteria to check. The PR body says it covers only the git ignore checks, and leaves the other hook git calls and lib/resolve-convention-pattern.sh unchanged.

Loosened-check verdict: fail (default; the wrapper gave no verdict or patterns line); patterns: 0. The diff adds assertions and loosens no check.

Spend: none; the change runs no paid or billed resource.

Verifier dropped 0 of 0 candidates.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 18, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 18, 2026
@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 9184de0 Nov 18, 2026
108 of 111 checks passed
@kyle-sexton
kyle-sexton deleted the fix/16959-git-overrides branch November 18, 2026 11:17
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 18, 2026
kyle-sexton added a commit that referenced this pull request Nov 18, 2026
#17104 added hook::git_untrusted for the three ignore checks. Drop this
branch's HOOK_GIT array, and the array the merge from main left beside the
function, and call the function at the remaining hook git call sites. Sites
a bash function cannot reach without an extra process or at all (a `( … )`
subshell or pipeline tail, an exec'd argv, `command git`, POSIX sh, Node, a
library sourced without hook-utils.sh) write the same overrides out.

block-dangerous-git's width probe and the hardcoded-path-check and
temp-scratch probes used `$(exec git … 2>…)` for one process; a function
cannot be exec'd, so the width probe runs `exec 2>&1` first inside the
substitution and the other two put the redirect on a group around the
assignment: one clone each under strace, as before. The comments that
explained the old `exec` are removed.

Trim lib/hook-git.test.sh to the sites #17104's tests do not cover, and
reword the 22 fragments to what this branch adds.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-path: owner-agent Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant