Skip to content

Git-hook floor can live outside the repo: an absolute core.hooksPath is honored but never reported, and an unrelated rm -rf silently removes the gate #496

Closed

Description

@sandstream

The gap

kit hooks add writes the git-hook enforcement floor into the directory git will actually run hooks from — resolveHooksDir() honors core.hooksPath, and that is correct: installing into .git/hooks while git reads somewhere else would be a silent no-op, which is the defect the comment at src/hooks.ts:8-18 exists to prevent.

What is missing is everything around it. When core.hooksPath is absolute and points outside the repo, kit will:

  1. write the hook outside the repo root — creating the directory tree if it does not exist — and report ✓ installed;
  2. never mention that the floor for this repo lives in another directory;
  3. leave no surface (kit check, kit status, kit doctor, kit hooks) that reports the floor is external, or that it now dangles.

So the gate can disappear because of a change to a directory that has nothing to do with the repo, and every kit report stays green.

This also contradicts a declared scope claim in src/fix.ts:205-212:

// Git-hook installs resolve their target via `core.hooksPath` at runtime;
// they land inside the repo, which the repo-rooted [scope].fs covers.

They do not always land inside the repo. Measured below: the write target's realpath is not under the repo root, so a repo-rooted [scope].fs does not cover it.

Reproduction (6.6.5, macOS, non-root)

The starting state is ordinary: a second checkout made by copying the first, so .git/config carries the first one's absolute core.hooksPath. Nothing exotic sets it.

$ git init -q clone-b && cd clone-b
$ printf '[tools]\nnode = "22"\n' > .kit.toml && git add -A && git commit -qm init
$ git config core.hooksPath "$PWD/.git/hooks"     # absolute, as husky/kit setups often leave it
$ cd .. && cp -R clone-b clone-a                  # the copy inherits the absolute path

$ git -C clone-a config core.hooksPath
/tmp/repro/clone-b/.git/hooks                     # clone-a's hooks live in clone-b

1. The install lands outside the repo and says nothing about it

$ cd clone-a && kit hooks add secret-scan --non-interactive
  ✓ pre-commit  installed  1 command(s)

$ ls clone-a/.git/hooks | grep -v sample     # empty
$ ls clone-b/.git/hooks | grep -v sample
post-commit
pre-commit

2. The gate does fire — so nothing looks wrong

$ printf 'const k = "sk_test_AAAAAAAAAAAAAAAAAAAA";\n' > leak.ts && git add leak.ts
$ git commit -qm "blocked?"
✗ kit secret-scan blocked the commit
Found 1 potential secret(s) in 1 staged file(s):
$ git rev-list --count HEAD
1

3. Delete the OTHER directory. Touch nothing in this repo.

$ rm -rf ../clone-b
$ git commit -qm "still blocked?"       # same staged fake credential
$ git rev-list --count HEAD
2                                        # committed. exit 0. no warning.

4. No kit surface reports the dangling floor

$ git config core.hooksPath
/tmp/repro/clone-b/.git/hooks
$ ls "$(git config core.hooksPath)"
ls: .../clone-b/.git/hooks: No such file or directory

$ kit status  | grep -i hook
  ○ memory hooks  not installed  → run `kit memory install`
$ kit doctor  | grep -i hook
  ✓ hook wrapper  ~/.kit/bin/kit
  ✓ memory hooks  5 wired
$ kit check --category security | grep -i hook
  ✓ memory hooks liveness   pass  5 capture hook(s) wired

Git-hook state is not reported at all here, so a hooks path that resolves to nothing reads exactly like a repo that never wired hooks — and kit status's next-step line (kit hooks install) is the same in both cases.

5. Re-installing recreates a tree outside the repo

$ kit hooks add secret-scan --non-interactive
  ✓ pre-commit  installed  1 command(s)

$ ls ../clone-b/.git/hooks                # kit re-created the deleted directory
post-commit  pre-commit
$ ls .git/hooks | grep -v sample          # still empty

repo:   /tmp/repro/clone-a
hooks:  /tmp/repro/clone-b/.git/hooks
inside repo: False

kit created a directory hierarchy in an unrelated location and reported success.

Why this is the same family as #470 and #488

Proposed

  1. Report the location. A kit check / kit doctor row for the git-hook floor: which directory it resolves to, and whether that is inside the repo. kit hooks add should print the resolved path when it is external, rather than a bare ✓ installed.
  2. A dangling hooks path is a finding, not silence. core.hooksPath pointing at a non-existent directory means every hook is off; that is a fail-closed condition for a repo that has hooks configured, and today it is unreported.
  3. Do not create directories outside the repo without saying so. Re-creating a deleted external tree on kit hooks add is surprising; at minimum name the path, or require an explicit opt-in.
  4. Correct the fix.ts scope comment, and consider declaring the resolved hooks dir in scopeNeeds.fsWrites when it is external, so [scope].fs describes the write that actually happens.

Not proposed

Stopping kit from honoring core.hooksPath — that behavior is right, and src/hooks.ts explains why. The gap is the reporting and the scope claim, not the resolution.

Provenance

Found on a machine holding two checkouts of the same repository, one copied from the other, where the copy's inherited absolute core.hooksPath put its hooks in the original's tree. Reproduced from scratch above with throwaway repos; measured against 6.6.5.

🤖 Generated with Claude Code

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions