Syknapse / Syknapse/Contribute-To-This-Project

[BUG] Fix: Resolve checkout failure in auto-format workflow on fork PRs

Open
#4,722 0 comments 0 reactions 1 assignee View on GitHub

@kuramaSeige-OFC is already working on this.

Since Aug 21, 2026.

bug github_actions maintainer-review priority:high
Dominant language
JavaScript
Stars
2.6k
Forks
3.5k
Avg merge
13h 14m
Merged PRs (30d)
32

Description

Scenario & Narration

Our Auto Format workflow (auto-format.yml) runs on the pull_request_target trigger so it has the write access required to push formatting fixes back to fork branches.

However, recent runs on fork PRs are failing at the Checkout PR branch step with this error:

Error: Refusing to check out fork pull request code from a 'pull_request_target' workflow. ... Fetching and executing a fork's code in that trusted context commonly leads to "pwn request" vulnerabilities.

Here is why this occurs:

  1. In pull_request_target, the workflow has access to write permissions and secrets (like FORMAT_BOT_PAT).
  2. Newer versions of actions/checkout (v4/v6) block checking out code from a fork branch by default in privileged environments to protect the repository owner.
  3. This blocks our format bot from ever running formatting on PRs from contributors.
Safety Analysis

Checking out a fork under pull_request_target is safe in our specific workflow because:

  • We do not run npm install or execute any scripts from the fork branch.
  • We overwrite the prettier config and .prettierignore with the trusted versions from master before executing Prettier.
  • We invoke Prettier solely via npx.
Remediation Plan

We need to explicitly opt-in to checking out the fork code by adding allow-unsafe-pr-checkout: true to the checkout action block:

      - name: Checkout PR branch
        uses: actions/checkout@v6
        with:
          token: ${{ secrets.FORMAT_BOT_PAT }}
          ref: ${{ github.event.pull_request.head.sha }}
          repository: ${{ github.event.pull_request.head.repo.full_name }}
          allow-unsafe-pr-checkout: true

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.