Skip to content

Add an allow_fork_prs input to skip pull requests from forks - #2094

Merged
mhegazy merged 2 commits into
mainfrom
claude/allow-fork-prs
Nov 18, 2026
Merged

mhegazy merged 2 commits into
mainfrom
claude/allow-fork-prs

Conversation

@mhegazy

@mhegazy mhegazy commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Human: @mhegazy

Requested by Mohamed · project thread

Adds an allow_fork_prs input. 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 skips workflow_run events for a fork's run. Any value other than true counts as off, including an empty one.

How it works

  • Where the event says which repository the branch is in (pull_request, pull_request_target, reviews, review comments, workflow_run), the action decides before it asks for a token.
  • The event for a comment on the conversation doesn't say, so the action looks the pull request up, after the write access and trigger checks. If that fails, so does the run. The token needs pull-requests: read.
  • A skipped run logs a warning and succeeds without Claude's outputs, so a required check that only runs the action passes.
  • Tag mode's checkout refuses a fork too, as a second check.

docs/security.md says 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 --check and the workflow hardening check on Linux, with @octokit/rest 22.0.1 in place of the locked 21.1.1. Two tests start run.ts and fail if either check is taken out.
  • The whole action with CLI 2.1.326, mock GitHub and a scripted model: comments, reviews, review comments, pull_request_target, workflow_run and agent mode, with a fork, a deleted fork, a writer's own fork and a branch in the repository, with the input true, false and empty, and with a failing lookup.
  • Not run: a GitHub runner, a real model, GitHub Enterprise Server, macOS and Windows.

Generated by Claude Code

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>
@mhegazy mhegazy self-assigned this Nov 17, 2026

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.ts still reaches the finally block that sets the github_token output, so the revoke step in action.yml still gets the app token.
  • A skipped fork run leaves a required check green. docs/security.md states 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.

Comment thread test/fork-pr.test.ts Resolved
Co-authored-by: mhegazy <mhegazy@anthropic.com>
@mhegazy
mhegazy enabled auto-merge (squash) November 17, 2026 23:03

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • isRefusedForkEvent and isCommentOnRefusedForkPr against the event shapes in src/github/context.ts: pull_request_target takes the pull_request path, a null head repository counts as a fork, and a failed pulls.get throws instead of letting the run continue.
  • Both early returns in src/entrypoints/run.ts: the finally block still sets the github_token output, so the App token revoke step in action.yml still runs after the comment-path skip.
  • The new throw in setupBranch sits only on the open-PR checkout path; closed and merged PRs branch from the base there and are skipped earlier in run.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.

@mhegazy
mhegazy merged commit e5812cd into main Nov 18, 2026
40 checks passed
@mhegazy
mhegazy deleted the claude/allow-fork-prs branch November 18, 2026 00:09
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