Securely using pull_request_target

Learn about the security risks of the pull_request_target event.

This guide helps you assess whether your workflow should use the pull_request_target event and understand the security risks involved. It also explains the protections that GitHub applies to these risks by default, and how to opt out of those protections if necessary.

Risks of pull_request_target

Workflows triggered by pull_request_target run with elevated trust: the job receives the base repository's GITHUB_TOKEN and access to repository and organization secrets. This is the same trust given to events like push that only collaborators can trigger, and it is what makes pull_request_target useful for automation that responds to pull requests from forks, such as labeling, triage, or for posting authenticated status checks.

To understand why this is safe by default, and how that safety is commonly broken, review pull_request_target against pull_request.

The pull_request event (along with pull_request_review and pull_request_review_comment) is unusual: it runs the workflow file from the merge commit of the pull request. For a pull request opened from a fork, that commit is controlled by someone without write access to the base repository. To run untrusted workflow code safely, GitHub restricts these events to a read-only GITHUB_TOKEN, withholds access to other secrets, and applies fork approval policies to prevent compute abuse. By default, actions/checkout in a pull_request workflow also checks out the pull request's merge commit, so the code checked out and the workflow that runs are consistent.

pull_request_target makes one critical and subtle change: the workflow, and any subsequent actions/checkout call that does not specify a ref, is taken from the base repository's default branch, not from the pull request. Because only trusted code from the default branch runs, it is safe to grant secrets and a read/write token. No code from the fork is executed by default.

You introduce risk when a workflow author overrides this default to run the fork's code. Developers frequently choose pull_request_target because they want to run a fork's pull request through CI and have access to secrets, for example to run tests that need a private registry. To do this, they point actions/checkout at the pull request head instead of the default branch, which is insecure:

# INSECURE. Provided as an example only.
on:
  pull_request_target:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          ref: ${{ github.event.pull_request.head.sha }}
      - name: Test
        run: make test

The checkout step alone does not execute untrusted code. The workflow file itself still comes from the default branch. The vulnerability is completed by the next step that runs code checked out into the current working directory. Here, make test executes a Makefile taken from the pull request head. An attacker only needs to open a pull request from a fork whose Makefile (or build script, test command, dependency, or configuration file) contains malicious commands. Those commands then run with the base repository's secrets and token.

This pattern is known as a "pwn request" and has been the root cause of multiple supply-chain compromises. For more information, see Preventing pwn requests from the GitHub Security Lab. Common vulnerable shapes include:

Pwn requests are also not unique to pull_request_target. Any event that runs with secrets can introduce a pwn request if it checks out or downloads and executes untrusted code. For example, an issue_comment or workflow_run workflow that fetches and runs a fork's pull request code is vulnerable in the same way. A workflow_run workflow should treat artifacts uploaded by other workflows as untrusted data, since their contents can come from a fork.

Default policy for pull_request_target

To help protect your workflows from untrusted pull requests, GitHub provides a default event policy that blocks the pull_request_target event in public repositories.

How the default policy works

For public repositories that do not already have an applicable Actions event policy, GitHub adds a default policy that blocks workflows triggered by pull_request_target. For more information about policies, see About Actions policies.

The default policy:

On December 2, 2026, GitHub will enforce the default policy for affected repositories that were using the default pull_request_target policy before general availability.

Reviewing the impact before enforcement

While the policy is in evaluate mode, review your policy insights to identify workflows that use pull_request_target and would be blocked when the policy is enforced.

For each affected workflow, decide whether pull_request_target is still required:

Warning

Only allow pull_request_target when it is necessary. Workflows triggered by this event should not check out, build, or run code from an untrusted pull request with access to repository secrets or a privileged GITHUB_TOKEN.

For more information about configuring event policies and viewing insights, see Governing execution of GitHub Actions workflows. To manage policies programmatically, see REST API endpoints for GitHub Actions policies.

Deciding whether to use pull_request_target

Some workflows need to check out fork pull request code with elevated trust, and this is why pull_request_target was created in the first place. For example, generating coverage reports that require a private artifact registry or producing and running authenticated checks against the changes introduced from the pull request. Consider the questions below before using pull_request_target or opting into the allow-unsafe-pr-checkout flag in actions/checkout.

Hardening a pull_request_target workflow

If you have confirmed you need pull_request_target, apply these controls to limit the impact of this high-risk event. These apply whether or not your workflow checks out pull request code.

Opting out of built-in protections

If you have worked through the questions above and confirmed your workflow requires pull_request_target and uses it safely, you can opt out of the default event policy and actions/checkout protection.

Setting allow-unsafe-pr-checkout: true as an actions/checkout input allows checking out pull request head refs from forks. Only do this after confirming the checked-out code is never executed. The input is intentionally named to be easy to spot in code review and static analysis.

This protection only covers fork pull request refs. Checking out other untrusted code, such as an unrelated third-party repository, fetching code with git fetch or gh pr checkout, or running a downloaded artifact, is not covered by the actions/checkout checks.