Skip to content

Commit cc33a43

Browse files
committed
fix(hooks): add -e flag to echo for ANSI color support
Git hooks were displaying raw ANSI escape codes instead of colors. The `echo` command requires the `-e` flag to interpret backslash escape sequences like `\033[0;32m`. Changes: - Add `-e` flag to all echo statements with color variables - Affects both pre-commit and pre-push hooks - Colors now display correctly: green for success, red for errors, yellow for warnings
1 parent fe3af46 commit cc33a43

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

.git-hooks/pre-commit

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ NC='\033[0m'
1313
# Allowed public API key (used in socket-lib).
1414
ALLOWED_PUBLIC_KEY="sktsec_t_--RAN5U4ivauy4w37-6aoKyYPDt5ZbaT5JBVMqiwKo_api"
1515

16-
echo "${GREEN}Running Socket Security checks...${NC}"
16+
echo -e "${GREEN}Running Socket Security checks...${NC}"
1717

1818
# Get list of staged files.
1919
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM)
2020

2121
if [ -z "$STAGED_FILES" ]; then
22-
echo "${GREEN}✓ No files to check${NC}"
22+
echo -e "${GREEN}✓ No files to check${NC}"
2323
exit 0
2424
fi
2525

@@ -28,23 +28,23 @@ ERRORS=0
2828
# Check for .DS_Store files.
2929
echo "Checking for .DS_Store files..."
3030
if echo "$STAGED_FILES" | grep -q '\.DS_Store'; then
31-
echo "${RED}✗ ERROR: .DS_Store file detected!${NC}"
31+
echo -e "${RED}✗ ERROR: .DS_Store file detected!${NC}"
3232
echo "$STAGED_FILES" | grep '\.DS_Store'
3333
ERRORS=$((ERRORS + 1))
3434
fi
3535

3636
# Check for log files.
3737
echo "Checking for log files..."
3838
if echo "$STAGED_FILES" | grep -E '\.log$' | grep -v 'test.*\.log'; then
39-
echo "${RED}✗ ERROR: Log file detected!${NC}"
39+
echo -e "${RED}✗ ERROR: Log file detected!${NC}"
4040
echo "$STAGED_FILES" | grep -E '\.log$' | grep -v 'test.*\.log'
4141
ERRORS=$((ERRORS + 1))
4242
fi
4343

4444
# Check for .env files.
4545
echo "Checking for .env files..."
4646
if echo "$STAGED_FILES" | grep -E '^\.env(\.local)?$'; then
47-
echo "${RED}✗ ERROR: .env or .env.local file detected!${NC}"
47+
echo -e "${RED}✗ ERROR: .env or .env.local file detected!${NC}"
4848
echo "$STAGED_FILES" | grep -E '^\.env(\.local)?$'
4949
echo "These files should never be committed. Use .env.example instead."
5050
ERRORS=$((ERRORS + 1))
@@ -61,7 +61,7 @@ for file in $STAGED_FILES; do
6161

6262
# Check for common user path patterns.
6363
if grep -E '(/Users/[^/\s]+/|/home/[^/\s]+/|C:\\Users\\[^\\]+\\)' "$file" 2>/dev/null | grep -q .; then
64-
echo "${RED}✗ ERROR: Hardcoded personal path found in: $file${NC}"
64+
echo -e "${RED}✗ ERROR: Hardcoded personal path found in: $file${NC}"
6565
grep -n -E '(/Users/[^/\s]+/|/home/[^/\s]+/|C:\\Users\\[^\\]+\\)' "$file" | head -3
6666
echo "Replace with relative paths or environment variables."
6767
ERRORS=$((ERRORS + 1))
@@ -74,7 +74,7 @@ echo "Checking for API keys..."
7474
for file in $STAGED_FILES; do
7575
if [ -f "$file" ]; then
7676
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 'SOCKET_SECURITY_API_KEY=' | grep -v 'fake-token' | grep -v 'test-token' | grep -q .; then
77-
echo "${YELLOW}⚠ WARNING: Potential API key found in: $file${NC}"
77+
echo -e "${YELLOW}⚠ WARNING: Potential API key found in: $file${NC}"
7878
grep -n 'sktsec_' "$file" | grep -v "$ALLOWED_PUBLIC_KEY" | grep -v 'your_api_key_here' | grep -v 'fake-token' | grep -v 'test-token' | head -3
7979
echo "If this is a real API key, DO NOT COMMIT IT."
8080
fi
@@ -92,32 +92,32 @@ for file in $STAGED_FILES; do
9292

