@@ -12,36 +12,61 @@ NC='\033[0m'
1212# Allowed public API key (used in socket-lib).
1313ALLOWED_PUBLIC_KEY=" sktsec_t_--RAN5U4ivauy4w37-6aoKyYPDt5ZbaT5JBVMqiwKo_api"
1414
15- # Get files in this commit.
16- COMMITTED_FILES=$( git diff --cached --name-only --diff-filter=ACM)
15+ ERRORS=0
1716
18- if [ -z " $COMMITTED_FILES " ]; then
19- exit 0
20- fi
17+ # Get files in this commit (for security checks).
18+ COMMITTED_FILES=$( git diff --cached --name-only --diff-filter=ACM 2> /dev/null || echo " " )
2119
22- ERRORS=0
20+ # Quick checks for critical issues in committed files.
21+ if [ -n " $COMMITTED_FILES " ]; then
22+ for file in $COMMITTED_FILES ; do
23+ if [ -f " $file " ]; then
24+ # Check for Socket API keys (except allowed).
25+ if grep -E ' sktsec_[a-zA-Z0-9_-]+' " $file " 2> /dev/null | grep -v " $ALLOWED_PUBLIC_KEY " | grep -v ' your_api_key_here' | grep -v ' fake-token' | grep -v ' test-token' | grep -v ' \.example' | grep -q . ; then
26+ echo " ${RED} ✗ SECURITY: Potential API key detected in commit!${NC} "
27+ echo " File: $file "
28+ ERRORS=$(( ERRORS + 1 ))
29+ fi
2330
24- # Quick checks for critical issues.
25- for file in $COMMITTED_FILES ; do
26- if [ -f " $file " ]; then
27- # Check for Socket API keys (except allowed).
28- if grep -E ' sktsec_[a-zA-Z0-9_-]+' " $file " 2> /dev/null | grep -v " $ALLOWED_PUBLIC_KEY " | grep -v ' your_api_key_here' | grep -v ' fake-token' | grep -v ' test-token' | grep -v ' \.example' | grep -q . ; then
29- echo " ${RED} ✗ SECURITY: Potential API key detected in commit!${NC} "
30- echo " File: $file "
31- ERRORS=$(( ERRORS + 1 ))
31+ # Check for .env files.
32+ if echo " $file " | grep -qE ' ^\.env(\.local)?$' ; then
33+ echo " ${RED} ✗ SECURITY: .env file in commit!${NC} "
34+ ERRORS=$(( ERRORS + 1 ))
35+ fi
3236 fi
37+ done
38+ fi
3339
34- # Check for .env files.
35- if echo " $file " | grep -qE ' ^\.env(\.local)?$' ; then
36- echo " ${RED} ✗ SECURITY: .env file in commit!${NC} "
37- ERRORS=$(( ERRORS + 1 ))
40+ # Auto-strip AI attribution from commit message.
41+ COMMIT_MSG_FILE=" $1 "
42+ if [ -f " $COMMIT_MSG_FILE " ]; then
43+ # Create a temporary file to store the cleaned message.
44+ TEMP_FILE=$( mktemp)
45+ REMOVED_LINES=0
46+
47+ # Read the commit message line by line and filter out AI attribution.
48+ while IFS= read -r line || [ -n " $line " ]; do
49+ # Check if this line contains AI attribution patterns.
50+ if echo " $line " | grep -qiE " (Generated with|Co-Authored-By: Claude|Co-Authored-By: AI|🤖 Generated|AI generated|Claude Code|@anthropic|Assistant:|Generated by Claude|Machine generated)" ; then
51+ REMOVED_LINES=$(( REMOVED_LINES + 1 ))
52+ else
53+ # Line doesn't contain AI attribution, keep it.
54+ printf ' %s\n' " $line " >> " $TEMP_FILE "
3855 fi
56+ done < " $COMMIT_MSG_FILE "
57+
58+ # Replace the original commit message with the cleaned version.
59+ if [ $REMOVED_LINES -gt 0 ]; then
60+ mv " $TEMP_FILE " " $COMMIT_MSG_FILE "
61+ echo " ${GREEN} ✓ Auto-stripped${NC} $REMOVED_LINES AI attribution line(s) from commit message"
62+ else
63+ # No lines were removed, just clean up the temp file.
64+ rm -f " $TEMP_FILE "
3965 fi
40- done
66+ fi
4167
4268if [ $ERRORS -gt 0 ]; then
4369 echo " ${RED} ✗ Commit blocked by security validation${NC} "
44- echo " Run: git reset HEAD~1"
4570 exit 1
4671fi
4772
0 commit comments