Skip to content

Commit 3c60481

Browse files
CI: Use pull_request_target for PR approval check (#4615)
The PR approval check workflow uses `pull_request`, which does not grant the `GITHUB_TOKEN` write permissions for commit statuses on fork PRs. This causes the check to silently fail on external contributions. Switches to `pull_request_target`, which runs in the context of the base branch and has the necessary permissions. **Security notes** (also documented as comments in the workflow file): - `pull_request_target` grants write access to the repository. This is safe here because the workflow **only reads PR metadata via the GitHub API** and never checks out, builds, or executes code from the PR branch. - A clear `SECURITY` comment block at the top of the file explains why `pull_request_target` is used and warns against adding a checkout step. - An additional inline comment on the job warns against adding checkout steps. Co-authored-by: clockwork-labs-bot <clockwork-labs-bot@users.noreply.github.com>
1 parent 4d7db10 commit 3c60481

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

.github/workflows/pr_approval_check.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
name: Review Checks
22

3+
# SECURITY: This workflow uses pull_request_target so that it has write access to
4+
# set commit statuses on external (fork) PRs. pull_request_target runs in the
5+
# context of the base branch, which grants the GITHUB_TOKEN write permissions
6+
# that a regular pull_request event on a fork would not have.
7+
#
8+
# IMPORTANT: This workflow must NEVER check out, build, or execute code from the
9+
# PR branch. Doing so would allow a malicious fork to run arbitrary code with
10+
# write access to the repository. This workflow only reads PR metadata via the
11+
# GitHub API, which is safe.
12+
313
on:
4-
pull_request:
14+
pull_request_target:
515
types: [opened, synchronize, reopened]
616
pull_request_review:
717
types: [submitted, dismissed]
@@ -21,6 +31,7 @@ jobs:
2131
name: Set approval status
2232
runs-on: ubuntu-latest
2333

34+
# SECURITY: Do not add a checkout step to this job. See comment at the top of this file.
2435
steps:
2536
- name: Evaluate and publish approval status
2637
uses: actions/github-script@v7

0 commit comments

Comments
 (0)