Skip to content

block checking out fork pr for pull_request_target and workflow_run#2454

Open
aiqiaoy wants to merge 3 commits into
mainfrom
enforce-safe-checkout
Open

block checking out fork pr for pull_request_target and workflow_run#2454
aiqiaoy wants to merge 3 commits into
mainfrom
enforce-safe-checkout

Conversation

@aiqiaoy

@aiqiaoy aiqiaoy commented Jun 12, 2026

Copy link
Copy Markdown

Implements https://github.com/github/c2c-actions/pull/10159

TL;DR; This PR adds a check that refuses to check out fork pull request code when the workflow trigger is either pull_request_target or workflow_run, unless the workflow author explicitly opts in via a new input allow-unsafe-pr-checkout: true.

Comment thread dist/index.js
// Determine the GitHub URL that the repository is being hosted from
result.githubServerUrl = core.getInput('github-server-url');
core.debug(`GitHub Host URL = ${result.githubServerUrl}`);
// Allow unsafe PR checkout (opt-in for pull_request_target / workflow_run fork PRs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can this apply to merge/head ref + issue_comment constructions by default as well?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks for the review, The risk of issue_comment is on our radar, however it will not be included in this change. This is because issue_comment event payload only has the PR number (no ref or sha), so we can't detect fork PR without an extra API call and issue_comment has a slightly different threat model (gated by who can comment rather than who can open a PR) that deserves its own design.

@aiqiaoy aiqiaoy marked this pull request as ready for review June 15, 2026 14:13
Copilot AI review requested due to automatic review settings June 15, 2026 14:13
@aiqiaoy aiqiaoy changed the title block checking out fork pr for some events block checking out fork pr for pull_request_target and workflow_run Jun 15, 2026

Copilot AI 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.

Pull request overview

Adds a guardrail to prevent accidentally checking out fork pull request code in privileged GitHub Actions contexts (pull_request_target and PR-triggered workflow_run), with an explicit opt-in escape hatch for advanced workflows.

Changes:

  • Introduces assertSafePrCheckout to detect and block unsafe fork-PR checkouts in privileged events unless allow-unsafe-pr-checkout is enabled.
  • Adds a new action input (allow-unsafe-pr-checkout) and threads it through input parsing and settings.
  • Updates documentation and adds test coverage for the new safety checks.
Show a summary per file
File Description
src/unsafe-pr-checkout-helper.ts New helper that blocks unsafe fork PR checkout patterns in privileged events unless opted in.
src/ref-helper.ts Exports fromPayload for reuse by the new safety helper.
src/input-helper.ts Parses allow-unsafe-pr-checkout and invokes the new safety assertion during input handling.
src/git-source-settings.ts Extends settings interface with allowUnsafePrCheckout.
README.md Documents the new input and its intent.
action.yml Adds the new input to the action metadata.
test/unsafe-pr-checkout-helper.test.ts New unit tests validating allow/refuse behavior across events and patterns.
test/input-helper.test.ts Asserts the new setting defaults to false.
test/git-auth-helper.test.ts Updates test settings object to include the new required field.
dist/index.js Bundled output updated to include the new logic.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 9/10 changed files
  • Comments generated: 4

Comment thread src/unsafe-pr-checkout-helper.ts
Comment thread src/unsafe-pr-checkout-helper.ts
Comment thread README.md
Comment on lines +164 to +166
# Required to check out fork pull request code from a workflow triggered by
# `pull_request_target` or `workflow_run`. See [Pwn Requests](todo:need-link) for
# the risks. Set to `true` only after reviewing the risks.
Comment thread action.yml
Comment on lines +101 to +106
allow-unsafe-pr-checkout:
description: >
Required to check out fork pull request code from a workflow triggered by
`pull_request_target` or `workflow_run`. See [Pwn Requests](todo:need-link)
for the risks. Set to `true` only after reviewing the risks.
default: false
Comment thread src/unsafe-pr-checkout-helper.ts Outdated
Comment thread src/unsafe-pr-checkout-helper.ts
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.

4 participants