fix: use pull_request_target for agentic CI on fork PRs#541
fix: use pull_request_target for agentic CI on fork PRs#541andreatgretel wants to merge 5 commits intomainfrom
Conversation
Greptile SummaryThis PR switches the agentic CI review workflow trigger from
|
| Filename | Overview |
|---|---|
| .github/workflows/agentic-ci-pr-review.yml | Switches trigger from pull_request to pull_request_target and adds environment: agentic-ci; introduces fork code checkout while secrets are in scope — safe only if the agentic-ci environment with required reviewers is configured before first run. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["pull_request_target event\n(opened / ready_for_review / labeled)"] --> B["gate job\n(GITHUB_TOKEN only, no secrets)"]
B --> C{Write access check}
C -- "allowed=false" --> D[Skip — exit 0]
C -- "allowed=true" --> E["review job\n(environment: agentic-ci)"]
E --> F["⏸ Environment gate\n(required reviewers approve)"]
F --> G["Checkout fork SHA\n⚠️ secrets now in scope"]
G --> H["Checkout base-branch recipes\n(SECURITY: untrusted prompt prevention)"]
H --> I["Run claude review\n(recipe from base branch only)"]
I --> J["Post review comment\ngh pr comment"]
J --> K["Remove agent-review label"]
Comments Outside Diff (1)
-
.github/workflows/agentic-ci-pr-review.yml, line 139-143 (link)Fork code checkout with secrets in scope
With
pull_request_target, repository secrets and a write-scopedGITHUB_TOKENare available throughout thereviewjob. This step checks out the fork's untrusted SHA (steps.head.outputs.sharesolves togithub.event.pull_request.head.sha) while those secrets are already accessible — the exact pattern GitHub's own security advisory flags.The
environment: agentic-cirequired-reviewers gate is the critical mitigation here: it blocks all steps (and thus this checkout) until a designated reviewer explicitly approves. If that environment does not exist in repo settings before the firstpull_request_targetrun is triggered, the gate silently becomes a no-op and secrets are in scope for any write-access contributor's fork checkout. Ensure theagentic-cienvironment with required reviewers is created in GitHub repo settings before or at the same time this workflow goes live.Prompt To Fix With AI
This is a comment left during a code review. Path: .github/workflows/agentic-ci-pr-review.yml Line: 139-143 Comment: **Fork code checkout with secrets in scope** With `pull_request_target`, repository secrets and a write-scoped `GITHUB_TOKEN` are available throughout the `review` job. This step checks out the fork's untrusted SHA (`steps.head.outputs.sha` resolves to `github.event.pull_request.head.sha`) while those secrets are already accessible — the exact pattern [GitHub's own security advisory](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) flags. The `environment: agentic-ci` required-reviewers gate is the critical mitigation here: it blocks all steps (and thus this checkout) until a designated reviewer explicitly approves. If that environment does not exist in repo settings **before** the first `pull_request_target` run is triggered, the gate silently becomes a no-op and secrets are in scope for any write-access contributor's fork checkout. Ensure the `agentic-ci` environment with required reviewers is created in GitHub repo settings before or at the same time this workflow goes live. How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: .github/workflows/agentic-ci-pr-review.yml
Line: 139-143
Comment:
**Fork code checkout with secrets in scope**
With `pull_request_target`, repository secrets and a write-scoped `GITHUB_TOKEN` are available throughout the `review` job. This step checks out the fork's untrusted SHA (`steps.head.outputs.sha` resolves to `github.event.pull_request.head.sha`) while those secrets are already accessible — the exact pattern [GitHub's own security advisory](https://securitylab.github.com/research/github-actions-preventing-pwn-requests/) flags.
The `environment: agentic-ci` required-reviewers gate is the critical mitigation here: it blocks all steps (and thus this checkout) until a designated reviewer explicitly approves. If that environment does not exist in repo settings **before** the first `pull_request_target` run is triggered, the gate silently becomes a no-op and secrets are in scope for any write-access contributor's fork checkout. Ensure the `agentic-ci` environment with required reviewers is created in GitHub repo settings before or at the same time this workflow goes live.
How can I resolve this? If you propose a fix, please make it concise.Reviews (3): Last reviewed commit: "fix: move expression interpolations to e..." | Re-trigger Greptile
Recipe files define the agent's prompt. When using pull_request_target, the fork's HEAD is checked out, so a malicious fork could craft recipe files to exfiltrate API secrets via prompt injection. Fix by adding a second sparse checkout from the base branch for .agents/recipes/ and reading prompts from there instead of the fork tree.
Match the base-branch recipe checkout to v6.0.2 (same SHA as the PR branch checkout) for consistency.
Replace direct ${{ }} interpolation in run: blocks with env vars.
Most values are GitHub-controlled, but github.event.label.name can
contain arbitrary characters and could break shell quoting. Moving
everything to env: is consistent with the injection-hardening pattern
applied in the rest of the workflow.
Code Review: PR #541 — fix: use
|
Summary
The agentic CI review workflow doesn't work on fork PRs. Discovered on #526: the
pull_requesttrigger requires manual approval in the Actions tab (not on the PR) for each fork workflow run, and fork PR runs don't have access to repo secrets/variables so the job fails at theAGENTIC_CI_MODELcheck even after approval.Switching to
pull_request_targetfixes both since the workflow definition comes frommain, so GitHub skips the fork approval gate and base repo secrets/variables are available.Changes
Changed
pull_requesttopull_request_targetso fork PRs get secret access without per-run Actions tab approvalenvironment: agentic-cito thereviewjob for an explicit approval gate on the PR checks UIFixed
.agents/recipes/) are now checked out from the base branch intobase-recipes/, so fork PRs cannot tamper with the agent's prompt while API secrets are in scope (agentic-ci-pr-review.yml#L132-L140)${{ }}interpolations inrun:blocks moved toenv:blocks to eliminate shell injection surface from event payload valuesAttention Areas
agentic-ci-pr-review.yml- Only file changed. Security model: gate job checks collaborator permissions,agentic-cienvironment requires reviewer approval, recipe files come from base branch (not fork), no direct${{ }}interpolation in shellDescription updated with AI