9393
# Check for AWS keys.
9494
if grep -iE '(aws_access_key|aws_secret|AKIA[0-9A-Z]{16})' "$file" 2>/dev/null | grep -q .; then
95-
echo "${RED}✗ ERROR: Potential AWS credentials found in: $file${NC}"
95+
echo -e "${RED}✗ ERROR: Potential AWS credentials found in: $file${NC}"
9696
grep -n -iE '(aws_access_key|aws_secret|AKIA[0-9A-Z]{16})' "$file" | head -3
9797
ERRORS=$((ERRORS + 1))
9898
fi
9999

100100
# Check for GitHub tokens.
101101
if grep -E 'gh[ps]_[a-zA-Z0-9]{36}' "$file" 2>/dev/null | grep -q .; then
102-
echo "${RED}✗ ERROR: Potential GitHub token found in: $file${NC}"
102+
echo -e "${RED}✗ ERROR: Potential GitHub token found in: $file${NC}"
103103
grep -n -E 'gh[ps]_[a-zA-Z0-9]{36}' "$file" | head -3
104104
ERRORS=$((ERRORS + 1))
105105
fi
106106

107107
# Check for private keys.
108108
if grep -E '-----BEGIN (RSA |EC |DSA )?PRIVATE KEY-----' "$file" 2>/dev/null | grep -q .; then
109-
echo "${RED}✗ ERROR: Private key found in: $file${NC}"
109+
echo -e "${RED}✗ ERROR: Private key found in: $file${NC}"
110110
ERRORS=$((ERRORS + 1))
111111
fi
112112
fi
113113
done
114114

115115
if [ $ERRORS -gt 0 ]; then
116116
echo ""
117-
echo "${RED}✗ Security check failed with $ERRORS error(s).${NC}"
117+
echo -e "${RED}✗ Security check failed with $ERRORS error(s).${NC}"
118118
echo "Fix the issues above and try again."
119119
exit 1
120120
fi
121121

122-
echo "${GREEN}✓ All security checks passed!${NC}"
122+
echo -e "${GREEN}✓ All security checks passed!${NC}"
123123
exit 0

.git-hooks/pre-push

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ YELLOW='\033[1;33m'
1111
GREEN='\033[0;32m'
1212
NC='\033[0m'
1313

14-
echo "${GREEN}Running mandatory pre-push validation...${NC}"
14+
echo -e "${GREEN}Running mandatory pre-push validation...${NC}"
1515

1616
# Allowed public API key (used in socket-lib).
1717
ALLOWED_PUBLIC_KEY="sktsec_t_--RAN5U4ivauy4w37-6aoKyYPDt5ZbaT5JBVMqiwKo_api"
@@ -46,7 +46,7 @@ while read local_ref local_sha remote_ref remote_sha; do
4646

4747
if echo "$full_msg" | 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
4848
if [ $ERRORS -eq 0 ]; then
49-
echo "${RED}✗ BLOCKED: AI attribution found in commit messages!${NC}"
49+
echo -e "${RED}✗ BLOCKED: AI attribution found in commit messages!${NC}"
5050
echo "Commits with AI attribution:"
5151
fi
5252
echo " - $(git log -1 --oneline "$commit_sha")"
@@ -76,21 +76,21 @@ while read local_ref local_sha remote_ref remote_sha; do
7676
if [ -n "$CHANGED_FILES" ]; then
7777
# Check for sensitive files.
7878
if echo "$CHANGED_FILES" | grep -qE '^\.env(\.local)?$'; then
79-
echo "${RED}✗ BLOCKED: Attempting to push .env file!${NC}"
79+
echo -e "${RED}✗ BLOCKED: Attempting to push .env file!${NC}"
8080
echo "Files: $(echo "$CHANGED_FILES" | grep -E '^\.env(\.local)?$')"
8181
ERRORS=$((ERRORS + 1))
8282
fi
8383

8484
# Check for .DS_Store.
8585
if echo "$CHANGED_FILES" | grep -q '\.DS_Store'; then
86-
echo "${RED}✗ BLOCKED: .DS_Store file in push!${NC}"
86+
echo -e "${RED}✗ BLOCKED: .DS_Store file in push!${NC}"
8787
echo "Files: $(echo "$CHANGED_FILES" | grep '\.DS_Store')"
8888
ERRORS=$((ERRORS + 1))
8989
fi
9090

