fix(ci): use pull_request_target in readme-pr-check so fork PRs work#3840
Conversation
The README PR Check workflow triggers on 'pull_request', which gives the
GITHUB_TOKEN read-only permissions when the PR comes from a fork. This
caused every fork PR (the vast majority) to fail with:
HttpError: Resource not accessible by integration (403)
POST /repos/.../issues/{n}/labels
Switch to 'pull_request_target' so the workflow runs in the base repo
context with the permissions declared in the job. This is safe here
because the workflow never checks out PR code — it only calls the GitHub
REST/GraphQL API to add a label and post a comment.
Also add 'issues: write' alongside 'pull-requests: write' since
addLabels/createComment use the issues endpoint internally.
|
@claude review |
|
Claude finished @cliffhall's task in 1m 25s —— View job PR Review
Summary: This is a correct, minimal, and well-reasoned fix. The diagnosis, solution, and security justification are all sound. Here's a detailed breakdown: What changed (4 lines)
Root cause analysis ✅The diagnosis is correct. GitHub's documented security model grants the Security assessment ✅ Safe
The entire script body only calls the GitHub REST/GraphQL API:
No Permission additions ✅ CorrectAdding Minor observations (not blockers)
VerdictApprove. The fix is correct, the minimal diff is appropriate, and the |
Summary
The
README PR Checkworkflow is currently failing on every PR opened from a fork (which is the vast majority of contributions to this repo). Example failed runs from the last couple of days: #24010860831, #24010684932, #24007350839, #24003674827, and many more — the full list on the workflow page shows the pattern: anything from a fork is red, only the one internal-branch run is green.All of them fail the same way:
Root cause
The workflow triggers on
pull_request. When apull_requestevent comes from a fork, theGITHUB_TOKENis read-only regardless of thepermissions:block in the job — that is the documented GitHub Actions security model. SoaddLabels/createCommentcan never succeed for the 99% case this workflow was written for.Fix
pull_request_target. This runs the workflow in the context of the base repo, so thepermissions:block is actually honored and the token can write labels/comments.issues: writenext topull-requests: write, sinceaddLabelsandcreateCommentboth hit the/issues/endpoint (the 403 response header even tells us:x-accepted-github-permissions: issues=write; pull_requests=write).if:guard oncheck-readme-onlyto match the new event name.Why
pull_request_targetis safe herepull_request_targetis normally dangerous because it runs with write privileges againstgithub.event.pull_request.head.ref— i.e. attacker-controlled code. This workflow never does acheckoutand never executes anything from the PR. It only callsoctokit(pulls.listFiles,issues.addLabels,issues.createComment) which read metadata and write labels/comments. There is no code-execution surface from the fork.Test plan
README.mdgets labeledreadme: pendingand commented instead of erroring/i-promise-this-is-not-a-new-serverstill swaps labels correctly (thehandle-confirmationjob was already fine — it runs onissue_commentwhich doesn't have the fork-token problem — but I addedissues: writethere too for consistency since it callsaddLabels/removeLabel)files.length !== 1 || files[0].filename !== 'README.md'check is unchanged)