處理 AI review findings 並改寫 Node.js entrypoint #1
@@ -15,6 +15,8 @@ inputs:
|
||||
outputs:
|
||||
status:
|
||||
description: 'Execution result status'
|
||||
|
Ghost marked this conversation as resolved
|
||||
output:
|
||||
description: 'Codex execution output'
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
|
||||
@@ -33,10 +33,30 @@ mv "$auth_file" "$CODEX_HOME/auth.json"
|
||||
chmod 600 "$CODEX_HOME/auth.json"
|
||||
trap - EXIT
|
||||
|
||||
|
Ghost marked this conversation as resolved
gitea-actions
commented
嚴重等級:🟡 警告 **嚴重等級**:🟡 警告
**審查員**:Mage
**問題**:使用 `mkdir` 作為鎖定機制若容器意外崩潰可能殘留鎖檔。
**建議**:考慮使用更穩健的 `flock` 機制來管理檔案鎖並確保自動清理。
|
||||
codex_output="$(mktemp)"
|
||||
trap 'rm -f "$codex_output"' EXIT
|
||||
|
||||
set +e
|
||||
codex exec \
|
||||
--model "$MODEL" \
|
||||
"$PROMPT"
|
||||
"$PROMPT" 2>&1 | tee "$codex_output"
|
||||
|
Ghost marked this conversation as resolved
gitea-actions
commented
嚴重等級:🟡 警告 **嚴重等級**:🟡 警告
**審查員**:Mage
**問題**:使用 `install -m 600` 將 `auth_file` 移至 `auth_path`。若 `mktemp` 產生的 `auth_file` 與 `auth_path` 不在同一個檔案系統分區(Filesystem),`install` 指令(底層通常是 copy + chmod/chown)可能會有短暫時間檔案權限為預設值,存在權限外洩風險。
**建議**:建議在確認檔案權限無誤後,於同一分區內使用 `mv` 進行原子性移轉,或在寫入前先明確設定 `umask`。
|
||||
codex_status="${PIPESTATUS[0]}"
|
||||
set -e
|
||||
|
||||
|
Ghost marked this conversation as resolved
gitea-actions
commented
嚴重等級:🟡 警告 **嚴重等級**:🟡 警告
**審查員**:Bard
**問題**:使用靜態路徑檢查 `auth.json` 是否存在,若前次執行中斷導致檔案未清除,會導致後續執行失敗(Self-inflicted DoS)。
**建議**:移除對既有檔案的檢查,改為在執行前確保該檔案為最新且受控狀態,或使用唯一的隨機臨時檔。
|
||||
if [[ -n "${GITHUB_OUTPUT:-}" ]]; then
|
||||
output_delimiter="CODEX_OUTPUT_$(date +%s)_$$"
|
||||
|
||||
if [[ "$codex_status" -eq 0 ]]; then
|
||||
|
Ghost marked this conversation as resolved
gitea-actions
commented
嚴重等級:🔴 嚴重 **嚴重等級**:🔴 嚴重
**審查員**:Mage
**問題**:在執行 install -m 600 時,若 codex 進程已經在嘗試讀取 auth.json,會發生檔案存取競態(Race Condition)。雖然使用了 flock,但這僅在同一個 shell 腳本實例中有效,無法保護跨容器或跨執行環境的檔案存取一致性。
**建議**:建議將 auth.json 放置於唯讀且受限的目錄中,並通過環境變數直接傳遞路徑給 codex,而非在執行時進行檔案寫入與複製。
|
||||
echo "status=completed" >> "$GITHUB_OUTPUT"
|
||||
else
|
||||
echo "status=failed" >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
{
|
||||
echo "output<<$output_delimiter"
|
||||
cat "$codex_output"
|
||||
echo "$output_delimiter"
|
||||
|
Ghost marked this conversation as resolved
gitea-actions
commented
嚴重等級:🟡 警告 **嚴重等級**:🟡 警告
**審查員**:Mage
**問題**:在容器化環境(通常是 ephemeral 的)中,auth.json 寫入後立刻被刪除,這會導致 codex 在後續執行中因找不到驗證檔案而無法運作。另外,trap 的清理機制會導致該檔案在 codex 完成工作前被刪除,這對於長效執行或需要多次存取的應用場景是錯誤的設計。
**建議**:評估 codex 是否需要該檔案在執行期間持續存在。若需要,請調整清理時機,或考慮使用記憶體中的臨時檔案系統(tmpfs)來提升安全性,而非直接移除檔案。
|
||||
} >> "$GITHUB_OUTPUT"
|
||||
fi
|
||||
|
||||
exit "$codex_status"
|
||||
|
||||
嚴重等級:🟡 警告
審查員:Bard
問題:輸出欄位命名為
text,但賦值內容為「執行狀態(status)」,語義不符。建議:將欄位名稱改為
status,以保持命名與意圖一致。