9191
# Check for log files.
9292
if echo "$CHANGED_FILES" | grep -E '\.log$' | grep -v 'test.*\.log' | grep -q .; then
93-
echo "${RED}✗ BLOCKED: Log file in push!${NC}"
93+
echo -e "${RED}✗ BLOCKED: Log file in push!${NC}"
9494
echo "Files: $(echo "$CHANGED_FILES" | grep -E '\.log$' | grep -v 'test.*\.log')"
9595
ERRORS=$((ERRORS + 1))
9696
fi
@@ -105,35 +105,35 @@ while read local_ref local_sha remote_ref remote_sha; do
105105

106106
# Check for hardcoded user paths.
107107
if grep -E '(/Users/[^/\s]+/|/home/[^/\s]+/|C:\\Users\\[^\\]+\\)' "$file" 2>/dev/null | grep -q .; then
108-
echo "${RED}✗ BLOCKED: Hardcoded personal path found in: $file${NC}"
108+
echo -e "${RED}✗ BLOCKED: Hardcoded personal path found in: $file${NC}"
109109
grep -n -E '(/Users/[^/\s]+/|/home/[^/\s]+/|C:\\Users\\[^\\]+\\)' "$file" | head -3
110110
ERRORS=$((ERRORS + 1))
111111
fi
112112

113113
# Check for Socket API keys.
114114
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 'SOCKET_SECURITY_API_KEY=' | grep -v 'fake-token' | grep -v 'test-token' | grep -q .; then
115-
echo "${RED}✗ BLOCKED: Real API key detected in: $file${NC}"
115+
echo -e "${RED}✗ BLOCKED: Real API key detected in: $file${NC}"
116116
grep -n 'sktsec_' "$file" | grep -v "$ALLOWED_PUBLIC_KEY" | grep -v 'your_api_key_here' | grep -v 'fake-token' | grep -v 'test-token' | head -3
117117
ERRORS=$((ERRORS + 1))
118118
fi
119119

120120
# Check for AWS keys.
121121
if grep -iE '(aws_access_key|aws_secret|AKIA[0-9A-Z]{16})' "$file" 2>/dev/null | grep -q .; then
122-
echo "${RED}✗ BLOCKED: Potential AWS credentials found in: $file${NC}"
122+
echo -e "${RED}✗ BLOCKED: Potential AWS credentials found in: $file${NC}"
123123
grep -n -iE '(aws_access_key|aws_secret|AKIA[0-9A-Z]{16})' "$file" | head -3
124124
ERRORS=$((ERRORS + 1))
125125
fi
126126

127127
# Check for GitHub tokens.
128128
if grep -E 'gh[ps]_[a-zA-Z0-9]{36}' "$file" 2>/dev/null | grep -q .; then
129-
echo "${RED}✗ BLOCKED: Potential GitHub token found in: $file${NC}"
129+
echo -e "${RED}✗ BLOCKED: Potential GitHub token found in: $file${NC}"
130130
grep -n -E 'gh[ps]_[a-zA-Z0-9]{36}' "$file" | head -3
131131
ERRORS=$((ERRORS + 1))
132132
fi
133133

134134
# Check for private keys.
135135
if grep -E '-----BEGIN (RSA |EC |DSA )?PRIVATE KEY-----' "$file" 2>/dev/null | grep -q .; then
136-
echo "${RED}✗ BLOCKED: Private key found in: $file${NC}"
136+
echo -e "${RED}✗ BLOCKED: Private key found in: $file${NC}"
137137
ERRORS=$((ERRORS + 1))
138138
fi
139139
fi
@@ -145,10 +145,10 @@ done
145145

146146
if [ $TOTAL_ERRORS -gt 0 ]; then
147147
echo ""
148-
echo "${RED}✗ Push blocked by mandatory validation!${NC}"
148+
echo -e "${RED}✗ Push blocked by mandatory validation!${NC}"
149149
echo "Fix the issues above before pushing."
150150
exit 1
151151
fi
152152

153-
echo "${GREEN}✓ All mandatory validation passed!${NC}"
153+
echo -e "${GREEN}✓ All mandatory validation passed!${NC}"
154154
exit 0

0 commit comments

Comments
 (0)