Skip to content

Commit 07c23b7

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 51463ea commit 07c23b7

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

.git-hooks/commit-msg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ if [ -n "$COMMITTED_FILES" ]; then
2323
if [ -f "$file" ]; then
2424
# Check for Socket API keys (except allowed).
2525
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}"
26+
printf "${RED}✗ SECURITY: Potential API key detected in commit!${NC}\n"
2727
echo "File: $file"
2828
ERRORS=$((ERRORS + 1))
2929
fi
3030

3131
# Check for .env files.
3232
if echo "$file" | grep -qE '^\.env(\.local)?$'; then
33-
echo "${RED}✗ SECURITY: .env file in commit!${NC}"
33+
printf "${RED}✗ SECURITY: .env file in commit!${NC}\n"
3434
ERRORS=$((ERRORS + 1))
3535
fi
3636
fi
@@ -58,15 +58,15 @@ if [ -f "$COMMIT_MSG_FILE" ]; then
5858
# Replace the original commit message with the cleaned version.
5959
if [ $REMOVED_LINES -gt 0 ]; then
6060
mv "$TEMP_FILE" "$COMMIT_MSG_FILE"
61-
echo "${GREEN}✓ Auto-stripped${NC} $REMOVED_LINES AI attribution line(s) from commit message"
61+
printf "${GREEN}✓ Auto-stripped${NC} $REMOVED_LINES AI attribution line(s) from commit message\n"
6262
else
6363
# No lines were removed, just clean up the temp file.
6464
rm -f "$TEMP_FILE"
6565
fi
6666
fi
6767

6868
if [ $ERRORS -gt 0 ]; then
69-
echo "${RED}✗ Commit blocked by security validation${NC}"
69+
printf "${RED}✗ Commit blocked by security validation${NC}\n"
7070
exit 1
7171
fi
7272

.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+
printf "${GREEN}Running Socket Security checks...${NC}\n"
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+
printf "${GREEN}✓ No files to check${NC}\n"
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+
printf "${RED}✗ ERROR: .DS_Store file detected!${NC}\n"
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+
printf "${RED}✗ ERROR: Log file detected!${NC}\n"
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+
printf "${RED}✗ ERROR: .env or .env.local file detected!${NC}\n"
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+
printf "${RED}✗ ERROR: Hardcoded personal path found in: $file${NC}\n"
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+
printf "${YELLOW}⚠ WARNING: Potential API key found in: $file${NC}\n"
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+
printf "${RED}✗ ERROR: Potential AWS credentials found in: $file${NC}\n"
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+
printf "${RED}✗ ERROR: Potential GitHub token found in: $file${NC}\n"
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+
printf "${RED}✗ ERROR: Private key found in: $file${NC}\n"
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+
printf "${RED}✗ Security check failed with $ERRORS error(s).${NC}\n"
118118
echo "Fix the issues above and try again."
119119
exit 1
120120
fi
121121

122-
echo "${GREEN}✓ All security checks passed!${NC}"
122+
printf "${GREEN}✓ All security checks passed!${NC}\n"
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+
printf "${GREEN}Running mandatory pre-push validation...${NC}\n"
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+
printf "${RED}✗ BLOCKED: AI attribution found in commit messages!${NC}\n"
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+
printf "${RED}✗ BLOCKED: Attempting to push .env file!${NC}\n"
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+
printf "${RED}✗ BLOCKED: .DS_Store file in push!${NC}\n"
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+
printf "${RED}✗ BLOCKED: Log file in push!${NC}\n"
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+
printf "${RED}✗ BLOCKED: Hardcoded personal path found in: $file${NC}\n"
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+
printf "${RED}✗ BLOCKED: Real API key detected in: $file${NC}\n"
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+
printf "${RED}✗ BLOCKED: Potential AWS credentials found in: $file${NC}\n"
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+
printf "${RED}✗ BLOCKED: Potential GitHub token found in: $file${NC}\n"
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+
printf "${RED}✗ BLOCKED: Private key found in: $file${NC}\n"
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+
printf "${RED}✗ Push blocked by mandatory validation!${NC}\n"
149149
echo "Fix the issues above before pushing."
150150
exit 1
151151
fi
152152

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

.husky/security-checks.sh

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ NC='\033[0m'
1515
# NOTE: This value is intentionally identical across all Socket repos.
1616
ALLOWED_PUBLIC_KEY="sktsec_t_--RAN5U4ivauy4w37-6aoKyYPDt5ZbaT5JBVMqiwKo_api"
1717

18-
echo "${GREEN}Running Socket Security checks...${NC}"
18+
printf "${GREEN}Running Socket Security checks...${NC}\n"
1919

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

2323
if [ -z "$STAGED_FILES" ]; then
24-
echo "${GREEN}✓ No files to check${NC}"
24+
printf "${GREEN}✓ No files to check${NC}\n"
2525
exit 0
2626
fi
2727

@@ -30,23 +30,23 @@ ERRORS=0
3030
# Check for .DS_Store files.
3131
echo "Checking for .DS_Store files..."
3232
if echo "$STAGED_FILES" | grep -q '\.DS_Store'; then
33-
echo "${RED}✗ ERROR: .DS_Store file detected!${NC}"
33+
printf "${RED}✗ ERROR: .DS_Store file detected!${NC}\n"
3434
echo "$STAGED_FILES" | grep '\.DS_Store'
3535
ERRORS=$((ERRORS + 1))
3636
fi
3737

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

4646
# Check for .env files.
4747
echo "Checking for .env files..."
4848
if echo "$STAGED_FILES" | grep -E '^\.env(\.local)?$'; then
49-
echo "${RED}✗ ERROR: .env or .env.local file detected!${NC}"
49+
printf "${RED}✗ ERROR: .env or .env.local file detected!${NC}\n"
5050
echo "$STAGED_FILES" | grep -E '^\.env(\.local)?$'
5151
echo "These files should never be committed. Use .env.example instead."
5252
ERRORS=$((ERRORS + 1))
@@ -63,7 +63,7 @@ for file in $STAGED_FILES; do
6363

6464
# Check for common user path patterns.
6565
if grep -E '(/Users/[^/\s]+/|/home/[^/\s]+/|C:\\Users\\[^\\]+\\)' "$file" 2>/dev/null | grep -q .; then
66-
echo "${RED}✗ ERROR: Hardcoded personal path found in: $file${NC}"
66+
printf "${RED}✗ ERROR: Hardcoded personal path found in: $file${NC}\n"
6767
grep -n -E '(/Users/[^/\s]+/|/home/[^/\s]+/|C:\\Users\\[^\\]+\\)' "$file" | head -3
6868
echo "Replace with relative paths or environment variables."
6969
ERRORS=$((ERRORS + 1))
@@ -76,7 +76,7 @@ echo "Checking for API keys..."
7676
for file in $STAGED_FILES; do
7777
if [ -f "$file" ]; then
7878
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
79-
echo "${YELLOW}⚠ WARNING: Potential API key found in: $file${NC}"
79+
printf "${YELLOW}⚠ WARNING: Potential API key found in: $file${NC}\n"
8080
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
8181
echo "If this is a real API key, DO NOT COMMIT IT."
8282
fi
@@ -94,32 +94,32 @@ for file in $STAGED_FILES; do
9494

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

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

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

117117
if [ $ERRORS -gt 0 ]; then
118118
echo ""
119-
echo "${RED}✗ Security check failed with $ERRORS error(s).${NC}"
119+
printf "${RED}✗ Security check failed with $ERRORS error(s).${NC}\n"
120120
echo "Fix the issues above and try again."
121121
exit 1
122122
fi
123123

124-
echo "${GREEN}✓ All security checks passed!${NC}"
124+
printf "${GREEN}✓ All security checks passed!${NC}\n"
125125
exit 0

0 commit comments

Comments
 (0)