T06 · System Persistence
- Location
install-hooks.sh:14- Finding
Persistent Git Hook Installation and Replacement
- Content
View full analysis
"$HOOKS_DIR/pre-commit" << 'HOOKEOF' #!/bin/bash # Skill Registry pre-commit hook # 自动更新 INDEX.md 并加入当前 commit SKILLS_DIR="$(git rev-parse --show-toplevel)/skills" REGISTER_SCRIPT="$SKILLS_DIR/skill-index/register.sh" INDEX_FILE="$SKILLS_DIR/INDEX.md" if [ -f "$REGISTER_SCRIPT" ] && git diff --cached --name-only | grep -q "^skills/"; then echo "🔄 Skill 目录有变更,更新索引..." bash "$REGISTER_SCRIPT" --quiet git add "$INDEX_FILE" echo "✅ INDEX.md 已更新并加入 commit" fi HOOKEOF chmod +x "$HOOKS_DIR/pre-commit" echo " ✅ pre-commit hook 已安装" # post-merge hook cat > "$HOOKS_DIR/post-merge" << 'HOOKEOF' #!/bin/bash # Skill Registry post-merge hook # pull 后自动更新索引 SKILLS_DIR="$(git rev-parse --show-toplevel)/skills" REGISTER_SCRIPT="$SKILLS_DIR/skill-index/register.sh" if [ -f "$REGISTER_SCRIPT" ]; then echo "🔄 Pull 完成,更新 skill 索引..." bash "$REGISTER_SCRIPT" --quiet fi HOOKEOF chmod +x "$HOOKS_DIR/post-merge" ``` ### Technical Analysis The installer directly writes executable files to `.git/hooks/pre-commit` and `.git/hooks/post-merge` using shell redirection. Because `>` replaces the destination, any existing hooks are overwritten without backup, confirmation, or safe chaining. The installed hooks establish execution triggers that remain active after the installation process ends: - The `pre-commit` hook runs during future commits when staged paths begin with `skills/`. - The `post-merge` hook runs after future merges. - Both hooks invoke the mutable repository file `skills/skill-index/register.sh`. - The pre-commit hook additionally runs `git add "$INDEX_FILE"`, modifying the set of content included in the pending commit. Although the documented purpose is automatic index maintenance, the hooks trust whate ...[truncated 2355 chars]- Remediation
View remediation
