Skip to content

fix: reject symlinked hook directories before mutation - #31

Merged
altaywtf merged 2 commits into
mainfrom
fix/hooks-containment
Sep 5, 2026
Merged

fix: reject symlinked hook directories before mutation#31
altaywtf merged 2 commits into
mainfrom
fix/hooks-containment

Conversation

@altaywtf

@altaywtf altaywtf commented Sep 5, 2026

Copy link
Copy Markdown
Member

Problem

Hook installation rejects a symlinked hook file but follows a symlinked .githooks directory, changing an external file's permissions and configuring Git to execute it.

Solution

Use the existing workspace filesystem boundary before either mutation. Open the validated regular hook without following a final symlink, check its identity, and apply executable permissions through that descriptor. Valid linked worktrees remain supported. Missing hooks keep a distinct diagnostic; missing paths also leave Git configuration unchanged.

Proof

Two new source-CLI parent-symlink regressions failed before the fix: the external hook changed from0600 to0711. The focused suite passes22 tests. The full gate passes165 tests with91.48% aggregate line coverage, unchanged frozen parity, build and installed-tarball smoke. Independent Astra review is clean. Fixtures verify external permissions and both existing/unset Git configuration remain unchanged on rejection. This does not claim isolation from arbitrary concurrent hostile filesystem replacement.

Copilot AI lite review requested due to automatic review settings September 5, 2026 11:31
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-05T11:41:32.604851Z 46705b6 New commits
ℹ️ 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.

@slopzapper slopzapper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ CLEAN

hooks install now refuses a symlinked .githooks parent and a symlinked pre-commit before git config or chmod, and the new cases prove both leave the external mode and local Git config untouched.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is narrowly scoped, adds targeted regression tests for the identified security/escape scenario, and the updated implementation consistently applies workspace-boundary validation before mutating config or permissions.

Pull request overview

This PR hardens hooks install against symlink-based escape paths by validating the .githooks/pre-commit path within the workspace filesystem boundary before any mutation, and by applying executable permissions through a verified file descriptor to avoid unexpected external permission changes.

Changes:

  • Add regression coverage ensuring hooks install rejects symlinked .githooks parents or hook files without mutating Git config or external file permissions.
  • Update hook installation to use workspaceLstat for workspace-boundary validation and openSync(...O_NOFOLLOW) + fchmodSync on a verified descriptor for safe permission changes.
File summaries
File Description
test/hooks.test.ts Adds regression tests for symlinked parent/hook scenarios and ensures rejection is non-mutating.
src/hooks.ts Enforces workspace-boundary checks for the hook path and applies executable bits via a verified, non-following file descriptor.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/hooks.ts

@slopzapper slopzapper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ CLEAN

The change is clean. Hook install now rejects symlink parents and non-regular hook files before git config or chmod, and a missing hook no longer looks like an invalid type.

@altaywtf
altaywtf merged commit 0e2ed1c into main Sep 5, 2026
3 checks passed
@altaywtf
altaywtf deleted the fix/hooks-containment branch September 5, 2026 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants