@@ -38,23 +38,23 @@ stdin_data=$(cat)
3838# Extract tool_name and file_path using sed (no jq dependency)
3939tool_name=$(echo "$stdin_data" | sed -n 's/.*"tool_name":"\([^"]*\)".*/\1/p' | head -1)
4040
41- if [ "$tool_name" != "Read" ]; then
41+ if [[ "$tool_name" != "Read" ] ]; then
4242 exit 0
4343fi
4444
4545# Extract file_path from tool_input
4646file_path=$(echo "$stdin_data" | sed -n 's/.*"tool_input":\s*{\([^}]*\)}.*/\1/p' | \
4747 sed -n 's/.*"file_path":"\([^"]*\)".*/\1/p' | head -1)
4848
49- if [ -z "$file_path" ] || [ ! -f "$file_path" ]; then
49+ if [[ -z "$file_path" ]] || [[ ! -f "$file_path" ] ]; then
5050 exit 0
5151fi
5252
5353# Scan file for secrets
5454sonar analyze --file "$file_path" > /dev/null 2>&1
5555exit_code=$?
5656
57- if [ $exit_code -eq 51 ]; then
57+ if [[ $exit_code -eq 51 ] ]; then
5858 # Secrets found - deny file read
5959 reason="Sonar detected secrets in file: $file_path"
6060 echo "{\"hookSpecificOutput\":{\"hookEventName\":\"PreToolUse\",\"permissionDecision\":\"deny\",\"permissionDecisionReason\":\"$reason\"}}"
@@ -131,7 +131,7 @@ stdin_data=$(cat)
131131# Extract prompt field using sed
132132prompt=$(echo "$stdin_data" | sed -n 's/.*"prompt":"\([^"]*\)".*/\1/p' | head -1)
133133
134- if [ -z "$prompt" ]; then
134+ if [[ -z "$prompt" ] ]; then
135135 exit 0
136136fi
137137
@@ -145,7 +145,7 @@ echo -n "$prompt" > "$temp_file"
145145sonar analyze --file "$temp_file" > /dev/null 2>&1
146146exit_code=$?
147147
148- if [ $exit_code -eq 51 ]; then
148+ if [[ $exit_code -eq 51 ] ]; then
149149 # Secrets found - block prompt
150150 reason="Sonar detected secrets in prompt"
151151 echo "{\"decision\":\"block\",\"reason\":\"$reason\"}"
0 commit comments