Repository navigation
Add an allow_fork_prs input to skip pull requests from forks - #2094
Conversation
Set to "false", the action skips pull requests from forks, and workflow_run events for a fork's run, before it checks anything out. The default keeps today's behavior. Co-authored-by: mhegazy <mhegazy@anthropic.com>
There was a problem hiding this comment.
Nothing blocking. The comments below are optional suggestions. There is no need to push a fix for them before merging.
Beyond the inline comment, I also checked three things and ruled them out:
- The skip after the comment lookup in
src/entrypoints/run.tsstill reaches thefinallyblock that sets thegithub_tokenoutput, so the revoke step inaction.ymlstill gets the app token. - A skipped fork run leaves a required check green.
docs/security.mdstates that as intended. - A mention on a closed or merged fork pull request gets no run. The same section says the skip applies whether the pull request is open or closed.
This changes which pull requests the action will act on, so a human look at the gating is still worthwhile.
Extended reasoning...
The change adds an allow_fork_prs input (default "true"), a new src/github/validation/fork-pr.ts module, two early returns in src/entrypoints/run.ts, and a second check in setupBranch, plus docs and tests (10 files, +453/-6). It touches the action's trust boundary: whether fork code is checked out, and where the fork check sits relative to token setup and the write-access check. The only finding is a nit about where a test lives, but the gating logic is security-sensitive and not a mechanical change, so this is a defer and not an approval. No CODEOWNERS file covers the changed paths, and the timeline shows no other reviewer objections.
Co-authored-by: mhegazy <mhegazy@anthropic.com>
There was a problem hiding this comment.
I reviewed the updated PR and found no bugs in this pass. Because it adds a security control that decides which pull requests the action runs on, and that runs ahead of the write-access check, a human look would still be worthwhile.
What was reviewed:
isRefusedForkEventandisCommentOnRefusedForkPragainst the event shapes insrc/github/context.ts:pull_request_targettakes thepull_requestpath, a null head repository counts as a fork, and a failedpulls.getthrows instead of letting the run continue.- Both early returns in
src/entrypoints/run.ts: thefinallyblock still sets thegithub_tokenoutput, so the App token revoke step inaction.ymlstill runs after the comment-path skip. - The new throw in
setupBranchsits only on the open-PR checkout path; closed and merged PRs branch from the base there and are skipped earlier inrun.ts. - One design point for a human to weigh: with
allow_fork_prs: "false", a fork's PR or review event returns success before the write-permission and trigger checks, so it logs a warning on every such event (including ones with no trigger phrase) and succeeds where a non-writer's run otherwise fails.
Extended reasoning...
The change adds an allow_fork_prs input wired through action.yml into a new src/github/validation/fork-pr.ts, two early returns in src/entrypoints/run.ts, and a defence-in-depth throw in src/github/operations/branch.ts, plus docs and about 300 lines of tests. It touches the action's trust boundary directly: which fork pull requests and workflow_run events get a token, a checkout and a session, and in what order that is decided relative to the write-permission check. No bugs were found, and the only commit since the earlier review is a one-line change to a test call. Deferring rather than approving because this is a new security-relevant control with design choices (skip-as-success, check ordering, documented gaps) that a maintainer should confirm; tests and typecheck were read, not run, in this review.
Human: @mhegazy
Requested by Mohamed · project thread
Adds an
allow_fork_prsinput. It is"true"by default, so nothing changes unless a workflow sets it.With
"false", the action skips a pull request whose branch is in another repository or in a deleted fork, whoever opened it and whatever event started the run, before it checks anything out. It also skipsworkflow_runevents for a fork's run. Any value other thantruecounts as off, including an empty one.How it works
pull_request,pull_request_target, reviews, review comments,workflow_run), the action decides before it asks for a token.pull-requests: read.docs/security.mdsays what the input doesn't cover: other steps in the workflow, events that don't name a pull request, commands in a session, and a fork's commits that are already in the repository.Testing
bun test(1413 pass),tsc --noEmit,prettier --checkand the workflow hardening check on Linux, with@octokit/rest22.0.1 in place of the locked 21.1.1. Two tests startrun.tsand fail if either check is taken out.pull_request_target,workflow_runand agent mode, with a fork, a deleted fork, a writer's own fork and a branch in the repository, with the inputtrue,falseand empty, and with a failing lookup.Generated by Claude Code