Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

ci: run AI review via pull_request_target so it works on fork PRs (#4958)

LearningCircuit8c5a4e0e4286
diff --git a/.github/workflows/ai-code-reviewer.yml b/.github/workflows/ai-code-reviewer.yml
index d43860b821..b16d46663c 100644
--- a/.github/workflows/ai-code-reviewer.yml
+++ b/.github/workflows/ai-code-reviewer.yml
@@ -6,8 +6,27 @@ name: AI Code Reviewer
# reviewing every push burned reviewer-API spend on PRs nobody asked to have
# reviewed, and a billing outage (HTTP 402) then showed a red check on every
# PR in the repo.
+#
+# Residual risk accepted: the diff text goes into the LLM prompt, so a
+# hostile diff can try to steer the posted comment or labels (prompt
+# injection). The maintainer-applied label gate plus the advisory-only
+# decision (FAIL_ON_REQUESTED_CHANGES defaults to false) bound that
+# blast radius, and it exists for internal PRs too.
+
on:
- pull_request:
+ # zizmor: ignore[dangerous-triggers] — pull_request_target is required so
+ # the review also works on fork PRs: fork-triggered pull_request runs get
+ # no secrets (OPENROUTER_API_KEY) and a read-only token, so the reviewer
+ # could neither call the model nor post its comment. This is safe under
+ # two invariants — KEEP BOTH when editing this file:
+ # 1. Only the ai_code_review label triggers a run, and only users with
+ # triage permission can add labels: every run on fork code is an
+ # explicit maintainer action, never attacker-initiated.
+ # 2. Nothing from the PR head is ever executed. The checkout is the
+ # trusted base branch (pull_request_target default), so
+ # .github/scripts/combine-ai-reviews.sh runs from base; the PR head
+ # is fetched as *data only* to compute the diff.
+ pull_request_target:
types: [labeled]
# Per-PR concurrency with cancel-in-progress: re-adding the label while a
@@ -51,6 +70,11 @@ jobs:
with:
egress-policy: audit
+ # SECURITY: this checks out the trusted BASE branch (the
+ # pull_request_target default), which is what makes running
+ # .github/scripts/combine-ai-reviews.sh below safe on fork PRs.
+ # Never add `ref: ${{ github.event.pull_request.head.sha }}` here —
+ # that would execute fork-controlled scripts with secrets in env.
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
@@ -65,11 +89,15 @@ jobs:
- name: Get PR diff
env:
BASE_REF: ${{ github.event.pull_request.base.ref }}
+ PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
- # Fetch the base branch (works for any target branch, not just main)
- # Use env var to prevent template injection from malicious branch names
- git fetch origin "$BASE_REF"
- git diff "origin/$BASE_REF...HEAD" --no-color > diff.txt
+ # The PR head — possibly fork code — is fetched as *data only*
+ # through the base repo's refs/pull/N/head mirror (present for
+ # fork and same-repo PRs alike); it is never checked out and
+ # nothing from it is executed. Env vars prevent template
+ # injection from malicious branch names.
+ git fetch origin "$BASE_REF" "+refs/pull/$PR_NUMBER/head:refs/remotes/origin/pr-head"
+ git diff "origin/$BASE_REF...origin/pr-head" --no-color > diff.txt
- name: Download AI reviewer script
run: |