Skip to content

fix(ci): make AI review safe + functional on fork PRs#6087

Merged
jam-jee merged 1 commit into
aws:masterfrom
jam-jee:fix-ai-review-fork-checkout
Jul 23, 2026
Merged

fix(ci): make AI review safe + functional on fork PRs#6087
jam-jee merged 1 commit into
aws:masterfrom
jam-jee:fix-ai-review-fork-checkout

Conversation

@jam-jee

@jam-jee jam-jee commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Problem

The AI Code Review workflow (added in #6053) fails on every fork PR — which is ~90% of PRs to this repo. Example: run 29965762436 on #6083 failed at checkout with:

Refusing to check out fork pull request code from a 'pull_request_target' workflow

The review job runs under pull_request_target (trusted context — it holds the Bedrock role and secrets) but was checking out the fork's head SHA. actions/checkout blocks that by default because executing untrusted fork code in a trusted context is a vulnerability.

Fix — safe diff-only review

Rather than opt into the unsafe checkout, this reworks the job so untrusted PR code is never executed in the privileged context (mirrors the pattern in AWS's own *-agentcore pr-security-review.yml):

  • Check out the BASE repo (base.sha), not the fork head. The trusted tree is used only for read-only context.
  • Fetch the PR diff via the API into /tmp/pr.diff — data, not executable code.
  • Remove Bash from allowedTools. Claude reads the diff and uses Read/Grep/Glob against the base tree; it cannot run commands or re-run git.
  • Skip cleanly when the diff is empty.

Explicitly does not use allow-unsafe-pr-checkout: true, which would expose secrets/the Bedrock role to fork-controlled code.

Result

  • ✅ Works on fork PRs (the common case)
  • ✅ No pwn-request exposure
  • ✅ Same review quality — Claude still gets the full diff + repo context for accurate inline comments

The review job runs under pull_request_target (trusted context with the
Bedrock role + secrets). It was checking out the fork's head SHA, which
actions/checkout now refuses ('pwn request' guard) — so the workflow failed on
every fork PR (~90% of PRs), e.g. run 29965762436 on aws#6083.

Rework to the safe diff-only pattern (mirrors aws/*-agentcore pr-security-review):
- Check out the BASE repo, never fork head code — untrusted PR code is never
  executed in the privileged job.
- Fetch the PR diff via the API into /tmp/pr.diff as read-only ground truth.
- Remove Bash from allowedTools; Claude reads the diff + uses Read/Grep/Glob
  against the trusted base tree for context. Skip cleanly on empty diffs.

Does NOT use allow-unsafe-pr-checkout, which would expose secrets to fork code.
@jam-jee
jam-jee merged commit 6455d2d into aws:master Jul 23, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants