pull_request_target: when a pull request runs with your secrets

GitHub has two triggers for pull requests, and the difference between them is the most common way a public repository leaks its secrets.

pull_request and pull_request_target

A workflow triggered by pull_request runs the workflow file from the pull request itself. When the pull request comes from a fork, GitHub gives the run a read-only token and no secrets. Whatever the pull request changes, it can’t reach anything worth stealing.

A workflow triggered by pull_request_target runs in the base repository instead: the workflow file comes from the default branch (since December 2025, whatever branch the pull request targets), and the run gets the repository’s secrets and a token with the repository’s default permissions, which can often write. It exists for jobs that have to act on pull requests from forks, such as labelling them or posting a comment.

That is safe as long as the run never executes anything from the pull request. By default it doesn’t: actions/checkout in a pull_request_target run checks out the default branch, not the pull request.

How it goes wrong

The usual mistake is wanting to test pull requests with a secret, such as an API key for integration tests, and finding that pull_request doesn’t provide one for forks. Switching the trigger and checking out the pull request’s commit looks like the fix:

on: pull_request_target

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          ref: ${{ github.event.pull_request.head.sha }}
      - run: npm ci
      - run: npm test
        env:
          API_KEY: ${{ secrets.TEST_API_KEY }}

Now anyone with a GitHub account can open a pull request that changes package.json, a test, or any file the build reads, and their code runs with TEST_API_KEY in its environment and a token that may be able to push to your repository. npm ci alone is enough: install scripts in package.json run during it. Researchers call this a pwn request. The example report is an audit of a workflow like this one.

The same thing happens without pull_request_target:

What GitHub changed in 2026

None of these covers private repositories, issue_comment, or a repository whose policy allows the trigger. If a workflow needs the opt-out input or a policy exception, that is the line to read twice in review.

Safe patterns

Tests that need no secrets. Use pull_request. That covers most test suites.

Jobs that write back but don’t run pull request code. Labelling, triage and welcome comments can use pull_request_target safely. Don’t check out the pull request, give the job only the permissions it uses, and pass any text from the event (title, body, branch name) to scripts through env:, never by expanding ${{ }} inside run::

on: pull_request_target

permissions: {}

jobs:
  label:
    runs-on: ubuntu-latest
    permissions:
      pull-requests: write
    steps:
      - run: gh pr edit "$NUMBER" --repo "$REPO" --add-label needs-review
        env:
          GH_TOKEN: ${{ github.token }}
          NUMBER: ${{ github.event.pull_request.number }}
          REPO: ${{ github.repository }}

Results that need posting back. Run the tests in a pull_request workflow and upload the results as an artifact. A second workflow, triggered by workflow_run, downloads the artifact and posts the comment. Treat the artifact as data from a stranger: extract it into a temporary directory, parse it and check it, never run it or expand it into a script, and give that workflow only the permission to comment.

Tests that really need a secret. Put the job in an environment with required reviewers, so it waits until a maintainer approves the run, and check out github.event.pull_request.head.sha: the exact commit the event was for, not the branch, which the author can push to while the job waits. The maintainer approving has to read that commit as though it will run with the secret, because it will. In a public repository this also needs an Actions policy that allows the workflow.

Checking your repository

Audit the repository to find these patterns in every workflow: zizmor and poutine both flag a checkout of pull request code in a privileged run, and zizmor flags the triggers themselves and event data expanded into scripts. The sample workflows include a pwn request, a comment-triggered deploy and an issue title injection to compare with your own.