[WRONG BRANCH] fix(scripts): refuse installing repo hooks into configured shared core.hooksPath - #229
Conversation
|
✅ Deterministic PR hygiene checks passed. |
📝 WalkthroughWalkthroughThe hook setup script now refuses installation when ChangesGit hook safety
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
⏳ DRAFT
What to do
Its title has been prefixed with |
core.hooksPathcore.hooksPath
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 479a5f6d3c
ℹ️ 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const configPath = join(directory, "gitconfig"); | ||
| const existingHook = join(hooksDirectory, "pre-push"); | ||
| mkdirSync(hooksDirectory); | ||
| writeFileSync(configPath, `[core]\n\thooksPath = ${hooksDirectory}\n`); |
There was a problem hiding this comment.
Escape the generated hooks path for Git config
On Windows, hooksDirectory contains backslashes (typically C:\Users\...), and interpolating it verbatim into the config makes sequences such as \U invalid to Git's config parser. Consequently, git config --get exits with a parse error, the script emits could not inspect instead of the expected refusal message, and this new test fails the Windows suite. Write the value using git config --file ... core.hooksPath ..., or normalize/escape the path before writing it.
AGENTS.md reference: AGENTS.md:L136-L137
Useful? React with 👍 / 👎.
Motivation
git rev-parse --git-path hooks, which honorscore.hooksPathand could install cwd-dependent pre-push hooks into a global/shared hooks directory, allowing arbitrary code execution and overwriting global hooks for unrelated repositories.prepushscript.Description
git config --get core.hooksPathand fails closed whencore.hooksPathis configured, preventing installation into a potentially shared hooks directory; the installer still supports repository-local and linked-worktree hooks whencore.hooksPathis unset (scripts/setup-hooks.ts).git rev-parse --path-format=absolute --git-path hooksfor linked worktrees and non-standard layouts after thecore.hooksPathguard.tests/setup-hooks.test.ts).core.hooksPathredirects them (CONTRIBUTING.md).Testing
bun test tests/setup-hooks.test.tsand the new test passed (1 pass, 0 fail).bun run typecheck(bun x tsc --noEmit) and it passed.bun run privacy:scanand it passed.git diff --checkand there were no whitespace or patch issues.bun run prepush/ full test suite for context; the focused changes and checks passed, while two unrelated CI-sensitive tests (tests/cli-help.test.ts) observed pre-existing environment-dependent failures not caused by this change.Codex Task
Summary by CodeRabbit
Bug Fixes
Documentation