From f1206e46c732c7bc06091df34c7e32492b276402 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Sat, 16 May 2026 15:19:00 +0000 Subject: [PATCH] triage: handle review findings --- .gitea/ai-review/exclusions.json | 12 ++++++++++++ .gitea/ai-review/findings.json | 24 +----------------------- entrypoint.sh | 9 ++++++++- 3 files changed, 21 insertions(+), 24 deletions(-) diff --git a/.gitea/ai-review/exclusions.json b/.gitea/ai-review/exclusions.json index 7308d99..6a52d8b 100644 --- a/.gitea/ai-review/exclusions.json +++ b/.gitea/ai-review/exclusions.json @@ -17,12 +17,24 @@ "location": "Dockerfile:10", "suggestion": "Dockerfile 中複製了 `rootCA.pem` 和 `jsc.idv.me+4.pem` 到容器中。請確保這些檔案僅包含公開的憑證資料,不包含任何私鑰或其他敏感資訊。若這些檔案包含私鑰,則會構成嚴重的安全漏洞。建議在 CI/CD 流程中增加檢查,確保這些檔案的內容符合預期。" }, + { + "level": "warning", + "role": "Leo", + "location": "entrypoint.sh", + "suggestion": "建議在檔案末尾添加一個空行。這是一個常見的 Unix 慣例,可以避免某些工具在處理檔案時產生非預期的行為。" + }, { "level": "warning", "role": "Aria", "location": "Dockerfile:15", "suggestion": "檔案末尾應包含一個空行,以符合 POSIX 規範並避免某些工具處理時產生問題。" }, + { + "level": "info", + "role": "Rex", + "location": "entrypoint.sh:70", + "suggestion": "將變數寫入 `$GITHUB_OUTPUT` 時,雖然此處 `status_code` 為數字,風險較低,但一般而言,應確保寫入的內容經過適當的清理或編碼,以防止潛在的命令注入風險。如果變數內容來自不受信任的輸入或包含特殊字元(例如換行符),可能會被 GitHub Actions 解釋為新的輸出變數或指令。" + }, { "level": "info", "role": "Leo", diff --git a/.gitea/ai-review/findings.json b/.gitea/ai-review/findings.json index 4610c32..fe51488 100644 --- a/.gitea/ai-review/findings.json +++ b/.gitea/ai-review/findings.json @@ -1,23 +1 @@ -[ - { - "level": "critical", - "role": "Rex", - "location": "entrypoint.sh:44", - "suggestion": "`CHECK_URL` 變數直接用於 `curl` 命令,存在伺服器端請求偽造 (SSRF) 的風險。如果攻擊者能控制 `CHECK_URL`,他們可能利用 `curl` 訪問內部網路資源、讀取本地檔案(例如 `file:///etc/passwd`)或與其他服務互動。請對 `CHECK_URL` 進行嚴格的輸入驗證,確保它只包含預期的協定(如 `http` 或 `https`)和有效的網域名稱格式。可以考慮使用正規表達式來驗證 URL,並限制 `curl` 允許的協定(例如使用 `--proto` 選項)。", - "is_new": true - }, - { - "level": "warning", - "role": "Leo", - "location": "entrypoint.sh", - "suggestion": "建議在檔案末尾添加一個空行。這是一個常見的 Unix 慣例,可以避免某些工具在處理檔案時產生非預期的行為。", - "is_new": true - }, - { - "level": "info", - "role": "Rex", - "location": "entrypoint.sh:70", - "suggestion": "將變數寫入 `$GITHUB_OUTPUT` 時,雖然此處 `status_code` 為數字,風險較低,但一般而言,應確保寫入的內容經過適當的清理或編碼,以防止潛在的命令注入風險。如果變數內容來自不受信任的輸入或包含特殊字元(例如換行符),可能會被 GitHub Actions 解釋為新的輸出變數或指令。", - "is_new": true - } -] +[] diff --git a/entrypoint.sh b/entrypoint.sh index efcb439..d4ed871 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -39,6 +39,13 @@ if [ -z "$HEALTH_CODE" ] || [ "$HEALTH_CODE" = "null" ]; then fail "HEALTH_CODE 不可為空。" fi +case "$CHECK_URL" in + http://*|https://*) ;; + *) + fail "CHECK_URL 只允許 http:// 或 https://。" + ;; +esac + log "[INFO] CHECK_URL=$CHECK_URL" log "[INFO] HEALTH_CODE=$HEALTH_CODE" @@ -48,7 +55,7 @@ log "[INFO] 開始檢查:$CHECK_URL" while true; do printf '[%s] [INFO] GET %s ... ' "$(timestamp)" "$CHECK_URL" - status_code="$(curl -sS --max-time 60 --url "$CHECK_URL" -o /dev/null -w '%{http_code}' || true)" + status_code="$(curl -sS --proto '=http,https' --proto-redir '=http,https' --max-time 60 --url "$CHECK_URL" -o /dev/null -w '%{http_code}' || true)" if [ -z "$status_code" ]; then status_code="000" fi