Skip to content

idd-all Phase 0.5: fork detection 改 fail-closed (gh repo view 失敗時預設 PR mode) #5

Description

@kiki830621

Problem

From verification of #1 (P3 finding 15 — security reviewer):
Phase 0.5 fork detection 用:

IS_FORK=$(gh repo view "$GITHUB_REPO" --json isFork -q .isFork 2>/dev/null || echo "false")

這是 fail-open:gh repo view 失敗時(網路不通、auth 過期、API rate limit)IS_FORK 被設為 "false",違反 spec scenario「fork forces PR path regardless of config」。

結果: 真的在 fork 上 + gh repo view 暫時失敗 + pr_policy: never → 落到 direct-commit,user 無法 push 到 upstream,但 mode resolution 沒提示為什麼。

Type

fix / security defensive

Why P3 not P1

需要三個 condition 同時成立 (fork + gh failure + pr_policy=never) 才會 trigger,但發生時 user 經驗很差。

Recommendation

改 fail-closed (錯時預設 PR mode,因為 PR 是更保守選擇 — 至少 user 會看到明確錯誤而不是 silent direct-commit):

IS_FORK_OUTPUT=$(gh repo view "$GITHUB_REPO" --json isFork -q .isFork 2>&1)
GH_EXIT=$?

if [ $GH_EXIT -ne 0 ]; then
  echo "⚠ Could not query fork status (gh exit $GH_EXIT): $IS_FORK_OUTPUT"
  echo "  Defaulting to PR mode for safety. Pass --no-pr to override."
  IS_FORK="true"  # fail-closed
else
  IS_FORK="$IS_FORK_OUTPUT"
fi

或 abort 比 fall-through 還清楚:

abort "Could not determine if $GITHUB_REPO is a fork. Re-auth gh or pass --pr/--no-pr explicitly."

Source

Related: #1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions