Files
recordingtest/historyhooks/protect-files.sh
minsung 5ac612f373 Add history tracking hooks and project structure
- Add docs/history/ directory for work history files
- Add PROGRESS.md for project status tracking
- Add .claude/settings.json with Gitea MCP permissions
- Gitea issue #1: 히스토리 및 AI 사용량 추적 시스템 설정

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-07 11:47:14 +09:00

46 lines
1.5 KiB
Bash

#!/bin/bash
# protect-files.sh
# PreToolUse (Edit|Write) 훅: 보호 파일 수정 차단
#
# 차단 대상:
# - CLAUDE.md (명시적 요청 없이 수정 금지)
# - .env 파일 (보안)
# - storage/ 외부에 영상/바이너리 파일 쓰기
INPUT=$(cat)
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
# 파일 경로가 없으면 통과
if [ -z "$FILE_PATH" ]; then
exit 0
fi
# .env 파일 직접 수정 차단
if echo "$FILE_PATH" | grep -qE '\.env$'; then
echo "Blocked: .env 파일 직접 수정은 보안상 차단됩니다. .env.example을 수정하세요." >&2
exit 2
fi
# storage/ 외부에 영상 파일 쓰기 차단
# 주의: .ts는 TypeScript와 HLS 세그먼트 모두에 사용됨
# src/ 하위의 .ts 파일은 TypeScript이므로 허용
if echo "$FILE_PATH" | grep -qiE '\.(mp4|mkv|webm|mov|avi|m3u8)$'; then
if ! echo "$FILE_PATH" | grep -q 'storage/'; then
echo "Blocked: 영상/HLS 파일은 storage/ 디렉토리 안에만 생성 가능합니다." >&2
exit 2
fi
fi
# HLS .ts 세그먼트 파일만 차단 (src/ 하위 TypeScript 제외)
if echo "$FILE_PATH" | grep -qE '\.ts$'; then
if ! echo "$FILE_PATH" | grep -qE '(src/|\.config\.ts|tsconfig)'; then
if echo "$FILE_PATH" | grep -q 'storage/'; then
: # storage 내 .ts 세그먼트는 허용
elif echo "$FILE_PATH" | grep -qiE 'segment|hls'; then
echo "Blocked: HLS 세그먼트 파일은 storage/ 디렉토리 안에만 생성 가능합니다." >&2
exit 2
fi
fi
fi
exit 0