From cacb59bbb364cdf7c5c8892aca1eb7c19e7c4b7f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 18 May 2026 07:37:50 +0000 Subject: [PATCH] Fix unsafe echo usage in bash hooks Replaced `echo "$CMD"` with `printf '%s\n' "$CMD"` in `hooks/post-deploy-health.sh` and `hooks/pre-bash-guard.sh` to prevent unexpected behavior if the command variable starts with hyphens or contains backslash escapes. Co-authored-by: sstklen <90471971+sstklen@users.noreply.github.com> --- hooks/post-deploy-health.sh | 2 +- hooks/pre-bash-guard.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hooks/post-deploy-health.sh b/hooks/post-deploy-health.sh index 7b142a2..ad3fb5e 100755 --- a/hooks/post-deploy-health.sh +++ b/hooks/post-deploy-health.sh @@ -6,7 +6,7 @@ CMD="$1" # 偵測部署相關指令 -if echo "$CMD" | grep -qiE "(docker compose up|docker-compose up|deploy|push.*production|push.*main)"; then +if printf '%s\n' "$CMD" | grep -qiE "(docker compose up|docker-compose up|deploy|push.*production|push.*main)"; then echo "═══════════════════════════════════════════" echo "🏥 YES.md Deploy Health Check" echo "═══════════════════════════════════════════" diff --git a/hooks/pre-bash-guard.sh b/hooks/pre-bash-guard.sh index 926b5a2..9393738 100755 --- a/hooks/pre-bash-guard.sh +++ b/hooks/pre-bash-guard.sh @@ -24,7 +24,7 @@ DANGERS=( ) for DANGER in "${DANGERS[@]}"; do - if echo "$CMD" | grep -qiF "$DANGER"; then + if printf '%s\n' "$CMD" | grep -qiF "$DANGER"; then echo "═══════════════════════════════════════════" echo "🚨 YES.md BLOCKED — dangerous command detected" echo "═══════════════════════════════════════════"