pull_request vs pull_request_target in GitHub Actions
pull_request vs pull_request_target: which one gets secrets and a write token, the pwn request risk, 2025-2026 changes, and the safe split pattern.
In this series24 guides, you're on pull_request vs pull_request_target
Short answer: pull_request runs the workflow from the pull request itself, with a read-only token and no secrets for forks. pull_request_target runs the workflow from your default branch, with a read/write token and your secrets, even for forks. Use pull_request for building and testing PR code. Use pull_request_target only for automation that never runs the PR’s code: labelling, commenting, triage. If fork PR tests need secrets, see where to run them.
pull_request | pull_request_target | |
|---|---|---|
| Workflow file comes from | The PR’s merge commit | The default branch |
actions/checkout checks out by default | The PR merge commit (refs/pull/N/merge) | The default branch |
GITHUB_TOKEN for fork PRs | Read-only | Read/write |
| Secrets for fork PRs | None (only GITHUB_TOKEN) | All repository and organization secrets |
| Waits for approval on a first-time contributor’s PR | Yes, by default | No, always runs |
| Runs when the PR has a merge conflict | No | Yes |
| Can write to the default branch’s cache | No (writes are scoped to the PR) | No (read-only since June 2026) |
| Allowed in public repositories | Yes | Blocked by default from December 2, 2026, unless a policy allows it |
For pull requests opened from a branch of the same repository (not a fork), pull_request gets the usual secrets and token, because the author already has write access. Dependabot’s pull requests are the exception: their branches live in your repository, but their pull_request runs get a read-only token and only Dependabot secrets ↗. Store what they need as Dependabot secrets, and raise the token with permissions: if a job needs to write, instead of switching to pull_request_target. In private repositories, an admin can also choose to send write tokens and secrets to workflows from fork pull requests.
Pull requests that a workflow opens or updates with GITHUB_TOKEN are another exception: since June 2026, their pull_request runs wait until someone with write access approves them. See if a workflow doesn’t start.
Under both events, github.sha is the commit the default checkout uses, not the PR’s last commit. To post a status or a check on the PR, use github.event.pull_request.head.sha.
Which one gets secrets?#
This is the whole difference, and why pull_request_target exists.
A fork pull request can change anything in the repository, including the workflow files. If pull_request handed secrets to those runs, anyone could open a PR that prints them. So for forks, GitHub runs pull_request workflows with a read-only GITHUB_TOKEN, withholds every other secret, and asks a maintainer to approve runs from first-time contributors.
pull_request_target flips this around: the workflow and the default checkout come from your default branch, code you already trust, so GitHub gives it the secrets and a writable token. That’s what lets it label or comment on pull requests from forks. It also skips the approval step: fork approval settings don’t apply to pull_request_target, so it runs as soon as anyone, a first-time contributor included, opens or updates a pull request. The trust only holds as long as the workflow never runs code from the pull request.
pull_request: build and test the PR#
name: CI
on: pull_request: branches: [main]
permissions: contents: read
jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 # checks out the PR merge commit - run: npm ci - run: npm testBy default it runs on the opened, synchronize (new commits pushed) and reopened activity types. Add others with types:, for example types: [opened, synchronize, reopened, ready_for_review] to also run when a draft is marked ready. The branches filter matches the base branch the PR targets, not the contributor’s branch.
pull_request_target: privileged automation on PRs#
name: Label PRs
on: pull_request_target: types: [opened, synchronize]
permissions: contents: read pull-requests: write
jobs: label: runs-on: ubuntu-latest steps: # No checkout of the PR code: the labeler reads the changed file list and its rules through the API. - uses: actions/labeler@v7The labeler reads its rules from .github/labeler.yml on your default branch, not from the fork, so a contributor can’t change them. Each rule names a label and the paths that earn it:
docs: - changed-files: - any-glob-to-any-file: 'docs/**'pull-requests: write is enough to add labels that already exist. Add issues: write if the labeler should create them.
Like pull_request, pull_request_target runs on the opened, synchronize and reopened activity types by default, and types: picks others from the same list of activity types.
Typical safe uses: adding labels, posting a welcome comment, assigning reviewers, closing spam. None of them need to execute the contributor’s code.
What changed in 2025 and 2026#
pull_request_target has caused enough supply-chain compromises that GitHub tightened it several times:
- December 8, 2025: the workflow always comes from the default branch. It used to come from the PR’s base branch, so an old, vulnerable workflow on a stale release branch could still be exploited by targeting that branch. Now the workflow file and the default
GITHUB_SHA/GITHUB_REFare always the default branch’s. actions/checkoutrefuses fork PR code by default. In apull_request_targetor PR-triggeredworkflow_runworkflow, checking out a fork PR’s head or merge commit, or pointingrepository:at the fork, fails unless you setallow-unsafe-pr-checkout: true. The input is named to stand out in code review. The check shipped in v7 (June 2026). Since July 20, 2026, thev4,v5andv6major tags have it too (from v4.4.0, v5.1.0 and v6.1.0). A checkout pinned to an older commit SHA or exact version, such asv4.2.2, has no check, so update the pin.- Read-only cache. Since June 2026,
pull_request_target,issue_commentandworkflow_runruns, and theclosedrun of a merged pull request, can restore the default branch’s caches but can’t write them, which closes off cache poisoning unless the workflow setscache-modetowriteorwrite-only(available since September 2026). See who can write the cache. - December 2, 2026: blocked by default in public repositories. GitHub adds a default Actions event policy that blocks
pull_request_targetin public repositories that don’t already have an applicable policy. Until then it runs in evaluate mode: workflows still run, and the policy insights show which ones would be blocked. The exceptions are two brownouts, on November 9 and November 16, 2026, from 16:00 to 18:00 UTC. During each one, the policy is enforced and the runs it blocks fail with an error. Private and internal repositories are not affected. If a public repository still needs the event, an organization or repository admin must create an event policy that allows it. The policy can target just the workflow files that need it.
The pwn request: checking out the PR head#
The dangerous pattern is a pull_request_target workflow that checks out the pull request and then runs it:
# INSECURE: do not copyon: pull_request_target:
jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 with: ref: ${{ github.event.pull_request.head.sha }} allow-unsafe-pr-checkout: true - run: npm install && npm test # runs the fork's package.json scripts, with your secretsThe checkout alone is harmless. The next step is not: npm install, make, a test runner or a config file all execute code the contributor controls, in a job that holds your secrets and a writable token. GitHub’s security lab calls this a “pwn request” ↗. Fetching the code another way (git fetch, gh pr checkout, downloading an artifact a fork’s run uploaded) is just as dangerous, and actions/checkout can’t catch those. So is checking out the PR from another event that runs with your secrets, such as an issue_comment workflow that checks out refs/pull/N/head when someone comments /test: the actions/checkout guard only covers pull_request_target and PR-triggered workflow_run workflows.
The safe pattern: split untrusted work from privileged work#
When a fork PR needs something privileged done with the results of its build (a coverage comment, a preview deploy), split it in two:
- A
pull_requestworkflow builds and tests the PR with no secrets and uploads the results as an artifact. - A
workflow_runworkflow, triggered when the first one completes, downloads the artifact, treats it as data only (parse it, never execute it), and posts the comment with its write token. If it deploys a preview, gate it with an environment: with a required reviewer, the job can’t read the deploy secrets until a maintainer approves the deploy.
name: CI
on: pull_request:
permissions: contents: read
jobs: test: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 - run: npm ci - run: npx jest --coverage --coverageReporters=json-summary - name: Save the PR number for comment.yml env: PR: ${{ github.event.number }} run: echo "$PR" > coverage/pr_number - uses: actions/upload-artifact@v7 with: name: coverage path: | coverage/coverage-summary.json coverage/pr_numberon: workflow_run: workflows: [CI] types: [completed]
permissions: pull-requests: write actions: read
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 path: ${{ runner.temp }}/coverage # outside the workspace run-id: ${{ github.event.workflow_run.id }} github-token: ${{ github.token }} # Read both files as data, never execute them. - name: Comment on the PR env: GH_TOKEN: ${{ github.token }} # the write token GH_REPO: ${{ github.repository }} DIR: ${{ runner.temp }}/coverage run: | pr=$(cat "$DIR/pr_number") [[ $pr =~ ^[0-9]+$ ]] || exit 1 pct=$(jq -e '.total.lines.pct | numbers' "$DIR/coverage-summary.json") gh pr comment "$pr" --body "Line coverage: ${pct}%"The PR number travels in the artifact because github.event.workflow_run.pull_requests is empty when the PR comes from a fork. A fork controls what its CI run uploads, so comment.yml extracts the files outside the workspace, accepts only digits as the PR number and only a number as the coverage figure. It also skips failed CI runs, which upload nothing.
If your tests need secrets#
Some test suites need a secret, such as a token for a private registry or a cloud account. Don’t give it to the fork’s code. Run the tests that need no secret on pull_request, and run the others only after a maintainer has reviewed the code: in a merge queue ↗, whose merge_group runs use branches GitHub creates in your repository, or on push to the default branch after the merge. A maintainer can also push the reviewed commits to a branch of your repository: a pull request from that branch gets secrets. Don’t check out and run the fork’s code in a pull_request_target job instead, even behind an environment with required reviewers: GitHub’s guidance is that code checked out there is only ever read as data, never executed.
Checklist if you keep pull_request_target#
- Set
permissions:to the minimum the job needs. - Don’t check out, build or run the PR’s code in that workflow. If you must check it out to read files, set
allow-unsafe-pr-checkout: true, use a separatepath:and treat it as data. - Never interpolate PR fields (
github.event.pull_request.title, branch names, bodies) directly intorun:scripts; pass them throughenv:to avoid shell injection. - Pin third-party actions to a full commit SHA, or commit a workflow dependency lockfile ↗ (generally available since October 2026) that pins every action your workflows use, transitive ones included. A tag can be moved to other code, which would then run with your secrets. The lockfile doesn’t cover calls to reusable workflows: pin those to a full commit SHA. The examples on this page use major-version tags only to stay short.
- Scan your workflows for these mistakes. CodeQL ↗ analyzes GitHub Actions workflows: in code scanning’s default setup, check that GitHub Actions is among the scanned languages. zizmor ↗, an open-source command-line tool, flags
pull_request_targettriggers, template injection and excessive permissions, and can write its findings as SARIF for code scanning. - Use ephemeral runners (how to set them up): a self-hosted runner that is reused between jobs can be poisoned by one malicious run. RunsOn launches a fresh EC2 instance for every job. Repositories on one RunsOn stack still share its cache bucket and runner IAM role, so give public repositories a separate RunsOn environment.
- In public repositories, check the policy insights for runs the default policy blocks or would block, and add an event policy that allows the event for the workflow files that still need it.
GitHub’s own guide, Securely using pull_request_target ↗, goes deeper on each point.