The pull_request_target trap: how pwn requests leak secrets

By the CapyShield team · · 5 min read

In short

A pwn request is a fork pull request whose code gets executed by a privileged workflow, most often a pull_request_target workflow that checks out the pull request head and builds it with the base repository's secrets. Since December 2, 2026, GitHub blocks pull_request_target by default in public repositories unless an event policy allows it. The safe patterns are plain pull_request for building untrusted code, and a pull_request plus workflow_run split when a privileged step needs the results.

pull_request_target is the GitHub Actions trigger that lets a workflow respond to pull requests from forks with the base repository's secrets and a write-capable token. Used as designed, for labeling or commenting, it is safe. Combined with a checkout of the pull request's code, it hands anyone with a GitHub account your secrets. This post explains why, what GitHub changed on December 2, 2026, and what to use instead.

What is a pwn request in GitHub Actions?

A pwn request is a pull request from a fork that gets its own code executed by a privileged workflow. The attacker doesn't need write access or a maintainer's approval: they open a pull request whose build script, test file, package.json or dependency contains a malicious command, and your workflow runs it with your repository's token and secrets. GitHub Security Lab named the pattern in 2021, and GitHub's documentation describes it as the root cause of multiple supply chain compromises.

It is not limited to one trigger. Any event that runs with secrets, including issue_comment and workflow_run, becomes a pwn request if it fetches and executes untrusted pull request code. But pull_request_target is where it most often happens, because the trigger looks like the obvious fix for "my tests need a secret and fork PRs don't get one".

The damage depends on what the workflow has. With a write-capable GITHUB_TOKEN, the attacker's code can push commits, create releases or edit other pull requests during the job. With repository secrets, it can send out registry tokens and cloud keys that keep working long after the job ends. GitHub Security Lab summarizes the outcome as repository write access or stolen secrets.

Why is pull_request_target dangerous when pull_request is not?

The two triggers fire on the same pull request activity, but they trust different code:

  • pull_request runs the workflow from the pull request's merge commit. For a fork, that commit is controlled by an outsider, so GitHub gives it a read-only GITHUB_TOKEN, withholds all other secrets and applies fork approval policies.
  • pull_request_target runs the workflow file from the base repository's default branch, and actions/checkout without a ref checks out the default branch too. Since only trusted code runs, GitHub gives it the base repository's token and secrets.

That safety disappears the moment the workflow checks out the pull request instead:

yaml
# INSECURE: GitHub's own example of a pwn request
on: pull_request_target
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6
        with:
          ref: ${{ github.event.pull_request.head.sha }}
      - run: make test   # runs the fork's Makefile with your secrets

The checkout alone executes nothing. The next step does: make test, npm install, pip install -e . and most build tools run code or configuration from the working directory. Other shapes of the same bug: ref: refs/pull/N/merge, setting repository: to the fork, or fetching the code with git fetch or gh pr checkout. A run: step that interpolates the pull request title or branch name is a second way in, via script injection, even with no checkout at all.

What changed for pull_request_target on December 2, 2026?

GitHub now blocks pull_request_target by default in public repositories. Since December 2, 2026, a default Actions event policy blocks workflows triggered by it unless an applicable event policy explicitly allows them. Before that, the rule ran in evaluate mode, with two brownouts on November 9 and 16, 2026, during which blocked runs failed with an error annotation. The details:

  • Private and internal repositories aren't affected.
  • An event policy you had already configured still applies; the default doesn't replace it.
  • It covers public repositories on GitHub Free, Team and Enterprise Cloud, not GitHub Enterprise Server.
  • Policy insights show which workflow runs the rule blocks, and an allow can be scoped to specific workflow files.

Separately, actions/checkout v7 refuses to check out fork pull request code under pull_request_target or workflow_run unless you set allow-unsafe-pr-checkout: true, an input named to stand out in code review. Workflows still on v6 or older, like the example above, get no such check. And pull_request_target workflows now get read-only access to the default branch's cache, so they can't poison it for other workflows. None of this makes an existing unsafe workflow safe if you allow it again: the advice is to allow the event only after confirming the workflow never executes pull request code with secrets or a privileged token.

What should you use instead of pull_request_target?

Plain pull_request for anything that builds or tests the pull request's code. It needs no extra secrets for most test suites, and it is safe for forks by design.

A pull_request plus workflow_run split when a privileged step needs results from untrusted code, such as posting coverage as a comment. The unprivileged pull_request workflow builds and tests, writes its results to an artifact and exits. A second workflow on workflow_run runs with write permissions, downloads the artifact and posts it:

yaml
# .github/workflows/report.yml
on:
  workflow_run:
    workflows: ["ci"]
    types: [completed]
permissions:
  pull-requests: write
jobs:
  comment:
    runs-on: ubuntu-latest
    steps:
      # download the artifact, then treat its contents as data: parse it, never execute it
      - run: gh run download "$RUN_ID" -n coverage -D coverage
        env:
          RUN_ID: ${{ github.event.workflow_run.id }}
          GH_TOKEN: ${{ github.token }}
          GH_REPO: ${{ github.repository }}

The artifact comes from a fork, so treat it as hostile input: don't run scripts from it, don't interpolate its content into run:, and don't extract it over your workspace.

Keep pull_request_target only for jobs that never touch the pull request's code, like labeling and triage, with a permissions: block that grants just what the job needs and no repository secrets beyond that.

How do you find pull_request_target workflows that are vulnerable?

Start with GitHub's policy insights, which list the runs the default rule would block or has blocked. Then check the code itself, because the same bug works under workflow_run, and in private repositories, where the new default doesn't apply. capyshield actions does this offline:

terminal
capyshield actions --fail-on critical   # exit 4 on untrusted-checkout
capyshield actions --fail-on high       # also template-injection, unpinned-uses, write-all-permissions

Its untrusted-checkout rule (critical) flags a checkout of the pull request head ref under pull_request_target or workflow_run, and template-injection (high) flags untrusted ${{ github.event.* }} values such as the pull request title, body or head_ref in run: or github-script. Each finding points at its line. Run it on every pull request that changes .github/workflows; the docs show the CI setup.

Frequently asked questions

What is a pwn request?
A pwn request is a pull request from a fork whose code is executed by a workflow that has the base repository's secrets or a write-capable token. The attacker only needs to open a pull request with a malicious build script, test or dependency.
What is the difference between pull_request and pull_request_target?
pull_request runs the workflow from the pull request's merge commit with a read-only token and no secrets for forks. pull_request_target runs the workflow from the base repository's default branch with its token and secrets, which is only safe if the pull request's code is never executed.
Is pull_request_target blocked on GitHub?
Since December 2, 2026, GitHub blocks pull_request_target workflows by default in public repositories on GitHub Free, Team and Enterprise Cloud unless an Actions event policy explicitly allows them. Private and internal repositories and existing event policies are not affected.
How do I safely comment test results on a fork pull request?
Run the build and tests in an unprivileged pull_request workflow that saves results as an artifact, then post them from a separate workflow_run workflow with write permissions. Treat the artifact as untrusted data and never execute its contents.

Sources