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:
workflow_runruns after another workflow finishes, with the base repository’s secrets, even when the first run was for a pull request from a fork. Anything it takes from that run (artifacts, branch names, files it checks out) came from the pull request.issue_commentruns for comments on pull requests. A workflow that checks out the pull request when someone comments/test, without checking who commented, lets anyone run it.
What GitHub changed in 2026
- actions/checkout refuses to check out a fork’s code in
pull_request_targetruns, and inworkflow_runruns that follow a fork’s pull request, unless the step setsallow-unsafe-pr-checkout: true. v7.0.0 brought this in June 2026, and July updates added it to v2 through v6, soactions/checkout@v4has it. A workflow pinned to an older commit, or one that fetches the pull request withgitorgh pr checkout, gets no such check. - Caches: since June 2026, runs triggered by
pull_request_target,issue_commentandworkflow_runcan restore the default branch’s caches but not save them, unless a job setscache-mode: write. - Public repositories: since December 2, 2026 GitHub blocks
pull_request_targetin public repositories unless an Actions policy (Settings, then Actions, then Policies) allows it. A blocked run fails with an annotation instead of running. The policy can allow the event for specific workflow files only.
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.